mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
PM: Minor refactor to suspend/resume code flow (#10426)
Make sure we only send Suspend/Resume events when we *actually* suspend/resume. This is done via the Device `_beforeSuspend`/`_afterResume` methods, and those were called by the *input handlers*, not the PM logic; which means they would fire, while the PM logic could actually take a smarter decision and *not* do what the event just sent implied ;). (i.e., sleep with a cover -> suspend + actual suspend, OK; but if you then resume with a button -> input assumes resume, but PM will actually suspend again!). Existing design issue made more apparent by #9448 ;). Also fixes/generalizes a few corner-cases related to screen_saver_lock handling (e.g., don't allow USBMS during a lock). And deal with the fallout of the main change to the Kobo frontlight ramp behavior ;).
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
local FFIUtil = require("ffi/util")
|
||||
local Generic = require("device/generic/device")
|
||||
local A, android = pcall(require, "android") -- luacheck: ignore
|
||||
local Event = require("ui/event")
|
||||
local Geom = require("ui/geometry")
|
||||
local Generic = require("device/generic/device")
|
||||
local UIManager
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local FFIUtil = require("ffi/util")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
@@ -129,8 +131,6 @@ function Device:init()
|
||||
device = self,
|
||||
event_map = event_map,
|
||||
handleMiscEv = function(this, ev)
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
logger.dbg("Android application event", ev.code)
|
||||
if ev.code == C.APP_CMD_SAVE_STATE then
|
||||
UIManager:broadcastEvent(Event:new("FlushSettings"))
|
||||
@@ -280,6 +280,10 @@ function Device:init()
|
||||
Generic.init(self)
|
||||
end
|
||||
|
||||
function Device:UIManagerReady(uimgr)
|
||||
UIManager = uimgr
|
||||
end
|
||||
|
||||
function Device:initNetworkManager(NetworkMgr)
|
||||
function NetworkMgr:turnOnWifi(complete_callback)
|
||||
android.openWifiSettings()
|
||||
@@ -483,7 +487,6 @@ function Device:showLightDialog()
|
||||
-- Delay it until next tick so that the event loop gets a chance to drain the input queue,
|
||||
-- and consume the APP_CMD_LOST_FOCUS event.
|
||||
-- This helps prevent ANRs on Tolino (c.f., #6583 & #7552).
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:nextTick(function() self:_showLightDialog() end)
|
||||
end
|
||||
|
||||
@@ -499,8 +502,6 @@ function Device:_showLightDialog()
|
||||
self.powerd.fl_warmth = self.powerd:frontlightWarmthHW()
|
||||
logger.dbg("Dialog OK, warmth: " .. self.powerd.fl_warmth)
|
||||
end
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
|
||||
elseif action == C.ALIGHTS_DIALOG_CANCEL then
|
||||
logger.dbg("Dialog Cancel, brightness: " .. self.powerd.fl_intensity)
|
||||
@@ -519,7 +520,6 @@ end
|
||||
function Device:download(link, name, ok_text)
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local ok = android.download(link, name)
|
||||
if ok == C.ADOWNLOAD_EXISTS then
|
||||
self:install()
|
||||
@@ -540,8 +540,6 @@ end
|
||||
|
||||
function Device:install()
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Event = require("ui/event")
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Update is ready. Install it now?"),
|
||||
ok_text = _("Install"),
|
||||
|
||||
Reference in New Issue
Block a user