CLOSES #883, CLOSES #887, CLOSES #894

This commit is contained in:
bryanthaboi
2026-08-06 06:36:12 -04:00
parent e2820e02c5
commit cb6cfb5556
13 changed files with 476 additions and 39 deletions
+33 -2
View File
@@ -30,6 +30,21 @@ end
local Game, EditorApp, Importer, TouchEditor
-- #887: quit-to-launcher state, shared by love.load and love.quit (both need
-- it, so it is declared here rather than next to love.quit).
-- * launchedIntoGame -- a --game / POKEPORT_GAME shortcut booted this
-- session straight into a game, so there is no launcher behind it and a
-- window close must exit. Restarting instead re-read the same shortcut
-- and came right back into the game, and the next close did it again:
-- the app could not be closed at all (macOS feels this worst, where the
-- red X, Cmd+Q and the Dock's Quit are all the same quit event).
-- * RELAUNCH_MARKER -- written in the save dir just before the #785
-- restart, so the fresh boot ignores any boot-straight-into-a-game
-- option exactly once and keeps #785's promise of landing in the
-- launcher, whatever put the game on screen this time.
local launchedIntoGame = false
local RELAUNCH_MARKER = "relaunch_to_launcher.txt"
local autopilot -- optional scripted-input dev tool (tests/autopilot.lua)
local driverCo -- optional frame-driver (POKEPORT_DRIVER=file.lua): a
-- coroutine that receives `Game` and yields once per
@@ -334,10 +349,19 @@ function love.load(args)
-- EmulationStation needs: one click into the game the player wants, with no
-- menu in between. A game that is not imported falls through to the
-- launcher on its tab rather than booting into nothing.
-- A window close that restarted us into the launcher (#785) leaves the
-- marker behind: consume it and stay on the launcher, or the shortcut below
-- would boot the same game again and that close would restart again,
-- forever (#887). Consumed on read, so the very next launch is normal.
local relaunched = love.filesystem.getInfo(RELAUNCH_MARKER) ~= nil
if relaunched then pcall(love.filesystem.remove, RELAUNCH_MARKER) end
local launchGame, launchSlot = LaunchOptions.resolve(arg)
if launchGame and not LaunchOptions.forceLauncher(arg) then
if launchGame and not relaunched and not LaunchOptions.forceLauncher(arg) then
if RomImporter.isReady(launchGame) then
if launchSlot then LaunchOptions.selectSlot(launchGame, launchSlot) end
-- No launcher behind this session: love.quit must exit, not restart.
launchedIntoGame = true
bootGame(launchGame)
return
end
@@ -793,8 +817,15 @@ function love.quit()
-- restart path must be no worse than that, not quietly better.
local scripted = os.getenv("POKEPORT_AUTOPILOT") or os.getenv("POKEPORT_DRIVER")
or os.getenv("POKEPORT_IMPORT_ONLY") == "1" or os.getenv("POKEPORT_IMPORT_ROM")
if Game and not Importer and not quitToLauncher and not scripted then
-- #887: a shortcut session (--game / POKEPORT_GAME) has no launcher to go
-- back to and the restart would re-read the shortcut, so it exits instead.
if Game and not Importer and not quitToLauncher and not scripted
and not launchedIntoGame then
quitToLauncher = true
-- Tell the fresh boot to ignore any boot-straight-into-a-game option this
-- once, so the restart really does land in the launcher (#887). A failed
-- write only costs that suppression, so it must never block the restart.
pcall(love.filesystem.write, RELAUNCH_MARKER, "1")
require("src.core.HostShell").restart()
return true -- abort this quit; the restart lands back in the launcher
end