2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00

chore: move kobo specific code into kobo/device.lua

This commit is contained in:
Qingping Hou 2016-09-11 21:41:56 -07:00
parent c619de324e
commit ebc7055b43
4 changed files with 46 additions and 37 deletions

View File

@ -156,6 +156,38 @@ function Kobo:init()
self:initEventAdjustHooks()
end
end
-- TODO: get rid of KOBO_LIGHT_ON_START
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
if kobo_light_on_start then
local new_intensity
local is_frontlight_on
if kobo_light_on_start > 0 then
new_intensity = math.min(kobo_light_on_start, 100)
is_frontlight_on = true
elseif kobo_light_on_start == 0 then
is_frontlight_on = false
elseif kobo_light_on_start == -2 then
local NickelConf = require("device/kobo/nickel_conf")
new_intensity = NickelConf.frontLightLevel.get()
is_frontlight_on = NickelConf.frontLightState:get()
if is_frontlight_on == nil then
-- this device does not support frontlight toggle,
-- we set the value based on frontlight intensity.
if new_intensity > 0 then
is_frontlight_on = true
else
is_frontlight_on = false
end
end
end
-- Since this is kobo-specific, we save all values in settings here
-- and let the code (reader.lua) pick it up later during bootstrap.
if new_intensity then
G_reader_settings:saveSetting("frontlight_intensity", new_intensity)
end
G_reader_settings:saveSetting("is_frontlight_on", is_frontlight_on)
end
end
function Kobo:initNetworkManager(NetworkMgr)

View File

@ -99,37 +99,6 @@ function UIManager:init()
self:sendEvent(input_event)
end
end
local kobo_light_on_start = tonumber(KOBO_LIGHT_ON_START)
if kobo_light_on_start then
local new_intensity
local is_frontlight_on
if kobo_light_on_start > 0 then
new_intensity = math.min(kobo_light_on_start, 100)
is_frontlight_on = true
elseif kobo_light_on_start == 0 then
is_frontlight_on = false
elseif kobo_light_on_start == -2 then
local NickelConf = require("device/kobo/nickel_conf")
new_intensity = NickelConf.frontLightLevel.get()
is_frontlight_on = NickelConf.frontLightState:get()
if is_frontlight_on == nil then
-- this device does not support frontlight toggle,
-- we set the value based on frontlight intensity.
if new_intensity > 0 then
is_frontlight_on = true
else
is_frontlight_on = false
end
end
end
-- Since this kobo-specific, we save all values in settings here
-- and let the code (reader.lua) pick it up later during bootstrap.
if new_intensity then
G_reader_settings:saveSetting("frontlight_intensity",
new_intensity)
end
G_reader_settings:saveSetting("is_frontlight_on", is_frontlight_on)
end
elseif Device:isKindle() then
self.event_handlers["IntoSS"] = function()
Device:intoScreenSaver()

1
kodev
View File

@ -329,6 +329,7 @@ OPTIONS:
test_path="${test_path}/$2"
fi
echo "Runing tests in" ${test_path}
busted --lua="./luajit" ${opts} \
--no-auto-insulate \
--lazy \

View File

@ -41,8 +41,21 @@ describe("device module", function()
describe("kobo", function()
local TimeVal
local NickelConf
setup(function()
TimeVal = require("ui/timeval")
NickelConf = require("device/kobo/nickel_conf")
end)
before_each(function()
stub(NickelConf.frontLightLevel, "get")
NickelConf.frontLightLevel.get.returns(0)
stub(NickelConf.frontLightState, "get")
end)
after_each(function()
NickelConf.frontLightLevel.get:revert()
NickelConf.frontLightState.get:revert()
end)
it("should initialize properly on Kobo dahlia", function()
@ -51,7 +64,6 @@ describe("device module", function()
kobo_dev:init()
assert.is.same("Kobo_dahlia", kobo_dev.model)
end)
it("should setup eventAdjustHooks properly for input in trilogy", function()
@ -149,10 +161,7 @@ describe("device module", function()
local sample_pdf = "spec/front/unit/data/tall.pdf"
local ReaderUI = require("apps/reader/readerui")
local Device = require("device")
local NickelConf = require("device/kobo/nickel_conf")
stub(NickelConf.frontLightLevel, "get")
stub(NickelConf.frontLightState, "get")
NickelConf.frontLightLevel.get.returns(1)
NickelConf.frontLightState.get.returns(0)
@ -175,8 +184,6 @@ describe("device module", function()
Device.suspend:revert()
Device.powerd.beforeSuspend:revert()
Device.isKobo:revert()
NickelConf.frontLightLevel.get:revert()
NickelConf.frontLightState.get:revert()
readerui.onFlushSettings:revert()
UIManager._startAutoSuspend = nil
UIManager._stopAutoSuspend = nil