Menu
Create native application and popup menus.
Application menu bar
Call application.setMenu()
to set the menu to be the application menu.
On macOS
this means the standard menu bar at the top of the screen.
On Windows
and Linux
this means a menu bar in the main window.
Note
The menu does not update automatically. After modifying the Menu
object, you'll need to call application.setMenu()
again.
Methods
addMenuItem(menuitem)
menuitem
MenuItem
- Menu item to be added.
Add a new menu item to Menu
.
insertMenuItem(pos, menuitem)
menuitem
MenuItem
- Menu item to be added.
Inert a menu item to a given position in the menu items array.
popup(x, y)
x
number - X screen coordinatey
number - Y screen coordinate
Show menu as popup at x
and y
coordinates.
closePopup()
Close popup menu programmatically.
getMenuItemById(id)
id
string - Unique ID of the menu item.
Returns corresponding MenuItem
. If cannot be found, returns undefined
.
Events
'popup-open'
Event triggered when the popup menu opens.
'menu-click'
Event triggered when a menu item has been clicked. The parameter is the clicked menu item object.
let menu = new Menu();
menu.addMenuItem(new MenuItem({label: "Item1"}));
menu.addMenuItem(new MenuItem({label: "Item2"}));
menu.addMenuItem(new MenuItem({label: "Item3"}));
menu.on('menu-click', (item) => {
alert(item.label + ' clicked!');
})
menu.popup(100, 100);
MenuItem class
Each MenuItem
represents an item in the menu.
new MenuItem([options])
options
MenuItemOptionslabel
string (optional) - Menu item label. Default""
.enabled
boolean (optional)hint
string (optional)radio
boolean (optional) - Radio item.checked
boolean (optional) - Make item checked by default.shortcut
string (optional) - Shortcut. SeeglobalShortcuts
for supported formats.submenu
Menu
(optional)id
string (optional) - Unique ID for item.click
Function (optional) - Item click handler.
All option items are available as properties of MenuItem
.