2
0
mirror of https://github.com/koreader/koreader synced 2024-11-04 12:00:25 +00:00

PowerD: Unbreak frontlight toggle notifications outside of Kobo (#10597)

Fix #10588
Regression since #10305

While we're there, rejig the FL toggle callback shenanigans so that implementation details don't leak through to *other* implementations.
(i.e., leave the Kobo mess in Kobo land, with only a minimal impact on the public API and its implementation).
This commit is contained in:
NiLuJe 2023-06-25 11:25:33 +02:00 committed by GitHub
parent 4a775b03f1
commit 55869b82cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 22 deletions

View File

@ -1,6 +1,4 @@
local BasePowerD = require("device/generic/powerd") local BasePowerD = require("device/generic/powerd")
local Event = require("ui/event")
local UIManager
local _, android = pcall(require, "android") local _, android = pcall(require, "android")
local AndroidPowerD = BasePowerD:new{ local AndroidPowerD = BasePowerD:new{
@ -8,13 +6,6 @@ local AndroidPowerD = BasePowerD:new{
fl_max = 100, fl_max = 100,
} }
-- Let the footer know of the change
local function broadcastLightChanges()
if UIManager then
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
end
end
function AndroidPowerD:frontlightIntensityHW() function AndroidPowerD:frontlightIntensityHW()
return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max) return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max)
end end
@ -66,8 +57,6 @@ function AndroidPowerD:turnOffFrontlightHW()
return return
end end
android.setScreenBrightness(self.fl_min) android.setScreenBrightness(self.fl_min)
self.is_fl_on = false
broadcastLightChanges()
end end
function AndroidPowerD:turnOnFrontlightHW() function AndroidPowerD:turnOnFrontlightHW()
@ -78,13 +67,6 @@ function AndroidPowerD:turnOnFrontlightHW()
android.enableFrontlightSwitch() android.enableFrontlightSwitch()
android.setScreenBrightness(math.floor(self.fl_intensity * self.bright_diff / self.fl_max)) android.setScreenBrightness(math.floor(self.fl_intensity * self.bright_diff / self.fl_max))
self.is_fl_on = true
broadcastLightChanges()
end
function AndroidPowerD:UIManagerReadyHW(uimgr)
UIManager = uimgr
end end
return AndroidPowerD return AndroidPowerD

View File

@ -59,8 +59,21 @@ function BasePowerD:isAuxChargingHW() return false end
function BasePowerD:isAuxChargedHW() return false end function BasePowerD:isAuxChargedHW() return false end
function BasePowerD:frontlightIntensityHW() return 0 end function BasePowerD:frontlightIntensityHW() return 0 end
function BasePowerD:isFrontlightOnHW() return self.fl_intensity > self.fl_min end function BasePowerD:isFrontlightOnHW() return self.fl_intensity > self.fl_min end
function BasePowerD:turnOffFrontlightHW(done_callback) self:setIntensityHW(self.fl_min) end --- @note: done_callback is used to display Notifications,
function BasePowerD:turnOnFrontlightHW(done_callback) self:setIntensityHW(self.fl_intensity) end --- @fixme: what if fl_intensity == fl_min (c.f., kindle)? --- some implementations *may* need to handle it themselves because of timing constraints,
--- in which case they should return *true* here, so that the public API knows not to consume the callback early.
function BasePowerD:turnOffFrontlightHW(done_callback)
self:setIntensityHW(self.fl_min)
-- Nothing fancy required, so we leave done_callback handling to the public API
return false
end
function BasePowerD:turnOnFrontlightHW(done_callback)
--- @fixme: what if fl_intensity == fl_min (c.f., kindle)?
self:setIntensityHW(self.fl_intensity)
return false
end
function BasePowerD:frontlightWarmthHW() return 0 end function BasePowerD:frontlightWarmthHW() return 0 end
-- Anything that needs to be done before doing a real hardware suspend. -- Anything that needs to be done before doing a real hardware suspend.
-- (Such as turning the front light off). -- (Such as turning the front light off).
@ -121,9 +134,12 @@ end
function BasePowerD:turnOffFrontlight(done_callback) function BasePowerD:turnOffFrontlight(done_callback)
if not self.device:hasFrontlight() then return end if not self.device:hasFrontlight() then return end
if self:isFrontlightOff() then return false end if self:isFrontlightOff() then return false end
self:turnOffFrontlightHW(done_callback) local cb_handled = self:turnOffFrontlightHW(done_callback)
self.is_fl_on = false self.is_fl_on = false
self:stateChanged() self:stateChanged()
if not cb_handled and done_callback then
done_callback()
end
return true return true
end end
@ -131,9 +147,12 @@ function BasePowerD:turnOnFrontlight(done_callback)
if not self.device:hasFrontlight() then return end if not self.device:hasFrontlight() then return end
if self:isFrontlightOn() then return false end if self:isFrontlightOn() then return false end
if self.fl_intensity == self.fl_min then return false end --- @fixme what the hell? if self.fl_intensity == self.fl_min then return false end --- @fixme what the hell?
self:turnOnFrontlightHW(done_callback) local cb_handled = self:turnOnFrontlightHW(done_callback)
self.is_fl_on = true self.is_fl_on = true
self:stateChanged() self:stateChanged()
if not cb_handled and done_callback then
done_callback()
end
return true return true
end end

View File

@ -364,6 +364,9 @@ function KoboPowerD:turnOffFrontlightHW(done_callback)
-- If UIManager is not initialized yet, just turn it off immediately -- If UIManager is not initialized yet, just turn it off immediately
self:setIntensityHW(self.fl_min) self:setIntensityHW(self.fl_min)
end end
-- We consume done_callback ourselves, make sure Generic's PowerD gets the memo
return true
end end
-- Similar functionality as `Kobo:turnOnFrontlightHW`, but the other way around ;). -- Similar functionality as `Kobo:turnOnFrontlightHW`, but the other way around ;).
@ -410,6 +413,9 @@ function KoboPowerD:turnOnFrontlightHW(done_callback)
-- If UIManager is not initialized yet, just turn it on immediately -- If UIManager is not initialized yet, just turn it on immediately
self:setIntensityHW(self.fl_intensity) self:setIntensityHW(self.fl_intensity)
end end
-- We consume done_callback ourselves, make sure Generic's PowerD gets the memo
return true
end end
-- Turn off front light before suspend. -- Turn off front light before suspend.