Skip to content

Wires up macOS 27 support - #26

Open
samhenrigold wants to merge 1 commit into
orchetect:mainfrom
samhenrigold:main
Open

Wires up macOS 27 support#26
samhenrigold wants to merge 1 commit into
orchetect:mainfrom
samhenrigold:main

Conversation

@samhenrigold

Copy link
Copy Markdown

Closes #25.

On macOS 27, window-based MenuBarExtra no longer uses the status item button's target/action. Presentation moved to AppKit's private "expanded interface session" machinery. A click begins an NSStatusItemExpandedInterfaceSession and notifies the item's expandedInterfaceDelegate (SwiftUI's WindowMenuBarExtraBehavior), which shows/hides the window.

This broke pretty much everything in this package.

Fix

All macOS 27 stuff is isolated in NSStatusItem+ExpandedInterfaceSession.swift and guarded by responds(to:) checks; macOS 26 and earlier is totally unchanged.

  • Present: call _beginExpandedInterfaceSession: directly. I found that _requestExpandedInterfaceSession is pretty flaky, AppKit drops begins whose event timestamp predates the last session end, so repeated programmatic presentation silently fails.
  • Dismiss: cancel expandedInterfaceSession which is the same call SwiftUI makes.
  • State: isMenuBarExtraPresented reads the session on 27, button state otherwise.
  • Disable: detach the delegate while disabled (stashed weakly, restored on re-enable) so a click never begins a session.
  • The resign-key failsafe cancels the session instead of closing the window, which would orphan the session.

@orchetect orchetect self-assigned this Jul 30, 2026
@orchetect orchetect added the bug Something isn't working label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Programmatically toggling visibility does not work on macOS 27

2 participants