diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index e196fde00..8968454ec 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -999,18 +999,6 @@ function FileManagerMenu:getStartWithMenuTable() end function FileManagerMenu:exitOrRestart(callback, force) - -- Only restart sets a callback, which suits us just fine for this check ;) - if callback and not force and not Device:isStartupScriptUpToDate() then - UIManager:show(ConfirmBox:new{ - text = _("KOReader's startup script has been updated. You'll need to completely exit KOReader to finalize the update."), - ok_text = _("Restart anyway"), - ok_callback = function() - self:exitOrRestart(callback, true) - end, - }) - return - end - UIManager:close(self.menu_container) self.ui:onClose() if callback then diff --git a/frontend/apps/reader/modules/readermenu.lua b/frontend/apps/reader/modules/readermenu.lua index c15cdcdeb..0145fb290 100644 --- a/frontend/apps/reader/modules/readermenu.lua +++ b/frontend/apps/reader/modules/readermenu.lua @@ -402,18 +402,6 @@ function ReaderMenu:saveDocumentSettingsAsDefault() end function ReaderMenu:exitOrRestart(callback, force) - -- Only restart sets a callback, which suits us just fine for this check ;) - if callback and not force and not Device:isStartupScriptUpToDate() then - UIManager:show(ConfirmBox:new{ - text = _("KOReader's startup script has been updated. You'll need to completely exit KOReader to finalize the update."), - ok_text = _("Restart anyway"), - ok_callback = function() - self:exitOrRestart(callback, true) - end, - }) - return - end - self:onTapCloseMenu() UIManager:nextTick(function() self.ui:onClose() diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index ec9b78481..623e4154c 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -854,7 +854,9 @@ function UIManager:unsetRunForeverMode() self._gated_quit = function() return self:quit(nil, true) end end --- Ignore an empty window stack *once*; for startup w/ a missing last_file shenanigans... +-- We'll want to return from this without actually quitting, so this is +-- a slightly mangled UIManager:run() call to coerce the main loop into +-- submission to ignore an empty window stack *once*. function UIManager:runOnce() -- We don't actually want to call self.quit, and we need to deal with a bit of trickery in there anyway... self._gated_quit = function() diff --git a/reader.lua b/reader.lua index 6fe9489d5..f9d631537 100755 --- a/reader.lua +++ b/reader.lua @@ -212,31 +212,30 @@ if G_reader_settings:isTrue("color_rendering") and not Device:hasColorScreen() t UIManager:broadcastEvent(Event:new("ColorRenderingUpdate")) end, }) + -- This will only return once the user has made a choice. + UIManager:runOnce() end --- Get which file to start with -local last_file = G_reader_settings:readSetting("lastfile") -local start_with = G_reader_settings:readSetting("start_with") or "filemanager" +local exit_code --- Helpers -local function retryLastFile() +if not Device:isStartupScriptUpToDate() then local ConfirmBox = require("ui/widget/confirmbox") - return ConfirmBox:new{ - text = _("Cannot open last file.\nThis could be because it was deleted or because external storage is still being mounted.\nDo you want to retry?"), + UIManager:show(ConfirmBox:new{ + text = _("KOReader's startup script has been updated. You'll need to completely exit KOReader to finalize the update."), + cancel_text = _("Ignore"), + ok_text = _("Quit"), ok_callback = function() - if lfs.attributes(last_file, "mode") ~= "file" then - UIManager:show(retryLastFile()) - end + exit_code = 0 end, - cancel_callback = function() - start_with = "filemanager" - end, - } + }) + -- This will only return once the user has made a choice. + UIManager:runOnce() end -- Start app -local exit_code -if file then +if exit_code then -- luacheck: ignore + -- We're quitting to finalize an update. +elseif file then local ReaderUI = require("apps/reader/readerui") ReaderUI:showReader(file) exit_code = UIManager:run() @@ -245,6 +244,10 @@ elseif directory then FileManager:showFiles(directory) exit_code = UIManager:run() else + -- Get which file to start with + local last_file = G_reader_settings:readSetting("lastfile") + local start_with = G_reader_settings:readSetting("start_with") or "filemanager" + local QuickStart = require("ui/quickstart") if not QuickStart:isShown() then start_with = "last" @@ -252,10 +255,22 @@ else end if start_with == "last" and last_file and lfs.attributes(last_file, "mode") ~= "file" then + local function retryLastFile() + local ConfirmBox = require("ui/widget/confirmbox") + return ConfirmBox:new{ + text = _("Cannot open last file.\nThis could be because it was deleted or because external storage is still being mounted.\nDo you want to retry?"), + ok_callback = function() + if lfs.attributes(last_file, "mode") ~= "file" then + UIManager:show(retryLastFile()) + end + end, + cancel_callback = function() + start_with = "filemanager" + end, + } + end UIManager:show(retryLastFile()) - -- We'll want to return from this without actually quitting, - -- so this is a slightly mangled UIManager:run() call to coerce the main loop into submission... - -- We'll call :run properly in either of the following branches once returning. + -- This will only return once the file is available or the user gave up. UIManager:runOnce() end if start_with == "last" and last_file then