mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Tweak SleepCover handling a bit on Kobo
Specifically, how we ignore it. No longer do anything specific and potentially racy, and let the unexpected wakeup handler take care of putting us back to sleep. Also add an option to only ignore wakeup events from the SleepCover. Re #5098 Re #5087
This commit is contained in:
@@ -107,13 +107,28 @@ if Device:setDateTime() then
|
||||
end
|
||||
|
||||
if Device:isKobo() then
|
||||
common_settings.sleepcover = {
|
||||
text = _("Ignore sleepcover events"),
|
||||
common_settings.ignore_sleepcover = {
|
||||
text = _("Ignore all sleepcover events"),
|
||||
checked_func = function()
|
||||
return G_reader_settings:isTrue("ignore_power_sleepcover")
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("ignore_power_sleepcover")
|
||||
G_reader_settings:flipFalse("ignore_open_sleepcover")
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("This will take effect on next restart."),
|
||||
})
|
||||
end
|
||||
}
|
||||
|
||||
common_settings.ignore_open_sleepcover = {
|
||||
text = _("Ignore sleepcover wakeup events"),
|
||||
checked_func = function()
|
||||
return G_reader_settings:isTrue("ignore_open_sleepcover")
|
||||
end,
|
||||
callback = function()
|
||||
G_reader_settings:flipNilOrFalse("ignore_open_sleepcover")
|
||||
G_reader_settings:flipFalse("ignore_power_sleepcover")
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("This will take effect on next restart."),
|
||||
})
|
||||
|
||||
@@ -40,7 +40,8 @@ local order = {
|
||||
"time",
|
||||
"battery",
|
||||
"autosuspend",
|
||||
"sleepcover",
|
||||
"ignore_sleepcover",
|
||||
"ignore_open_sleepcover",
|
||||
"mass_storage_settings",
|
||||
},
|
||||
navigation = {
|
||||
|
||||
@@ -60,7 +60,8 @@ local order = {
|
||||
"time",
|
||||
"battery",
|
||||
"autosuspend",
|
||||
"sleepcover",
|
||||
"ignore_sleepcover",
|
||||
"ignore_open_sleepcover",
|
||||
"mass_storage_settings",
|
||||
},
|
||||
navigation = {
|
||||
|
||||
@@ -117,7 +117,22 @@ function UIManager:init()
|
||||
self:suspend()
|
||||
end
|
||||
end
|
||||
if not G_reader_settings:readSetting("ignore_power_sleepcover") then
|
||||
-- Sleep Cover handling
|
||||
if G_reader_settings:readSetting("ignore_power_sleepcover") then
|
||||
-- NOTE: The hardware event itself will wake the kernel up if it's in suspend (:/).
|
||||
-- Let the unexpected wakeup guard handle that.
|
||||
self.event_handlers["SleepCoverClosed"] = nil
|
||||
self.event_handlers["SleepCoverOpened"] = nil
|
||||
elseif G_reader_settings:readSetting("ignore_open_sleepcover") then
|
||||
-- Just ignore wakeup events, and do NOT set is_cover_closed,
|
||||
-- so device/generic/device will let us use the power button to wake ;).
|
||||
self.event_handlers["SleepCoverClosed"] = function()
|
||||
self:suspend()
|
||||
end
|
||||
self.event_handlers["SleepCoverOpened"] = function()
|
||||
Device.is_cover_closed = false
|
||||
end
|
||||
else
|
||||
self.event_handlers["SleepCoverClosed"] = function()
|
||||
Device.is_cover_closed = true
|
||||
self:suspend()
|
||||
@@ -126,15 +141,6 @@ function UIManager:init()
|
||||
Device.is_cover_closed = false
|
||||
self:resume()
|
||||
end
|
||||
else
|
||||
-- Closing/opening the cover will still wake up the device, so we
|
||||
-- need to put it back to sleep if we are in screen saver mode
|
||||
self.event_handlers["SleepCoverClosed"] = function()
|
||||
if Device.screen_saver_mode then
|
||||
self:suspend()
|
||||
end
|
||||
end
|
||||
self.event_handlers["SleepCoverOpened"] = self.event_handlers["SleepCoverClosed"]
|
||||
end
|
||||
self.event_handlers["Light"] = function()
|
||||
Device:getPowerDevice():toggleFrontlight()
|
||||
|
||||
Reference in New Issue
Block a user