From cf3b97537b58cf296eefe8a9178737807a122b79 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 1 Mar 2016 22:30:29 -0800 Subject: [PATCH] kobo: build fl_state based on fl_intensity if model does not support toggle --- frontend/device/kobo/nickel_conf.lua | 8 ++------ frontend/ui/uimanager.lua | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/device/kobo/nickel_conf.lua b/frontend/device/kobo/nickel_conf.lua index f0e39ca9d..57aca7ac1 100644 --- a/frontend/device/kobo/nickel_conf.lua +++ b/frontend/device/kobo/nickel_conf.lua @@ -68,12 +68,8 @@ function NickelConf.frontLightState.get() if new_state then new_state = (new_state == "true") or false end - - if new_state == nil then - assert(NickelConf.frontLightState.set(false)) - return false - end - + -- for devices that do not have toggle button, the entry will be missing + -- and we return nil in this case. return new_state end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 7576d5c87..7d57e0f2c 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -74,12 +74,21 @@ function UIManager:init() local NickelConf = require("device/kobo/nickel_conf") new_intensity = NickelConf.frontLightLevel.get() new_state = NickelConf.frontLightState:get() + if new_state == nil then + -- this device does not support frontlight toggle, + -- we set the state based on frontlight intensity. + if new_intensity > 0 then + new_state = true + else + new_state = 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 - -- Since this kobo-specific, we save here and let the code pick - -- it up later from the reader settings. - G_reader_settings:saveSetting( - "frontlight_intensity", new_intensity) + G_reader_settings:saveSetting("frontlight_intensity", + new_intensity) end G_reader_settings:saveSetting("frontlight_state", new_state) end