Quit when the last window closes - #5
Merged
Merged
Conversation
Closing Schist's only window on macOS left the app running with nothing on screen: still in the dock, still holding the menu bar, and with no way back to a window, since nothing in the menus opens a second one. AppKit keeps a window-less app alive unless it is told otherwise, so say so. The other backends already end the process themselves once no window is left -- X11 and Wayland stop their event loop, Windows posts a quit message from the last close -- so the observer is macOS-only. That is not just to avoid a redundant call: `Platform::quit` is asynchronous on macOS and Windows but synchronous on Linux, where it re-enters the client state that is already borrowed to dispatch the close, and the process died on a "RefCell already borrowed" panic rather than shutting down. The gate is a `cfg!` rather than a `#[cfg]` so the callback keeps being type-checked wherever Schist builds. Co-Authored-By: Claude Opus 5 (1M context) <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.
Closing Schist's only window on macOS left the app running with nothing on screen — still in the dock, still holding the menu bar that #3 just moved up there, and with no route back to a window, since no menu item opens a second one. AppKit keeps a window-less app alive unless told otherwise, so an
on_window_closedobserver now quits oncecx.windows()is empty.The observer is macOS-only, for two reasons:
close_one_window.Platform::quitdefers to the main queue on macOS and to the foreground executor on Windows, but on Linux it callswith_commonstraight away, which re-borrows the client state this callback is already being dispatched from. Schist died onRefCell already borrowed(exit 101) instead of shutting down, skipping the rest of the quit path.It is a
cfg!rather than a#[cfg]so the callback stays type-checked wherever Schist builds, matching hownative_menuhandles the same split.Testing
cargo build -p schist-app.WM_DELETE_WINDOWto the app window: exits 0 with no panic, same as before this change. The intermediate ungated version is what turned up theRefCellpanic above.Window::on_close→remove_window(), which drops the window fromcx.windowsbefore the observers fire, so the emptiness check is accurate, and mac's deferredquitmeans calling it from inside the observer is safe.One thing to flag, unchanged by this PR but now easier to hit: there is no unsaved-changes prompt on window close (
Workspaceregisters noshould_closehandler), so closing the last window discards dirty tabs and quits. Crash-recovery snapshots are still written, exactly as with the existing Quit menu item.🤖 Generated with Claude Code