Skip to content

macOS: keep the menu-bar icon from vanishing when the window opens#229

Open
kevin-nous wants to merge 1 commit into
TomBadash:masterfrom
kevin-nous:fix/menu-bar-status-item-flicker
Open

macOS: keep the menu-bar icon from vanishing when the window opens#229
kevin-nous wants to merge 1 commit into
TomBadash:masterfrom
kevin-nous:fix/menu-bar-status-item-flicker

Conversation

@kevin-nous

Copy link
Copy Markdown

Problem

On macOS, opening the window (e.g. clicking the menu-bar icon) makes the menu-bar
icon disappear until the app is relaunched. Opening the window promotes the app
.accessory -> .regular to give the window a Dock tile + Cmd-Tab entry, and that
activation-policy flip detaches our custom NSStatusItem from the menu bar: the object
survives (it's strongly referenced), but its menu-bar slot is dropped. On a
multi-monitor setup it's especially confusing — the window opens on one display while
the icon vanishes on another, so it reads as the app having quit.

Fix

Re-create the status item right after the .regular flip, mirroring the existing
_schedule_macos_dock_icon_refresh 0ms + 250ms double-fire so it works whether AppKit
detaches the item synchronously or a tick later. A re-install drops any prior item
first, so it never leaves a duplicate. The intended Dock-tile-on-window-open behavior
is preserved.

Known limitation (being upfront)

This turns "icon vanishes until relaunch" into "icon blinks briefly and returns" — but
a one-frame blink remains, because the activation-policy toggle inherently tears the
status item off the menu bar before we can re-add it. I tried a synchronous re-install
to close the gap; it still blinks, so the detach isn't cleanly synchronous. Fully
eliminating the blink would mean not toggling activation policy (i.e. dropping the
Dock tile / Cmd-Tab entry for the window) — a deliberate design call I've left to you
rather than change unilaterally. Happy to follow up either way.

Testing

Verified on a real MX Anywhere 2S / macOS, including the multi-monitor case that
surfaced it: before, the icon vanished permanently; after, it returns immediately.
Menu (right/control/option-click) and Dock-tile behavior are unchanged.

Clicking the status-item promotes the app .accessory -> .regular (for a Dock
tile + Cmd-Tab), and that activation-policy flip detaches our custom
NSStatusItem from the menu bar -- the object survives, but its menu-bar slot
is dropped, so the icon disappears until the app is relaunched.

Re-create the status item right after the flip, mirroring the existing
_schedule_macos_dock_icon_refresh 0ms+250ms double-fire so it works whether
AppKit detaches synchronously or a tick later. Installing now drops any prior
item first, so a re-install never leaves a duplicate. Preserves the intended
Dock-tile-on-window-open behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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