Fix crash on launch on macOS 14 (Sonoma) - #90
Merged
Conversation
Defer NSStatusItem creation from property initializer to applicationDidFinishLaunching. On macOS 14, SwiftUI creates the @NSApplicationDelegateAdaptor before the window server (CGS) connection is established, causing an assertion failure in CGSConnectionByID when NSStatusBar.system.statusItem is called during AppDelegate.init(). Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
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
SIGABRTinCGSConnectionByID) affecting all macOS 14.x (Sonoma) users.Problem
The app crashes immediately on launch on macOS 14.x — the status bar icon never appears and the app silently terminates. Confirmed by multiple crash reports from App Store Connect on macOS 14.6.1, 14.8.2, and 14.8.3.
Crash stack trace:
Root Cause
NSStatusBar.system.statusItem(withLength:)was called as a property initializer inAppDelegate, which runs duringinit(). On macOS 14.x, SwiftUI creates the@NSApplicationDelegateAdaptorbefore the window server (CGS) connection is established.NSStatusIteminitialization requires a valid CGS connection to register notification handlers, causing an assertion failure →abort().On macOS 26, SwiftUI establishes the CGS connection earlier so this happened to work — but it was never safe to call during
init().Fix
Defer
NSStatusItemcreation from the property initializer toapplicationDidFinishLaunching, where the CGS connection is guaranteed to be ready.func applicationDidFinishLaunching(_: Notification) { AppDelegate.shared = self + self.statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) self.setupStatusItem()Summary by cubic
Fixes a launch crash on macOS 14 (Sonoma) by creating the status bar item after the app finishes launching. Sonoma users can now start the app and see the menu bar icon.
Written for commit a10ae9f. Summary will update on new commits.