mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ReaderStatus: Don't crash in EndOfDocument actions that *immediately* destroy the ReaderUI instance. (#7733)
This is handled in an Event handler, but we have zero guarantee that we're actually the *final* Event sent to the Document, and other Events usually kinda need the Document instance to still be alive ;). Delay action until the next tick to avoid potential crashes.
This commit is contained in:
@@ -144,8 +144,11 @@ function ReaderStatus:onEndOfBook()
|
||||
}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
self:openNextFile(self.document.file)
|
||||
UIManager:close(info)
|
||||
-- Delay until the next tick, as this will destroy the Document instance, but we may not be the final Event caught by said Document...
|
||||
UIManager:nextTick(function()
|
||||
self:openNextFile(self.document.file)
|
||||
end)
|
||||
else
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Could not open next file. Sort by last read date does not support this feature."),
|
||||
@@ -154,7 +157,10 @@ function ReaderStatus:onEndOfBook()
|
||||
elseif settings == "goto_beginning" then
|
||||
self.ui:handleEvent(Event:new("GoToBeginning"))
|
||||
elseif settings == "file_browser" then
|
||||
self:openFileBrowser()
|
||||
-- Ditto
|
||||
UIManager:nextTick(function()
|
||||
self:openFileBrowser()
|
||||
end)
|
||||
elseif settings == "mark_read" then
|
||||
self:onMarkBook(true)
|
||||
UIManager:show(InfoMessage:new{
|
||||
@@ -162,10 +168,16 @@ function ReaderStatus:onEndOfBook()
|
||||
timeout = 3
|
||||
})
|
||||
elseif settings == "book_status_file_browser" then
|
||||
local before_show_callback = function() self:openFileBrowser() end
|
||||
self:onShowBookStatus(before_show_callback)
|
||||
-- Ditto
|
||||
UIManager:nextTick(function()
|
||||
local before_show_callback = function() self:openFileBrowser() end
|
||||
self:onShowBookStatus(before_show_callback)
|
||||
end)
|
||||
elseif settings == "delete_file" then
|
||||
self:deleteFile(self.document.file, true)
|
||||
-- Ditto
|
||||
UIManager:nextTick(function()
|
||||
self:deleteFile(self.document.file, true)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -175,7 +187,6 @@ function ReaderStatus:openFileBrowser()
|
||||
if not FileManager.instance then
|
||||
self.ui:showFileManager()
|
||||
end
|
||||
self.document = nil
|
||||
end
|
||||
|
||||
function ReaderStatus:openNextFile(next_file)
|
||||
|
||||
Reference in New Issue
Block a user