Skip to content

fix(desktop): restore the native application menu and unify platform command routing - #2098

Merged
Astro-Han merged 2 commits into
mainfrom
fix/2088-restore-native-menu
Aug 4, 2026
Merged

Astro-Han merged 2 commits into
mainfrom
fix/2088-restore-native-menu

Conversation

@Astro-Han

Copy link
Copy Markdown
Contributor

Summary

Closes #2088.

Menu.setApplicationMenu(null) (main-window.ts, from PR #399) leaves macOS with no application menu at all — Cmd+Q has no handler, and after closing the window the process stays alive with the Dock tile lit (window-all-closed is a darwin no-op). Windows/Linux keep the menu suppressed and their renderer-owned Ctrl+N / Ctrl+, shortcuts untouched.

This restores a platform-appropriate native menu from Electron roles and routes its commands through the existing renderer actions over one typed channel — no duplicate command implementations:

  • New application-menu.ts — pure buildApplicationMenuTemplate() (darwin-only, returns null elsewhere) + installApplicationMenu(). Menu layout:
    • App: About · Settings… (⌘,) · Services · Hide/Hide Others/Show All · Quit
    • File: New Task (⌘N) · Close Window
    • Edit: role: 'editMenu' — keeps native Undo/Redo/Cut/Copy/Paste/Select All plus macOS's auto-appended Dictation and Emoji & Symbols. Not relabeled on purpose.
    • View: explicit zoom/fullscreen; Reload/DevTools only when !isPackaged
    • Window: role: 'windowMenu' · Help: Keyboard Shortcuts → renderer keyboard help
  • One channel: window:command (newTask | openSettings | openHelp) — preload subscribeCommand (on/off idiom), renderer subscribes in the existing mount effect, handler is a useEffectEvent; menu clicks call dispatch once.
  • Single accelerator owner per platform: on macOS AppKit resolves menu key equivalents before the web contents sees the keydown, so the renderer useHotkeys entry never also fires; the renderer path stays active for CDP-injected test keys and on Windows/Linux.
  • Menu installs once at whenReady (app-scoped, survives window close), not inside createWindow; dispatch re-creates the window when none exists (quitCoordinator makes that a no-op during quit).

Note: menu labels are English — Electron renders role menus (Edit, Window, …) in English anyway, so localizing only the custom items would split the menu bar's language.

Verification

  • npm run typecheck (desktop) — clean
  • Desktop main suite: 1592 tests pass, including 6 new ones in application-menu.test.ts (template composition + semantic dispatch; no source-regex assertions) and the updated effect-stability contract with the new subscription
  • npm run lint + npm run format:check — clean
  • Live macOS dev run (isolated --user-data-dir): menu bar shows Apple/Electron/File/Edit/View/Window/Help; Settings… sits under About, New Task under File; View shows Reload/Force Reload/Toggle Developer Tools in dev; menu-click Quit exits through the quit coordinator
  • Not verified: real Cmd+Q keystroke via automation (System Events keystroke was refused for the dev Electron process; menu accelerators are the same menu-item path as the verified click), and packaged-build menu behavior (Reload/DevTools absence is locked by the template test). Worth a quick manual check on the packaged app before merge.

PR #399 removed the Electron application menu (Menu.setApplicationMenu(null)),
which on macOS leaves Cmd+Q and the Edit roles without any handler — quitting
was impossible via keyboard and closing the window left the Dock tile lit.

Rebuild a platform-appropriate menu from native roles and route its commands
through the existing renderer actions over one typed channel:

- New application-menu.ts builds a darwin-only template: App (About, Settings,
  Services, Hide, Quit), File (New Task, Close), role-based Edit/Window, an
  explicit View menu with Reload/DevTools gated on isPackaged, and Help with
  a Keyboard Shortcuts entry. Non-darwin keeps setApplicationMenu(null) so
  Windows/Linux shell chrome and Ctrl+N / Ctrl+, behavior are untouched.
- Menu commands dispatch over window:command (newTask | openSettings |
  openHelp); the renderer already owns those implementations in
  app-shell-effects.ts, which subscribes in the existing mount effect.
- Menu accelerators are the single active owner on macOS: AppKit resolves
  menu key equivalents before the web contents sees the keydown, so the
  renderer useHotkeys entry never also fires.
- The menu installs once at whenReady (app-scoped, survives window close)
  instead of inside createWindow; dispatch re-creates the window when none
  exists.

Verified: 1592 desktop main tests pass (6 new menu tests), typecheck clean,
and on a real macOS dev run the menu bar shows App/File/Edit/View/Window/Help
with Settings… under About, New Task under File, dev-only Reload/DevTools,
and menu-click Quit exits through the quit coordinator.

Closes #2088
- Derive ApplicationMenuCommand from the preload WindowCommand contract so
  the two sides of the window:command channel cannot silently drift.
- Drop the unused labels injection point (dead abstraction; English labels
  are the documented decision).
- Lock the renderer-side routing with a stability-contract case: the
  window-command subscription must not duplicate across rerenders and must
  dispatch newTask/openSettings/openHelp to the existing actions.
- Note the deliberate command drop when no window exists next to the
  dispatch branch.
@Astro-Han
Astro-Han marked this pull request as ready for review August 4, 2026 07:13
@Astro-Han
Astro-Han merged commit 121bbe7 into main Aug 4, 2026
20 of 22 checks passed
@Astro-Han
Astro-Han deleted the fix/2088-restore-native-menu branch August 4, 2026 07:13
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.

fix(desktop): restore the native application menu and unify platform command routing

1 participant