On MacOS, dynamically changing the enabled property of a menu item breaks keyboard accelerators in Electron 39.1.0 and later. The accelerator stops responding after a menu item is accessed via the native menu. Windows is OK.
| Electron Version | Status |
|---|---|
| 38.3.0 | Works correctly |
| 39.0.0 | Works correctly |
| 39.1.0 | BROKEN |
| 40.0.0 | BROKEN |
- Run the app:
npm install && npm start - Alternately press Cmd+O/Cmd+S & Menu action is logged.
- Then select "Open" from the menu & Menu action is logged. But Cmd+S accelerator no longer works.
- Then select "Save" from the menu & Menu action is logged. But Cmd+O accelerator no longer works.
Expected: The accelerator triggers the menu action and logs "Open clicked via menu!"
Actual: The accelerator does nothing. The keyboard shortcut is broken.
Rebuild the entire menu instead of mutating the enabled property:
// Instead of:
menuItem.enabled = false;
// Do this:
function rebuildMenu() {
const template = buildMenuTemplate(); // Returns template with current enabled states
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}- This regression appears to have been introduced in Electron 39.1.0
- Only the keyboard accelerator is broken
- Tested on macOS (Darwin)
- OS: macOS
- Electron: 40.0.0 (also reproduced in 39.1.0)