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 | { role: "quit" }, | 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 | Menu.setApplicationMenu( | 864 | Menu.setApplicationMenu( |
| 857 | Menu.buildFromTemplate([ | 865 | Menu.buildFromTemplate([ |
| 858 | appMenu, | 866 | appMenu, |
| 867 | fileMenu, | ||
| 859 | { role: "editMenu" }, | 868 | { role: "editMenu" }, |
| 860 | { role: "viewMenu" }, | 869 | { role: "viewMenu" }, |
| 861 | { role: "windowMenu" }, | 870 | { role: "windowMenu" }, |