Fix loader lingering or force-quitting on macOS Cmd+Q - #85
Open
peter-bonanni wants to merge 2 commits into
Open
Conversation
On macOS, Cmd+Q is delivered through Tk's tk::mac::Quit handler rather than WM_DELETE_WINDOW, so it bypassed quit() entirely. Depending on the Tk build this either terminated the process immediately (skipping unload(), leaving spacehaven.jar patched) or destroyed the window while the non-daemon launch thread kept the loader alive as a headless process waiting on the game. Register tk::mac::Quit to route Cmd+Q through the same guarded quit() as the close button, and mark the background task thread as a daemon so the interpreter can always exit once the GUI is gone. Fixes Spacehaven-modding-tools#74 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
peter-bonanni
marked this pull request as draft
June 11, 2026 01:19
Author
|
Automated fix, take it or leave it. Tested and it seems to work. |
peter-bonanni
marked this pull request as ready for review
June 11, 2026 01:20
If quit() destroys the window while a previously scheduled update_background_state tick is still pending, the callback fires afterward and tries to configure launchButton, raising 'invalid command name ...'. handleException then attempts messagebox.showerror on the now-destroyed root, raising again and crashing the process (exit code 1) instead of just logging. Bail out of update_background_state if the window is gone, and make handleException tolerate a missing root. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tk::mac::Quitso Cmd+Q on macOS routes through the same guardedquit()as the window close button, instead of bypassing it via Tk's default Quit handler.Why
On macOS, Cmd+Q is delivered through Tk's
tk::mac::Quithandler rather thanWM_DELETE_WINDOW, so it bypassedquit()entirely. Depending on the Tk build this either terminated the process immediately (skippingunload(), leavingspacehaven.jarpatched) or destroyed the window while the non-daemon launch thread kept the loader alive as a headless process waiting on the game to exit — matching thepsoutput in the issue.Fixes #74
Test plan
uv run python -m unittest discover -s tests)ruff checkpasses