mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #2004 from koreader/houqp-master
test flush config before suspend
This commit is contained in:
@@ -356,12 +356,12 @@ function ReaderUI:showReader(file)
|
||||
end)
|
||||
end
|
||||
|
||||
local running_instance = nil
|
||||
local _running_instance = nil
|
||||
function ReaderUI:doShowReader(file)
|
||||
dbg("opening file", file)
|
||||
-- keep only one instance running
|
||||
if running_instance then
|
||||
running_instance:onClose()
|
||||
if _running_instance then
|
||||
_running_instance:onClose()
|
||||
end
|
||||
local document = DocumentRegistry:openDocument(file)
|
||||
if not document then
|
||||
@@ -388,11 +388,11 @@ function ReaderUI:doShowReader(file)
|
||||
document = document,
|
||||
}
|
||||
UIManager:show(reader)
|
||||
running_instance = reader
|
||||
_running_instance = reader
|
||||
end
|
||||
|
||||
function ReaderUI:_getRunningInstance()
|
||||
return running_instance
|
||||
return _running_instance
|
||||
end
|
||||
|
||||
function ReaderUI:unlockDocumentWithPassword(document, try_again)
|
||||
@@ -493,8 +493,8 @@ function ReaderUI:onClose()
|
||||
UIManager:close(self.dialog, "full")
|
||||
-- serialize last used items for later launch
|
||||
Cache:serialize()
|
||||
if running_instance == self then
|
||||
running_instance = nil
|
||||
if _running_instance == self then
|
||||
_running_instance = nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -47,16 +47,16 @@ function UIManager:init()
|
||||
-- suspend. So let's unschedule it when suspending, and restart it after
|
||||
-- resume.
|
||||
self:_initAutoSuspend()
|
||||
self.event_handlers["Suspend"] = function(input_event)
|
||||
self.event_handlers["Suspend"] = function()
|
||||
self:_stopAutoSuspend()
|
||||
Device:onPowerEvent(input_event)
|
||||
Device:onPowerEvent("Suspend")
|
||||
end
|
||||
self.event_handlers["Resume"] = function(input_event)
|
||||
Device:onPowerEvent(input_event)
|
||||
self.event_handlers["Resume"] = function()
|
||||
Device:onPowerEvent("Resume")
|
||||
self:sendEvent(Event:new("Resume"))
|
||||
self:_startAutoSuspend()
|
||||
end
|
||||
self.event_handlers["PowerPress"] = function(input_event)
|
||||
self.event_handlers["PowerPress"] = function()
|
||||
self._power_ev_handled = false
|
||||
local showPowerOffDialog = function()
|
||||
if self._power_ev_handled then return end
|
||||
@@ -80,10 +80,10 @@ function UIManager:init()
|
||||
end
|
||||
UIManager:scheduleIn(3, showPowerOffDialog)
|
||||
end
|
||||
self.event_handlers["PowerRelease"] = function(input_event)
|
||||
self.event_handlers["PowerRelease"] = function()
|
||||
if not self._power_ev_handled then
|
||||
self._power_ev_handled = true
|
||||
self.event_handlers["Suspend"]("Suspend")
|
||||
self.event_handlers["Suspend"]()
|
||||
end
|
||||
end
|
||||
self.event_handlers["Light"] = function()
|
||||
|
||||
@@ -94,6 +94,44 @@ describe("device module", function()
|
||||
os.getenv:revert()
|
||||
mock_input.open:revert()
|
||||
end)
|
||||
|
||||
it("should flush book settings before suspend", function()
|
||||
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local Device = require("device")
|
||||
local NickelConf = require("device/kobo/nickel_conf")
|
||||
|
||||
stub(NickelConf.frontLightLevel, "get")
|
||||
stub(NickelConf.frontLightState, "get")
|
||||
NickelConf.frontLightLevel.get.returns(1)
|
||||
NickelConf.frontLightState.get.returns(0)
|
||||
|
||||
local UIManager = require("ui/uimanager")
|
||||
stub(Device, "suspend")
|
||||
stub(Device.powerd, "beforeSuspend")
|
||||
stub(Device, "isKobo")
|
||||
|
||||
Device.isKobo.returns(true)
|
||||
local saved_noop = UIManager._resetAutoSuspendTimer
|
||||
UIManager:init()
|
||||
|
||||
ReaderUI:doShowReader(sample_pdf)
|
||||
local readerui = ReaderUI._getRunningInstance()
|
||||
stub(readerui, "onFlushSettings")
|
||||
UIManager.event_handlers["PowerPress"]()
|
||||
UIManager.event_handlers["PowerRelease"]()
|
||||
assert.stub(readerui.onFlushSettings).was_called()
|
||||
|
||||
Device.suspend:revert()
|
||||
Device.powerd.beforeSuspend:revert()
|
||||
Device.isKobo:revert()
|
||||
NickelConf.frontLightLevel.get:revert()
|
||||
NickelConf.frontLightState.get:revert()
|
||||
UIManager._startAutoSuspend = nil
|
||||
UIManager._stopAutoSuspend = nil
|
||||
UIManager._resetAutoSuspendTimer = saved_noop
|
||||
readerui:onClose()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("kindle", function()
|
||||
|
||||
Reference in New Issue
Block a user