Skip to content

ElectronMenu

Unofficial

Electron Menu for creating native application menus and context menus.

Import:

import type { ElectronMenu } from '@obsidian-typings/obsidian-public-latest';

Signature:

export class ElectronMenu

Properties

Property Type Description
items ElectronMenuItem[] A MenuItem[] array containing the menu's items.

Each menu consists of multiple menu items and each menu item can have a submenu.

Methods

Method Returns Description
addListener(event, listener) this Registers an event listener that is invoked when a popup is closed either manually or with ElectronMenu.closePopup.
addListener(event, listener) this Registers an event listener that is invoked when ElectronMenu.popup is called.
append(menuItem) void Appends the menuItem to the menu.
buildFromTemplate(template) ElectronMenu Generally, the template is an array of options for constructing a menu item.

You can also attach other fields to the elements of the template and they will become properties of the constructed menu items.
closePopup(browserWindow?) void Closes the context menu in the browserWindow.
getApplicationMenu() ElectronMenu | null Returns the application menu, if set, or null, if not set.

The returned menu instance doesn't support dynamic addition or removal of menu items. Instance properties can still be dynamically modified.
getMenuItemById(id) ElectronMenuItem | null Returns the item with the specified id.
insert(pos, menuItem) void Inserts the menuItem to the pos position of the menu.
on('menu-will-close', listener) this Registers an event listener that is invoked when a popup is closed either manually or with ElectronMenu.closePopup.
on('menu-will-show', listener) this Registers an event listener that is invoked when ElectronMenu.popup is called.
once(event, listener) this Registers a one-time event listener that is invoked when a popup is closed either manually or with ElectronMenu.closePopup.
once(event, listener) this Registers a one-time event listener that is invoked when ElectronMenu.popup is called.
popup(options?) void Pops up this menu as a context menu in the BrowserWindow.
removeListener(event, listener) this Removes the event listener for a menu popup being closed.
removeListener(event, listener) this Removes the event listener for a menu popup being shown.
sendActionToFirstResponder(action) void Sends the action to the first responder of application. This is used for emulating default macOS menu behaviors. Usually you would use the role property of a menu item. darwin only.
setApplicationMenu(menu) void Sets menu as the application menu on macOS. On Windows and Linux, the menu will be set as each window's top menu.

Passing null will suppress the default menu. On Windows and Linux, this has the additional effect of removing the menu bar from the window.

Links to this page: