kobo(fix): do not wake up device when cover is closed

pull/2245/head
Qingping Hou 8 years ago
parent 93b3262db7
commit 4036e2c460

@ -9,6 +9,7 @@ local Device = {
screen_saver_mode = false, screen_saver_mode = false,
charging_mode = false, charging_mode = false,
survive_screen_saver = false, survive_screen_saver = false,
is_cover_closed = false,
model = nil, model = nil,
powerd = nil, powerd = nil,
screen = nil, screen = nil,
@ -113,35 +114,44 @@ function Device:outofScreenSaver()
self.screen_saver_mode = false self.screen_saver_mode = false
end end
function Device:scheduleSuspendIfNeeded()
local UIManager = require("ui/uimanager")
if not UIManager:hasScheduled(self.suspend) then
UIManager:nextTick(self.suspend)
end
end
-- ONLY used for Kobo and PocketBook devices -- ONLY used for Kobo and PocketBook devices
function Device:onPowerEvent(ev) function Device:onPowerEvent(ev)
if self.screen_saver_mode then if self.screen_saver_mode then
if ev == "Power" or ev == "Resume" then if ev == "Power" or ev == "Resume" then
DEBUG("Resuming...") if self.is_cover_closed then
require("ui/uimanager"):unschedule(self.suspend) -- don't let power key press wake up device when the cover is in closed state
local network_manager = require("ui/network/manager") self:scheduleSuspendIfNeeded()
if network_manager.wifi_was_on and G_reader_settings:nilOrTrue("auto_restore_wifi") then else
network_manager.restoreWifiAsync() DEBUG("Resuming...")
end require("ui/uimanager"):unschedule(self.suspend)
self:resume() local network_manager = require("ui/network/manager")
require("ui/screensaver"):close() if network_manager.wifi_was_on and G_reader_settings:nilOrTrue("auto_restore_wifi") then
-- restore to previous rotation mode network_manager.restoreWifiAsync()
self.screen:setRotationMode(self.orig_rotation_mode) end
if self:needsScreenRefreshAfterResume() then self:resume()
self.screen:refreshFull() require("ui/screensaver"):close()
-- restore to previous rotation mode
self.screen:setRotationMode(self.orig_rotation_mode)
if self:needsScreenRefreshAfterResume() then
self.screen:refreshFull()
end
self.screen_saver_mode = false
self.powerd:refreshCapacity()
self.powerd:afterResume()
end end
self.screen_saver_mode = false
self.powerd:refreshCapacity()
self.powerd:afterResume()
elseif ev == "Suspend" then elseif ev == "Suspend" then
-- Already in screen saver mode, no need to update UI/state before -- Already in screen saver mode, no need to update UI/state before
-- suspending the hardware. This usually happens when sleep cover -- suspending the hardware. This usually happens when sleep cover
-- is closed after the device was sent to suspend state. -- is closed after the device was sent to suspend state.
DEBUG("Already in screen saver mode, suspending...") DEBUG("Already in screen saver mode, suspending...")
local UIManager = require("ui/uimanager") self:scheduleSuspendIfNeeded()
if not UIManager:hasScheduled(self.suspend) then
UIManager:nextTick(self.suspend)
end
end end
-- else we we not in screensaver mode -- else we we not in screensaver mode
elseif ev == "Power" or ev == "Suspend" then elseif ev == "Power" or ev == "Suspend" then

@ -87,8 +87,14 @@ function UIManager:init()
end end
end end
if not G_reader_settings:readSetting("ignore_power_sleepcover") then if not G_reader_settings:readSetting("ignore_power_sleepcover") then
self.event_handlers["SleepCoverClosed"] = self.event_handlers["Suspend"] self.event_handlers["SleepCoverClosed"] = function()
self.event_handlers["SleepCoverOpened"] = self.event_handlers["Resume"] Device.is_cover_closed = true
self.event_handlers["Suspend"]()
end
self.event_handlers["SleepCoverOpened"] = function()
Device.is_cover_closed = false
self.event_handlers["Resume"]()
end
else else
-- Closing/opening the cover will still wake up the device, so we -- 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 -- need to put it back to sleep if we are in screen saver mode

Loading…
Cancel
Save