Add onFrontlightStateChanged event (#2966)

So we do not need the hacky solution in KoboLight plugin anymore. PageFooter can receive and process the event itself.
pull/2977/head
Hzj_jie 7 years ago committed by GitHub
parent bd92d68b7f
commit d83de47204

@ -668,4 +668,10 @@ function ReaderFooter:onSuspend()
end
end
function ReaderFooter:onFrontlightStateChanged()
if self.settings.frontlight then
self:updateFooter()
end
end
return ReaderFooter

@ -35,8 +35,8 @@ function BasePowerD:setIntensityHW(intensity) end
function BasePowerD:getCapacityHW() return 0 end
function BasePowerD:isChargingHW() return false end
function BasePowerD:frontlightIntensityHW() return 0 end
function BasePowerD:turnOffFrontlightHW() self:setIntensityHW(self.fl_min) end
function BasePowerD:turnOnFrontlightHW() self:setIntensityHW(self.fl_intensity) end
function BasePowerD:turnOffFrontlightHW() self:_setIntensity(self.fl_min) end
function BasePowerD:turnOnFrontlightHW() self:_setIntensity(self.fl_intensity) end
-- Anything needs to be done before do a real hardware suspend. Such as turn off
-- front light.
function BasePowerD:beforeSuspend() end
@ -80,8 +80,8 @@ function BasePowerD:turnOffFrontlight()
assert(self ~= nil)
if not self.device.hasFrontlight() then return end
if self:isFrontlightOff() then return false end
self:turnOffFrontlightHW()
self.is_fl_on = false
self:turnOffFrontlightHW()
return true
end
@ -90,8 +90,8 @@ function BasePowerD:turnOnFrontlight()
if not self.device.hasFrontlight() then return end
if self:isFrontlightOn() then return false end
if self.fl_intensity == self.fl_min then return false end
self:turnOnFrontlightHW()
self.is_fl_on = true
self:turnOnFrontlightHW()
return true
end
@ -128,7 +128,7 @@ function BasePowerD:setIntensity(intensity)
self.fl_intensity = self:normalizeIntensity(intensity)
self:_decideFrontlightState()
logger.dbg("set light intensity", self.fl_intensity)
self:setIntensityHW(self.fl_intensity)
self:_setIntensity(self.fl_intensity)
return true
end
@ -144,4 +144,15 @@ function BasePowerD:isCharging()
return self:isChargingHW()
end
function BasePowerD:_setIntensity(intensity)
self:setIntensityHW(intensity)
-- BasePowerD is loaded before UIManager. So we cannot broadcast events before UIManager has
-- been loaded.
if package.loaded["ui/uimanager"] ~= nil then
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
end
end
return BasePowerD

@ -122,9 +122,6 @@ end
function KoboLight:onTap()
Device:getPowerDevice():toggleFrontlight()
self:onShowOnOff()
if self.view.footer_visible and self.view.footer.settings.frontlight then
self.view.footer:updateFooter()
end
return true
end
@ -153,9 +150,6 @@ function KoboLight:onSwipe(_, ges)
powerd:setIntensity(new_intensity)
self:onShowIntensity()
end
if self.view.footer_visible and self.view.footer.settings.frontlight then
self.view.footer:updateFooter()
end
return true
end

Loading…
Cancel
Save