ReaderUI: minor optimization (#10634)

reviewable/pr10636/r1
hius07 10 months ago committed by GitHub
parent eb299c300d
commit dee1c902ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -451,7 +451,6 @@ function FileManager:init()
self:initGesListener()
self:handleEvent(Event:new("SetDimensions", self.dimen))
-- NOTE: ReaderUI has a _getRunningInstance method for this, because it used to store the instance reference in a private module variable.
if FileManager.instance == nil then
logger.dbg("Spinning up new FileManager instance", tostring(self))
else

@ -656,7 +656,7 @@ function ReaderUI:doShowReader(file, provider, seamless)
document = document,
}
local title = reader.document:getProps().title
local title = reader.doc_settings:readSetting("doc_props").title
if title ~= "" then
Screen:setWindowTitle(title)
@ -678,13 +678,6 @@ function ReaderUI:doShowReader(file, provider, seamless)
UIManager:show(reader, seamless and "ui" or "full")
end
-- NOTE: The instance reference used to be stored in a private module variable, hence the getter method.
-- We've since aligned behavior with FileManager, which uses a class member instead,
-- but kept the function to avoid changing existing code.
function ReaderUI:_getRunningInstance()
return ReaderUI.instance
end
function ReaderUI:unlockDocumentWithPassword(document, try_again)
logger.dbg("show input password dialog")
self.password_dialog = InputDialog:new{
@ -695,7 +688,6 @@ function ReaderUI:unlockDocumentWithPassword(document, try_again)
{
text = _("Cancel"),
id = "close",
enabled = true,
callback = function()
self:closeDialog()
coroutine.resume(self._coroutine)
@ -703,7 +695,6 @@ function ReaderUI:unlockDocumentWithPassword(document, try_again)
},
{
text = _("OK"),
enabled = true,
callback = function()
local success = self:onVerifyPassword(document)
self:closeDialog()
@ -767,7 +758,7 @@ function ReaderUI:notifyCloseDocument()
self:closeDocument()
else
UIManager:show(ConfirmBox:new{
text = _("Write highlights into this PDF??"),
text = _("Write highlights into this PDF?"),
ok_text = _("Write"),
dismissable = false,
ok_callback = function()
@ -889,11 +880,7 @@ function ReaderUI:onOpenLastDoc()
end
function ReaderUI:getCurrentPage()
if self.document.info.has_pages then
return self.paging.current_page
else
return self.document:getCurrentPage()
end
return self.paging and self.paging.current_page or self.document:getCurrentPage()
end
return ReaderUI

@ -156,7 +156,7 @@ function Screensaver:expandSpecial(message, fallback)
local batt_lvl = _("N/A")
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance()
local ui = ReaderUI.instance
if ui and ui.document then
-- If we have a ReaderUI instance, use it.
local doc = ui.document
@ -372,7 +372,7 @@ end
function Screensaver:isExcluded()
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance()
local ui = ReaderUI.instance
if ui and ui.doc_settings then
local doc_settings = ui.doc_settings
return doc_settings:isTrue("exclude_screensaver")
@ -508,7 +508,7 @@ function Screensaver:setup(event, event_message)
-- Check lastfile and setup the requested mode's resources, or a fallback mode if the required resources are unavailable.
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance()
local ui = ReaderUI.instance
local lastfile = G_reader_settings:readSetting("lastfile")
if self.screensaver_type == "document_cover" then
-- Set lastfile to the document of which we want to show the cover.
@ -639,7 +639,7 @@ function Screensaver:show()
}
elseif self.screensaver_type == "bookstatus" then
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance()
local ui = ReaderUI.instance
local doc = ui.document
local doc_settings = ui.doc_settings
widget = BookStatusWidget:new{

@ -960,8 +960,8 @@ function Menu:onCloseWidget()
-- Don't do anything if we're in the process of tearing down FM or RD, or if we don't actually have a live instance of 'em...
local FileManager = require("apps/filemanager/filemanager")
local ReaderUI = require("apps/reader/readerui")
local reader_ui = ReaderUI:_getRunningInstance()
if (FileManager.instance and not FileManager.instance.tearing_down) or (reader_ui and not reader_ui.tearing_down) then
if (FileManager.instance and not FileManager.instance.tearing_down)
or (ReaderUI.instance and not ReaderUI.instance.tearing_down) then
UIManager:setDirty(nil, "ui")
end
end

@ -649,8 +649,8 @@ function TouchMenu:onCloseWidget()
-- Don't do anything when we're switching between the two, or if we don't actually have a live instance of 'em...
local FileManager = require("apps/filemanager/filemanager")
local ReaderUI = require("apps/reader/readerui")
local reader_ui = ReaderUI:_getRunningInstance()
if (FileManager.instance and not FileManager.instance.tearing_down) or (reader_ui and not reader_ui.tearing_down) then
if (FileManager.instance and not FileManager.instance.tearing_down)
or (ReaderUI.instance and not ReaderUI.instance.tearing_down) then
UIManager:setDirty(nil, "flashui")
end
end

@ -367,7 +367,7 @@ describe("device module", function()
local sample_pdf = "spec/front/unit/data/tall.pdf"
local ReaderUI = require("apps/reader/readerui")
ReaderUI:doShowReader(sample_pdf)
local readerui = ReaderUI._getRunningInstance()
local readerui = ReaderUI.instance
stub(readerui, "onFlushSettings")
UIManager.event_handlers.PowerPress()
UIManager.event_handlers.PowerRelease()
@ -409,7 +409,7 @@ describe("device module", function()
local sample_pdf = "spec/front/unit/data/tall.pdf"
local ReaderUI = require("apps/reader/readerui")
ReaderUI:doShowReader(sample_pdf)
local readerui = ReaderUI._getRunningInstance()
local readerui = ReaderUI.instance
stub(readerui, "onFlushSettings")
UIManager.event_handlers.PowerPress()
UIManager.event_handlers.PowerRelease()
@ -457,7 +457,7 @@ describe("device module", function()
local sample_pdf = "spec/front/unit/data/tall.pdf"
local ReaderUI = require("apps/reader/readerui")
ReaderUI:doShowReader(sample_pdf)
local readerui = ReaderUI._getRunningInstance()
local readerui = ReaderUI.instance
stub(readerui, "onFlushSettings")
UIManager.event_handlers.PowerPress()
UIManager.event_handlers.PowerRelease()
@ -484,7 +484,7 @@ describe("device module", function()
local sample_pdf = "spec/front/unit/data/tall.pdf"
local ReaderUI = require("apps/reader/readerui")
ReaderUI:doShowReader(sample_pdf)
local readerui = ReaderUI._getRunningInstance()
local readerui = ReaderUI.instance
stub(readerui, "onFlushSettings")
-- UIManager.event_handlers.PowerPress() -- We only fake a Release event on the Emu
UIManager.event_handlers.PowerRelease()

@ -44,7 +44,7 @@ describe("Readerui module", function()
end)
it("should not reset ReaderUI.instance by mistake", function()
ReaderUI:doShowReader(sample_epub) -- spins up a new, sane instance
local new_readerui = ReaderUI:_getRunningInstance()
local new_readerui = ReaderUI.instance
assert.is.truthy(new_readerui.document)
-- This *will* trip:
-- * A pair of ReaderUI instance mimsatch warnings (on open/close) because it bypasses the safety of doShowReader!

Loading…
Cancel
Save