Repository navigation
fix(desktop): stop onboarding bundles from relaunching - #6050
Conversation
Greptile SummaryThis 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 Confidence Score: 5/5Safe 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
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]
Reviews (1): Last reviewed commit: "fix(desktop): stop onboarding bundles fr..." | Re-trigger Greptile |
| userDefaultsObserver = NotificationCenter.default.addObserver( | ||
| forName: UserDefaults.didChangeNotification, | ||
| object: nil, | ||
| queue: .main | ||
| ) { [weak self] _ in | ||
| self?.updateOnboardingLifecyclePolicy(reason: "user_defaults_changed") | ||
| } |
There was a problem hiding this comment.
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.
…#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.
Summary
Verification
./run.sh --yoloCmd-Wto the onboarding window and confirmed the dev app process exited and stayed downNotes
NSApp.disableRelaunchOnLogin()/enableRelaunchOnLogin(); I did not reboot or log out the machine to test that path directly.