Skip to content

[mac] fix: open document from launcher when "Keep running in menu bar" is off#375

Merged
Shpigford merged 1 commit into
Shpigford:mainfrom
tonkapark:fix/launcher-quits-with-menubar-off
May 22, 2026
Merged

[mac] fix: open document from launcher when "Keep running in menu bar" is off#375
Shpigford merged 1 commit into
Shpigford:mainfrom
tonkapark:fix/launcher-quits-with-menubar-off

Conversation

@tonkapark

Copy link
Copy Markdown
Contributor

Summary

  • When "Keep running in menu bar" is off and launchBehavior is filePicker or nothing, picking a file or "New Document" in the SwiftUI DocumentGroup launcher caused the app to quit before the chosen document opened. Both applicationShouldTerminate and applicationShouldTerminateAfterLastWindowClosed fire on launcher dismiss in this combo, and the existing menubar-off branches returned .terminateNow / true immediately.
  • Adds an isDocumentPanelPresented flag set in applicationDidFinishLaunching whenever no document will auto-open at launch (so the SwiftUI launcher is about to show). The two terminate methods consult it via a shared scheduleDeferredQuitIfPanelInFlight() that holds quit off for 3 seconds, giving the user-picked document time to register in NSDocumentController.shared.documents.
  • Flag is cleared from updateActivationPolicy once a real NSDocument exists. hasDocumentWindows() matches the launcher itself by frame, so using the controller's documents collection (which the launcher is absent from) is the authoritative "real doc is up" signal.
  • Diagnostic logging added at the new decision points — left in deliberately; trivial cost and what made this bug diagnosable.

Test plan

  • "Keep running in menu bar" off + "On Launch: Show file picker": pick a file in launcher → file opens (previously: app quit).
  • "Keep running in menu bar" off + "On Launch: Show file picker": pick "New Document" in launcher → new untitled opens.
  • "Keep running in menu bar" off + "On Launch: Do nothing": launcher pick of either kind → opens correctly.
  • "Keep running in menu bar" off + "On Launch: Create new document": untitled opens at launch, no regression.
  • "Keep running in menu bar" off + "On Launch: Open last file": last file opens, no regression.
  • Close last doc with "Keep running in menu bar" off → app still quits as expected (no 3s hang on every quit).
  • "Keep running in menu bar" on: launcher still works, no behavior change.

…" is off

The SwiftUI DocumentGroup launcher fired both applicationShouldTerminate
  and applicationShouldTerminateAfterLastWindowClosed on dismiss, quitting
  the app before the user-picked document finished loading. Track when a
  panel is in flight (any launchBehavior that doesn't auto-open a doc) and
  defer termination 3s so the chosen document has time to register. (aided by Claude)
@Shpigford Shpigford merged commit 55a2828 into Shpigford:main May 22, 2026
2 checks passed
Shpigford added a commit that referenced this pull request May 28, 2026
…nubar mode (#378)

The SwiftUI DocumentGroup launcher dismiss fires applicationShouldTerminate
with the user-picked doc already added to NSDocumentController.documents but
its SwiftUI scene still mid-construction. With "Keep running in menu bar" on
(the default), the existing path falls through to closeAllDocuments, tearing
the brand-new doc down before its window finishes building and crashing the
app (#377). PR #375 fixed the same race for the menubar-off branch; this
extends the isDocumentPanelPresented guard to the menubar-on path so the
default-config users see the same protection.
GPTAlgoPro pushed a commit to GPTAlgoPro/clearly that referenced this pull request Jul 8, 2026
…nubar mode (Shpigford#378)

The SwiftUI DocumentGroup launcher dismiss fires applicationShouldTerminate
with the user-picked doc already added to NSDocumentController.documents but
its SwiftUI scene still mid-construction. With "Keep running in menu bar" on
(the default), the existing path falls through to closeAllDocuments, tearing
the brand-new doc down before its window finishes building and crashing the
app (Shpigford#377). PR Shpigford#375 fixed the same race for the menubar-off branch; this
extends the isDocumentPanelPresented guard to the menubar-on path so the
default-config users see the same protection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants