Skip to content

Menu bar: own the status item and rebuild the panel on every open - #62

Merged
broisnees merged 1 commit into
mainfrom
fix/menu-panel-rebuilt
Oct 31, 2026
Merged

broisnees merged 1 commit into
mainfrom
fix/menu-panel-rebuilt

Conversation

@broisnees

Copy link
Copy Markdown
Collaborator

Problem

After eWiz had been running for hours (~10h here), the menu-bar panel opened looking normal but nothing in it responded. Logs showed AppKit tracking each click and sending the action, yet the SwiftUI action never ran (rest.snoozeUntil unchanged after Later) and the panel never redrew. Relaunching eWiz fixed it. MenuBarExtra(.window) builds one panel window at launch and reuses it forever, and that window had come loose from its view graph.

Change

  • MenuBarController (new) owns an NSStatusItem that hosts MenuBarLabel, and builds a borderless NSPanel + NSHostingView on every open, discarded on close (resign key, Esc, outside click, icon click). There is no long-lived panel left to go stale.
  • The window takes its size from the content's constraints in the same layout pass, and setFrame pins the top edge and clamps to the screen. This fixes the flicker on mode switches and the panel running off the right edge.
  • A hidden MenuBarExtra(isInserted: false) stops SwiftUI opening Settings at launch. The no-⌘Q command moves to the Settings scene.
  • The panel's helper-install error moves into ChargeLimitStore so it survives the admin prompt closing the panel. The panel seeds its height from the last measurement.

Verified

  • swift build, and all 262 tests pass
  • Packaged 99.0.0 build running locally: the icon shows, the panel opens on screen, nothing opens by itself at launch, and openWindow works from the hosted label (History opened)
  • Helper reinstalled through the bundled admin-prompt route: daemon running, socket answers protocol 8 / build 28

MenuBarExtra(.window) builds its panel once and reuses it for the process's life.
After ~10 hours one went deaf: AppKit tracked clicks and sent actions, but no
SwiftUI action ran and nothing redrew, until eWiz was relaunched.

MenuBarController now owns an NSStatusItem hosting MenuBarLabel, and builds a
borderless NSPanel + NSHostingView on each open, torn down on close (resign key,
Esc, outside click, icon click). The window sizes from the content's own
constraints in the same layout pass, and setFrame pins the top edge and clamps
to the screen, which fixes the mode-switch flicker and the off-screen right edge.

Follow-ons of rebuilding the panel each open:
- a hidden MenuBarExtra(isInserted: false) keeps SwiftUI from opening Settings
  at launch, and the no-Cmd-Q command moves to the Settings scene
- the panel's helper-install error lives in ChargeLimitStore, not view state
- the panel seeds its height from the last measurement instead of growing in
@broisnees
broisnees merged commit 05688d4 into main Oct 31, 2026
1 check passed
@broisnees
broisnees deleted the fix/menu-panel-rebuilt branch October 31, 2026 15:45
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