mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
refactor(statistics): avoid magic 0.1 schedule with PostRender event
This commit is contained in:
@@ -259,11 +259,14 @@ function ReaderUI:init()
|
||||
self:registerPostInitCallback(function()
|
||||
self.document:loadDocument()
|
||||
|
||||
-- read additional settings after the document has been loaded
|
||||
-- (but not rendered yet)
|
||||
-- used to read additional settings after the document has been
|
||||
-- loaded (but not rendered yet)
|
||||
self:handleEvent(Event:new("PreRenderDocument", self.doc_settings))
|
||||
|
||||
self.document:render()
|
||||
|
||||
-- CREngine only reports correct page count after rendering is done
|
||||
self:handleEvent(Event:new("PostRenderDocument", self.doc_settings))
|
||||
end)
|
||||
-- typeset controller
|
||||
self:registerModule("typeset", ReaderTypeset:new{
|
||||
|
||||
@@ -58,9 +58,7 @@ function ReaderStatistics:initData(config)
|
||||
if self.is_enabled then
|
||||
local book_properties = self:getBookProperties()
|
||||
self:savePropertiesInToData(book_properties)
|
||||
if config.data.stats then
|
||||
self.data = config.data.stats
|
||||
else
|
||||
if not self.data then
|
||||
--first time merge data
|
||||
self:inplaceMigration();
|
||||
end
|
||||
@@ -490,9 +488,12 @@ function ReaderStatistics:saveSettings(fields)
|
||||
end
|
||||
|
||||
function ReaderStatistics:onReadSettings(config)
|
||||
-- delay initialization for accurate total pages count of the doc
|
||||
UIManager:scheduleIn(0.1, function() self:initData(config) end)
|
||||
self.data = config.data.stats
|
||||
end
|
||||
|
||||
function ReaderStatistics:onPostRenderDocument()
|
||||
-- we have correct page count now, do the actual initialization work
|
||||
self:initData()
|
||||
end
|
||||
|
||||
return ReaderStatistics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user