mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
* Make hasNaturalLight* caps safe to call without a device check. (fix #4919) Make it clear that it's expecting the NTX implementation, though. * Don't turn the FL on on resume if it was off on suspend * Make sure turnOn/turnOff actually updates hw_intensity in the process where it matters, instead of just in a short lived fork ;). (fix #4923)
This commit is contained in:
@@ -747,7 +747,7 @@ end
|
||||
|
||||
function ReaderFooter:onFrontlightStateChanged()
|
||||
if self.settings.frontlight then
|
||||
self:updateFooter()
|
||||
self:updateFooter(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ local Device = {
|
||||
hasWifiManager = no,
|
||||
isTouchDevice = no,
|
||||
hasFrontlight = no,
|
||||
hasNaturalLight = no, -- FL warmth implementation specific to NTX boards (Kobo, Cervantes)
|
||||
hasNaturalLightMixer = no, -- Same, but only found on newer boards
|
||||
needsTouchScreenProbe = no,
|
||||
hasClipboard = yes, -- generic internal clipboard on all devices
|
||||
hasEinkScreen = yes,
|
||||
|
||||
@@ -21,6 +21,7 @@ local KoboPowerD = BasePowerD:new{
|
||||
fl_warmth = nil,
|
||||
auto_warmth = false,
|
||||
max_warmth_hour = 23,
|
||||
fl_was_on = nil,
|
||||
}
|
||||
|
||||
-- TODO: Remove KOBO_LIGHT_ON_START
|
||||
@@ -148,8 +149,9 @@ function KoboPowerD:init()
|
||||
-- Use setIntensity to ensure it sets fl_intensity, and because we don't want the ramping behavior of turnOn
|
||||
self:setIntensity(self:frontlightIntensityHW())
|
||||
else
|
||||
-- Use setIntensityHW so as *NOT* to set fl_intensity, so toggle will still work.
|
||||
self:setIntensityHW(0)
|
||||
-- Use _setIntensity for setIntensityHW so as *NOT* to set fl_intensity, so toggle will still work,
|
||||
-- plus the FrontlightStateChanged event.
|
||||
self:_setIntensity(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -293,7 +295,7 @@ function KoboPowerD:isChargingHW()
|
||||
end
|
||||
|
||||
function KoboPowerD:turnOffFrontlightHW()
|
||||
if self:isFrontlightOff() then
|
||||
if not self:isFrontlightOnHW() then
|
||||
return
|
||||
end
|
||||
local util = require("ffi/util")
|
||||
@@ -308,9 +310,20 @@ function KoboPowerD:turnOffFrontlightHW()
|
||||
end
|
||||
end
|
||||
end, false, true)
|
||||
-- NOTE: This is essentially what _setIntensity does, except we don't actually touch the FL,
|
||||
-- we only sync the state of the main process with the final state of what we're doing in the forks.
|
||||
-- And update hw_intensity in our actual process ;).
|
||||
self.hw_intensity = self.fl_min
|
||||
self:_decideFrontlightState()
|
||||
-- And let the footer know of the change
|
||||
if package.loaded["ui/uimanager"] ~= nil then
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
|
||||
end
|
||||
end
|
||||
function KoboPowerD:turnOnFrontlightHW()
|
||||
if self:isFrontlightOn() then
|
||||
if self:isFrontlightOnHW() then
|
||||
return
|
||||
end
|
||||
local util = require("ffi/util")
|
||||
@@ -324,11 +337,24 @@ function KoboPowerD:turnOnFrontlightHW()
|
||||
end
|
||||
end
|
||||
end, false, true)
|
||||
-- NOTE: This is essentially what _setIntensity does, except we don't actually touch the FL,
|
||||
-- we only sync the state of the main process with the final state of what we're doing in the forks.
|
||||
-- And update hw_intensity in our actual process ;).
|
||||
self.hw_intensity = self.fl_intensity
|
||||
self:_decideFrontlightState()
|
||||
-- And let the footer know of the change
|
||||
if package.loaded["ui/uimanager"] ~= nil then
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
|
||||
end
|
||||
end
|
||||
|
||||
-- Turn off front light before suspend.
|
||||
function KoboPowerD:beforeSuspend()
|
||||
if self.fl == nil then return end
|
||||
-- Remember the current frontlight state
|
||||
self.fl_was_on = self:isFrontlightOnHW()
|
||||
-- Turn off the frontlight
|
||||
self:turnOffFrontlight()
|
||||
end
|
||||
@@ -336,6 +362,8 @@ end
|
||||
-- Restore front light state after resume.
|
||||
function KoboPowerD:afterResume()
|
||||
if self.fl == nil then return end
|
||||
-- Don't bother if the light was already off on suspend
|
||||
if not self.fl_was_on then return end
|
||||
-- Update AutoWarmth state
|
||||
if self.fl_warmth ~= nil and self.auto_warmth then
|
||||
self:calculateAutoWarmth()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local Device = require("device")
|
||||
|
||||
local with_frontlight = (Device:isCervantes() or Device:isKindle() or Device:isKobo()) and Device:hasFrontlight()
|
||||
local with_natural_light = (Device:isCervantes() or Device:isKobo()) and Device:hasNaturalLight()
|
||||
local with_natural_light = Device:hasNaturalLight()
|
||||
if not (with_frontlight or Device:isSDL()) then
|
||||
return { disabled = true, }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user