Skip to content

fix(desktop): stop onboarding bundles from relaunching - #6050

Merged
kodjima33 merged 1 commit into
mainfrom
fix/onboarding-relaunch-behavior
Mar 26, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
fix/onboarding-relaunch-behavior

Conversation

@kodjima33

Copy link
Copy Markdown
Collaborator

Summary

  • disable macOS relaunch-on-login while onboarding is incomplete
  • terminate the app when the last onboarding window closes instead of leaving a menu bar process running
  • re-enable relaunch-on-login once onboarding completes

Verification

  • built and launched the patched dev app with ./run.sh --yolo
  • relaunched the app into incomplete onboarding and confirmed onboarding UI appeared
  • sent Cmd-W to the onboarding window and confirmed the dev app process exited and stayed down
  • relaunched into onboarding again, quit the app explicitly, and confirmed the dev app process exited and stayed down

Notes

  • macOS restart behavior is inferred from NSApp.disableRelaunchOnLogin() / enableRelaunchOnLogin(); I did not reboot or log out the machine to test that path directly.

@kodjima33
kodjima33 merged commit 7674982 into main Mar 26, 2026
3 checks passed
@kodjima33
kodjima33 deleted the fix/onboarding-relaunch-behavior branch March 26, 2026 06:03
@greptile-apps

greptile-apps Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a macOS lifecycle bug where an incomplete-onboarding build of the app could be re-launched automatically at login and then left as a silent menu-bar process when its window was closed. The fix adds three coordinated changes to AppDelegate:\n\n- Relaunch-on-login suppression: updateOnboardingLifecyclePolicy is called at launch and whenever UserDefaults changes. It calls NSApp.disableRelaunchOnLogin() while hasCompletedOnboarding is false, and re-enables it the moment the key flips to true. A boolean flag (relaunchOnLoginSuppressedForOnboarding) prevents redundant system calls.\n- Terminal behaviour on last-window-close: applicationShouldTerminateAfterLastWindowClosed now returns true when hasCompletedOnboarding is false, terminating the process instead of leaving an invisible background app.\n- Cleanup: userDefaultsObserver is properly torn down in applicationWillTerminate alongside the existing windowObservers.\n\nThe implementation is logically correct. UserDefaults.standard.bool(forKey:) is read directly (not from SwiftUI state), so applicationShouldTerminateAfterLastWindowClosed always sees the latest persisted value even during SwiftUI view-update cycles, avoiding any race condition at the onboarding-completion boundary. One minor point: the UserDefaults.didChangeNotification observer fires for every key change in the app, not just \"hasCompletedOnboarding\" — this is harmless thanks to the guard pattern but worth tightening.

Confidence Score: 5/5

Safe to merge; the fix is well-scoped and the only open item is a non-blocking observer-scope style suggestion.

All three changes (disable relaunch-on-login, terminate on last-window-close during onboarding, re-enable after onboarding) are logically consistent and handle the sign-out/re-onboard path correctly. The guard-based state machine prevents redundant system calls, cleanup is properly wired into applicationWillTerminate, and the direct UserDefaults read in the terminate delegate avoids SwiftUI-state race conditions. The sole P2 observation (broad UserDefaults.didChangeNotification scope) does not affect correctness.

No files require special attention.

Important Files Changed

Filename Overview
desktop/Desktop/Sources/OmiApp.swift Adds three coordinated changes: disables macOS relaunch-on-login while onboarding is incomplete, terminates the app when the last window closes during onboarding, and re-enables relaunch-on-login once the onboarding key is set. Logic is correct; one minor concern about the breadth of the UserDefaults observer.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[applicationDidFinishLaunching] --> B[updateOnboardingLifecyclePolicy - launch]
    B --> C{hasCompletedOnboarding?}
    C -- No --> D[NSApp.disableRelaunchOnLogin\nrelaunchOnLoginSuppressedForOnboarding = true]
    C -- Yes --> E{relaunchOnLoginSuppressedForOnboarding?}
    E -- false --> F[return early — already enabled]
    E -- true --> G[NSApp.enableRelaunchOnLogin\nrelaunchOnLoginSuppressedForOnboarding = false]

    A --> H[Register UserDefaults.didChangeNotification observer]
    H --> I[Any UserDefaults write]
    I --> B

    J[applicationShouldTerminateAfterLastWindowClosed] --> K{hasCompletedOnboarding?}
    K -- No = onboarding --> L[return true — terminate app]
    K -- Yes = normal use --> M[return false — stay in menu bar]

    N[applicationWillTerminate] --> O[removeObserver userDefaultsObserver]
Loading

Reviews (1): Last reviewed commit: "fix(desktop): stop onboarding bundles fr..." | Re-trigger Greptile

Comment on lines +411 to +417
userDefaultsObserver = NotificationCenter.default.addObserver(
forName: UserDefaults.didChangeNotification,
object: nil,
queue: .main
) { [weak self] _ in
self?.updateOnboardingLifecyclePolicy(reason: "user_defaults_changed")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Observer fires on every UserDefaults write

UserDefaults.didChangeNotification is posted for every key change in the standard suite, not just "hasCompletedOnboarding". During normal operation this will invoke updateOnboardingLifecyclePolicy on each write (settings saves, analytics flags, feature toggles, etc.). The guard-based state machine inside the function makes each extra call virtually free once the flag is set, but if other parts of the app batch-write many keys this could fire dozens of times in quick succession.

A more targeted alternative is to pass UserDefaults.standard as the object: argument instead of nil. That limits delivery to the standard suite only and avoids notifications from any other UserDefaults suites the app may use. True key-level observation would require KVO on UserDefaults.standard, but the object: scope narrowing is a low-risk one-line improvement.

Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…#6050)

## Summary
- disable macOS relaunch-on-login while onboarding is incomplete
- terminate the app when the last onboarding window closes instead of
leaving a menu bar process running
- re-enable relaunch-on-login once onboarding completes

## Verification
- built and launched the patched dev app with `./run.sh --yolo`
- relaunched the app into incomplete onboarding and confirmed onboarding
UI appeared
- sent `Cmd-W` to the onboarding window and confirmed the dev app
process exited and stayed down
- relaunched into onboarding again, quit the app explicitly, and
confirmed the dev app process exited and stayed down

## Notes
- macOS restart behavior is inferred from
`NSApp.disableRelaunchOnLogin()` / `enableRelaunchOnLogin()`; I did not
reboot or log out the machine to test that path directly.
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.

1 participant