Browse Source

ReadHistory: nil guard a Document instance access

We're now more careful about this, so, I suppose weird timings may mean
we might be trying to access a nil here.

Fix #7706

Guard a few other similar constructs
reviewable/pr7711/r1
NiLuJe 6 months ago
parent
commit
90c38e2d0d
3 changed files with 6 additions and 6 deletions
  1. +1
    -1
      frontend/apps/filemanager/filemanagerhistory.lua
  2. +1
    -1
      frontend/readhistory.lua
  3. +4
    -4
      frontend/ui/screensaver.lua

+ 1
- 1
frontend/apps/filemanager/filemanagerhistory.lua View File

@ -44,7 +44,7 @@ end
function FileManagerHistory:onMenuHold(item)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document.file
local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file
self.histfile_dialog = nil
local buttons = {
{

+ 1
- 1
frontend/readhistory.lua View File

@ -30,7 +30,7 @@ local function buildEntry(input_time, input_file)
-- mandatory = file_exists and util.getFriendlySize(lfs.attributes(input_file, "size") or 0),
mandatory_func = function() -- Show the last read time (rather than file size)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document.file
local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file
local last_read_ts
if file_path == currently_opened_file then
-- Don't use the sidecar file date which is updated regularly while

+ 4
- 4
frontend/ui/screensaver.lua View File

@ -118,7 +118,7 @@ local function expandSpecial(message, fallback)
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance()
if ui then
if ui and ui.document then
-- If we have a ReaderUI instance, use it.
local doc = ui.document
currentpage = ui.view.state.page or currentpage
@ -303,7 +303,7 @@ end
function Screensaver:isExcluded()
local ReaderUI = require("apps/reader/readerui")
local ui = ReaderUI:_getRunningInstance()
if ui then
if ui and ui.doc_settings then
local doc_settings = ui.doc_settings
return doc_settings:isTrue("exclude_screensaver")
else
@ -415,7 +415,7 @@ function Screensaver:setup(event, fallback_message)
local excluded
if DocSettings:hasSidecarFile(self.lastfile) then
local doc_settings
if ui then
if ui and ui.doc_settings then
doc_settings = ui.doc_settings
else
doc_settings = DocSettings:open(self.lastfile)
@ -427,7 +427,7 @@ function Screensaver:setup(event, fallback_message)
end
if not excluded then
if self.lastfile and lfs.attributes(self.lastfile, "mode") == "file" then
if ui then
if ui and ui.document then
local doc = ui.document
self.image = doc:getCoverPageImage()
else

Loading…
Cancel
Save