The application menu had no File menu, so the close-window role (which carries the Cmd+W / Ctrl+W accelerator) was never registered. The Window menu role only provides Minimize, Zoom, and Bring All to Front, so there was no keyboard shortcut to close the window. Add a File menu with the close role to restore the standard accelerator on every platform.
Unified · Split
| @@ -846,9 +846,18 @@ const installApplicationMenu = () => { · 845 unmodified lines | ||
| 846 | 846 | { role: "quit" }, |
| 847 | 847 | ], |
| 848 | 848 | }; |
| 849 | + // The close-window accelerator (Cmd+W on macOS, Ctrl+W elsewhere) lives on | |
| 850 | + // the `close` role, which the File menu carries. The Window menu's role only | |
| 851 | + // provides Minimize/Zoom/Front, so without an explicit File menu nothing | |
| 852 | + // binds Cmd+W and the window can't be closed from the keyboard. | |
| 853 | + const fileMenu: MenuItemConstructorOptions = { | |
| 854 | + label: "File", | |
| 855 | + submenu: [{ role: "close" }], | |
| 856 | + }; | |
| 849 | 857 | Menu.setApplicationMenu( |
| 850 | 858 | Menu.buildFromTemplate([ |
| 851 | 859 | appMenu, |
| 860 | + fileMenu, | |
| 852 | 861 | { role: "editMenu" }, |
| 853 | 862 | { role: "viewMenu" }, |
| 854 | 863 | { role: "windowMenu" }, |