diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 09db1d7da..533e3e8ce 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -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) diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index abe985a7b..79dd545c8 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -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() diff --git a/kodev b/kodev index 4eae9c5af..e39ac0387 100755 --- a/kodev +++ b/kodev @@ -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 \ diff --git a/spec/unit/device_spec.lua b/spec/unit/device_spec.lua index 424d1ed03..66e376a07 100644 --- a/spec/unit/device_spec.lua +++ b/spec/unit/device_spec.lua @@ -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