CreDocument: fix document loading interferences (#4349)

When a main document is opened for displaying, some other
document openings (for getting metadata or cover image)
could affect the main document.
Split some code from CreDocument:init() into another new
method CreDocument:setupDefaultView(), that will only be
called by ReaderUI when opening the main document (and not
by these other openings like Book inforation, View cover...)

Also speed up some of these other openings (Search, Screensaver)
by using doc:loadDocument(false) to load only metadata and
avoid parsing the HTML.

Details in https://github.com/koreader/koreader/issues/4346#issuecomment-440036496
pull/4352/head
poire-z 6 years ago committed by Frans de Jonge
parent 872c908a02
commit 85ac59ae00

@ -1 +1 @@
Subproject commit 84299a585587f306230c448f80e4e4811f2f990d Subproject commit 461b750936897041c115f5de6c94eb9e0309a5ee

@ -504,6 +504,9 @@ function Search:onMenuHold(item)
local thumbnail local thumbnail
local doc = DocumentRegistry:openDocument(item.path) local doc = DocumentRegistry:openDocument(item.path)
if doc then if doc then
if doc.loadDocument then -- CreDocument
doc:loadDocument(false) -- load only metadata
end
thumbnail = doc:getCoverPageImage() thumbnail = doc:getCoverPageImage()
doc:close() doc:close()
end end

@ -263,6 +263,11 @@ function ReaderUI:init()
document = self.document, document = self.document,
}) })
else else
-- load crengine default settings (from cr3.ini, some of these
-- will be overriden by our settings by some reader modules below)
if self.document.setupDefaultView then
self.document:setupDefaultView()
end
-- make sure we render document first before calling any callback -- make sure we render document first before calling any callback
self:registerPostInitCallback(function() self:registerPostInitCallback(function()
if not self.document:loadDocument() then if not self.document:loadDocument() then

@ -124,18 +124,6 @@ function CreDocument:init()
error(self._document) -- will contain error message error(self._document) -- will contain error message
end end
-- adjust font sizes according to screen dpi
self._document:adjustFontSizes(Screen:getDPI())
if G_reader_settings:readSetting("cre_header_status_font_size") then
self._document:setIntProperty("crengine.page.header.font.size",
G_reader_settings:readSetting("cre_header_status_font_size"))
end
-- set fallback font face
self._document:setStringProperty("crengine.font.fallback.face",
G_reader_settings:readSetting("fallback_font") or self.fallback_font)
-- We would have liked to call self._document:loadDocument(self.file) -- We would have liked to call self._document:loadDocument(self.file)
-- here, to detect early if file is a supported document, but we -- here, to detect early if file is a supported document, but we
-- need to delay it till after some crengine settings are set for a -- need to delay it till after some crengine settings are set for a
@ -160,6 +148,34 @@ function CreDocument:requestDomVersion(version)
cre.requestDomVersion(version) cre.requestDomVersion(version)
end end
function CreDocument:setupDefaultView()
if self.loaded then
-- Don't apply defaults if the document has already been loaded
-- as this must be done before calling loadDocument()
return
end
-- have crengine load defaults from cr3.ini
self._document:readDefaults()
logger.dbg("CreDocument: applied cr3.ini default settings.")
-- set fallback font face (this was formerly done in :init(), but it
-- affects crengine calcGlobalSettingsHash() and would invalidate the
-- cache from the main currently being read document when we just
-- loadDocument(only_metadata) another document go get its metadata
-- or cover image, eg. from History hold menu).
self._document:setStringProperty("crengine.font.fallback.face",
G_reader_settings:readSetting("fallback_font") or self.fallback_font)
-- adjust font sizes according to screen dpi
self._document:adjustFontSizes(Screen:getDPI())
-- set top status bar font size
if G_reader_settings:readSetting("cre_header_status_font_size") then
self._document:setIntProperty("crengine.page.header.font.size",
G_reader_settings:readSetting("cre_header_status_font_size"))
end
end
function CreDocument:loadDocument(full_document) function CreDocument:loadDocument(full_document)
if not self._loaded then if not self._loaded then
local only_metadata = full_document == false local only_metadata = full_document == false

@ -249,6 +249,9 @@ function Screensaver:show(event, fallback_message)
if exclude ~= true then if exclude ~= true then
if lfs.attributes(lastfile, "mode") == "file" then if lfs.attributes(lastfile, "mode") == "file" then
local doc = DocumentRegistry:openDocument(lastfile) local doc = DocumentRegistry:openDocument(lastfile)
if doc.loadDocument then -- CreDocument
doc:loadDocument(false) -- load only metadata
end
local image = doc:getCoverPageImage() local image = doc:getCoverPageImage()
doc:close() doc:close()
if image ~= nil then if image ~= nil then

Loading…
Cancel
Save