Startup: Unbreak last_file when the file is missing

Fix #9887, likely a regression since #9669
reviewable/pr9909/r1
NiLuJe 1 year ago
parent 6c2d5c66da
commit 649af0be59

@ -825,6 +825,23 @@ function UIManager:unsetRunForeverMode()
self._gated_quit = self.quit self._gated_quit = self.quit
end end
-- Ignore an empty window stack *once*; for startup w/ a missing last_file shenanigans...
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()
-- We need this set to break the loop in UIManager:run()
self._exit_code = 0
-- And this is to break the loop in UIManager:handleInput()
return true
end
-- The idea being that we want to *return* from this run call, but *without* quitting.
-- NOTE: This implies that calling run multiple times across a single session *needs* to be safe.
self:run()
-- Restore standard behavior
self:unsetRunForeverMode()
self._exit_code = nil
end
--[[-- --[[--
Transmits an @{ui.event.Event|Event} to active widgets, top to bottom. Transmits an @{ui.event.Event|Event} to active widgets, top to bottom.
Stops at the first handler that returns `true`. Stops at the first handler that returns `true`.

@ -271,15 +271,11 @@ end
local exit_code local exit_code
if file then if file then
local ReaderUI = require("apps/reader/readerui") local ReaderUI = require("apps/reader/readerui")
UIManager:nextTick(function() ReaderUI:showReader(file)
ReaderUI:showReader(file)
end)
exit_code = UIManager:run() exit_code = UIManager:run()
elseif directory then elseif directory then
local FileManager = require("apps/filemanager/filemanager") local FileManager = require("apps/filemanager/filemanager")
UIManager:nextTick(function() FileManager:showFiles(directory)
FileManager:showFiles(directory)
end)
exit_code = UIManager:run() exit_code = UIManager:run()
else else
local QuickStart = require("ui/quickstart") local QuickStart = require("ui/quickstart")
@ -290,47 +286,38 @@ else
if start_with == "last" and last_file and lfs.attributes(last_file, "mode") ~= "file" then if start_with == "last" and last_file and lfs.attributes(last_file, "mode") ~= "file" then
UIManager:show(retryLastFile()) UIManager:show(retryLastFile())
-- no exit code as something else will be run after this. -- We'll want to return from this without actually quitting,
UIManager:run() -- 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.
UIManager:runOnce()
end end
if start_with == "last" and last_file then if start_with == "last" and last_file then
local ReaderUI = require("apps/reader/readerui") local ReaderUI = require("apps/reader/readerui")
UIManager:nextTick(function() -- Instantiate RD
-- Instantiate RD ReaderUI:showReader(last_file)
ReaderUI:showReader(last_file)
end)
exit_code = UIManager:run() exit_code = UIManager:run()
else else
local FileManager = require("apps/filemanager/filemanager") local FileManager = require("apps/filemanager/filemanager")
local home_dir = local home_dir = G_reader_settings:readSetting("home_dir") or Device.home_dir or lfs.currentdir()
G_reader_settings:readSetting("home_dir") or Device.home_dir or lfs.currentdir() -- Instantiate FM
UIManager:nextTick(function() FileManager:showFiles(home_dir)
-- Instantiate FM
FileManager:showFiles(home_dir)
end)
-- Always open FM modules on top of filemanager, so closing 'em doesn't result in an exit -- Always open FM modules on top of filemanager, so closing 'em doesn't result in an exit
-- because of an empty widget stack, and so they can interact with the FM instance as expected. -- because of an empty widget stack, and so they can interact with the FM instance as expected.
if start_with == "history" then if start_with == "history" then
local FileManagerHistory = require("apps/filemanager/filemanagerhistory") local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
UIManager:nextTick(function() FileManagerHistory:new{
FileManagerHistory:new{ ui = FileManager.instance,
ui = FileManager.instance, }:onShowHist()
}:onShowHist()
end)
elseif start_with == "favorites" then elseif start_with == "favorites" then
local FileManagerCollection = require("apps/filemanager/filemanagercollection") local FileManagerCollection = require("apps/filemanager/filemanagercollection")
UIManager:nextTick(function() FileManagerCollection:new{
FileManagerCollection:new{ ui = FileManager.instance,
ui = FileManager.instance, }:onShowColl("favorites")
}:onShowColl("favorites")
end)
elseif start_with == "folder_shortcuts" then elseif start_with == "folder_shortcuts" then
local FileManagerShortcuts = require("apps/filemanager/filemanagershortcuts") local FileManagerShortcuts = require("apps/filemanager/filemanagershortcuts")
UIManager:nextTick(function() FileManagerShortcuts:new{
FileManagerShortcuts:new{ ui = FileManager.instance,
ui = FileManager.instance, }:onShowFolderShortcutsDialog()
}:onShowFolderShortcutsDialog()
end)
end end
exit_code = UIManager:run() exit_code = UIManager:run()
end end
@ -342,8 +329,10 @@ local function exitReader()
local ko_exit = os.getenv("KO_EXIT_CODE") local ko_exit = os.getenv("KO_EXIT_CODE")
if ko_exit then if ko_exit then
local fo = io.open(ko_exit, "w+") local fo = io.open(ko_exit, "w+")
fo:write(tostring(exit_code)) if fo then
fo:close() fo:write(tostring(exit_code))
fo:close()
end
end end
local ReaderActivityIndicator = local ReaderActivityIndicator =

Loading…
Cancel
Save