Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MacOS Electron Menu Item enabled Property Regression

Summary

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.

Versions Tested

Electron Version Status
38.3.0 Works correctly
39.0.0 Works correctly
39.1.0 BROKEN
40.0.0 BROKEN

Steps to Reproduce

  1. Run the app: npm install && npm start
  2. Alternately press Cmd+O/Cmd+S & Menu action is logged.
  3. Then select "Open" from the menu & Menu action is logged. But Cmd+S accelerator no longer works.
  4. 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.

Workaround

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);
}

Additional Notes

  • This regression appears to have been introduced in Electron 39.1.0
  • Only the keyboard accelerator is broken
  • Tested on macOS (Darwin)

Environment

  • OS: macOS
  • Electron: 40.0.0 (also reproduced in 39.1.0)

About

Test repo for menu item accelerators

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages