Skip to content

Menu

Create native application and popup menus.

import { Menu, MenuItem } from 'miletus';

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.

let menu = new Menu();
menu.addMenuItem(...);

application.setMenu(menu);

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 coordinate
  • y 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

Event triggered when the popup menu opens.

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

Each MenuItem represents an item in the menu.

new MenuItem([options])

  • options MenuItemOptions
    • label 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. See globalShortcuts 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.