Repository navigation
fix(desktop): restore the native application menu and unify platform command routing - #2098
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-closedis a darwin no-op). Windows/Linux keep the menu suppressed and their renderer-ownedCtrl+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:
application-menu.ts— purebuildApplicationMenuTemplate()(darwin-only, returnsnullelsewhere) +installApplicationMenu(). Menu layout:role: 'editMenu'— keeps native Undo/Redo/Cut/Copy/Paste/Select All plus macOS's auto-appended Dictation and Emoji & Symbols. Not relabeled on purpose.!isPackagedrole: 'windowMenu'· Help: Keyboard Shortcuts → renderer keyboard helpwindow:command(newTask | openSettings | openHelp) — preloadsubscribeCommand(on/off idiom), renderer subscribes in the existing mount effect, handler is auseEffectEvent; menu clicks calldispatchonce.useHotkeysentry never also fires; the renderer path stays active for CDP-injected test keys and on Windows/Linux.whenReady(app-scoped, survives window close), not insidecreateWindow; dispatch re-creates the window when none exists (quitCoordinatormakes 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) — cleanapplication-menu.test.ts(template composition + semantic dispatch; no source-regex assertions) and the updated effect-stability contract with the new subscriptionnpm run lint+npm run format:check— clean--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 coordinatorkeystrokewas 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.