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).
reviewable/pr10611/r1
NiLuJe 11 months ago committed by GitHub
parent 4a775b03f1
commit 55869b82cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,4 @@
local BasePowerD = require("device/generic/powerd")
local Event = require("ui/event")
local UIManager
local _, android = pcall(require, "android")
local AndroidPowerD = BasePowerD:new{
@ -8,13 +6,6 @@ local AndroidPowerD = BasePowerD:new{
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()
return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max)
end
@ -66,8 +57,6 @@ function AndroidPowerD:turnOffFrontlightHW()
return
end
android.setScreenBrightness(self.fl_min)
self.is_fl_on = false
broadcastLightChanges()
end
function AndroidPowerD:turnOnFrontlightHW()
@ -78,13 +67,6 @@ function AndroidPowerD:turnOnFrontlightHW()
android.enableFrontlightSwitch()
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
return AndroidPowerD

@ -59,8 +59,21 @@ function BasePowerD:isAuxChargingHW() return false end
function BasePowerD:isAuxChargedHW() return false end
function BasePowerD:frontlightIntensityHW() return 0 end
function BasePowerD:isFrontlightOnHW() return self.fl_intensity > self.fl_min end
function BasePowerD:turnOffFrontlightHW(done_callback) self:setIntensityHW(self.fl_min) end
function BasePowerD:turnOnFrontlightHW(done_callback) self:setIntensityHW(self.fl_intensity) end --- @fixme: what if fl_intensity == fl_min (c.f., kindle)?
--- @note: done_callback is used to display Notifications,
--- 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
-- Anything that needs to be done before doing a real hardware suspend.
-- (Such as turning the front light off).
@ -121,9 +134,12 @@ end
function BasePowerD:turnOffFrontlight(done_callback)
if not self.device:hasFrontlight() then return 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:stateChanged()
if not cb_handled and done_callback then
done_callback()
end
return true
end
@ -131,9 +147,12 @@ function BasePowerD:turnOnFrontlight(done_callback)
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 --- @fixme what the hell?
self:turnOnFrontlightHW(done_callback)
local cb_handled = self:turnOnFrontlightHW(done_callback)
self.is_fl_on = true
self:stateChanged()
if not cb_handled and done_callback then
done_callback()
end
return true
end

@ -364,6 +364,9 @@ function KoboPowerD:turnOffFrontlightHW(done_callback)
-- If UIManager is not initialized yet, just turn it off immediately
self:setIntensityHW(self.fl_min)
end
-- We consume done_callback ourselves, make sure Generic's PowerD gets the memo
return true
end
-- 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
self:setIntensityHW(self.fl_intensity)
end
-- We consume done_callback ourselves, make sure Generic's PowerD gets the memo
return true
end
-- Turn off front light before suspend.

Loading…
Cancel
Save