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
| @@ -853,9 +853,18 @@ const installApplicationMenu = () => { · 852 unmodified lines | ||
| 853 | 853 | { role: "quit" }, |
| 854 | 854 | ], |
| 855 | 855 | }; |
| 856 | + // The close-window accelerator (Cmd+W on macOS, Ctrl+W elsewhere) lives on | |
| 857 | + // the `close` role, which the File menu carries. The Window menu's role only | |
| 858 | + // provides Minimize/Zoom/Front, so without an explicit File menu nothing | |
| 859 | + // binds Cmd+W and the window can't be closed from the keyboard. | |
| 860 | + const fileMenu: MenuItemConstructorOptions = { | |
| 861 | + label: "File", | |
| 862 | + submenu: [{ role: "close" }], | |
| 863 | + }; | |
| 856 | 864 | Menu.setApplicationMenu( |
| 857 | 865 | Menu.buildFromTemplate([ |
| 858 | 866 | appMenu, |
| 867 | + fileMenu, | |
| 859 | 868 | { role: "editMenu" }, |
| 860 | 869 | { role: "viewMenu" }, |
| 861 | 870 | { role: "windowMenu" }, |