Skip to content

Fix intermittent failure to bring Preferences window forward - #47

Open
marcpbailey wants to merge 1 commit into
apexskier:mainfrom
marcpbailey:fix/window-activation
Open

Fix intermittent failure to bring Preferences window forward#47
marcpbailey wants to merge 1 commit into
apexskier:mainfrom
marcpbailey:fix/window-activation

Conversation

@marcpbailey

Copy link
Copy Markdown
Contributor

Confirmed via repeated testing: NSApp.activate() (macOS 14+) can silently decline to activate the app, with no error and no signal that it happened — the window then gets ordered front but stays behind whatever app was already frontmost. Switched to the forceful ignoringOtherApps: true unconditionally, which doesn't exhibit the same failure and is appropriate for a direct, deliberate user click on our own menu item.

Confirmed via NSLog instrumentation across repeated repro attempts:
NSApp.activate() (macOS 14+) can silently decline to activate the
app, with no error and no signal that it happened — the window then
gets ordered front but stays behind whatever app was already
frontmost. Switched to the forceful ignoringOtherApps: true
unconditionally. It's deprecated in favor of activate(), but doesn't
exhibit the same failure, and is the right tool here since this is a
direct, deliberate user click on our own menu item rather than
unsolicited background focus-stealing (the case the newer API's
heuristics are meant to guard against).

Accessory-policy (no Dock icon, i.e. LSUIElement) apps like this one
are the sharpest edge case for window activation in general — see
https://steipete.me/posts/2025/showing-settings-from-macos-menu-bar-items
for a deeper workaround (temporarily switching to .regular activation
policy) if this ever recurs.
@apexskier

Copy link
Copy Markdown
Owner

I've never seeing this issue, and don't love always using a deprecated API. When have you seen this reproduce?

@marcpbailey

Copy link
Copy Markdown
Contributor Author

Hi - thanks for looking at this so quickly.
I can't reproduce at will, but while I was testing I found that the preferences window would just not come to the top. There's a great article here about why this happens in particular with dockless menulets.
https://steipete.me/posts/2025/showing-settings-from-macos-menu-bar-items
I went with the simplest option - and agree I don't love it either - but I believe it's in very common use.
There is a more complicated approach to fixing this as detailed, but to be honest I needed to move on, having spent many hours hunting this particular wumpus.

I LOVE your app btw, and have been extending it to Markdown editors as well - similar problem. Sometimes I need Obsidian, others MacDown, others Antigravity, etc.

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