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

PropertyTypeDescription
itemsElectronMenuItem[]A MenuItem[] array containing the menu's items.

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

Methods

MethodReturnsDescription
addListener(event, listener)thisRegisters an event listener that is invoked when a popup is closed either manually or with ElectronMenu.closePopup.
addListener(event, listener)thisRegisters an event listener that is invoked when ElectronMenu.popup is called.
append(menuItem)voidAppends the menuItem to the menu.
buildFromTemplate(template)ElectronMenuGenerally, 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?)voidCloses the context menu in the browserWindow.
getApplicationMenu()ElectronMenu | nullReturns 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 | nullReturns the item with the specified id.
insert(pos, menuItem)voidInserts the menuItem to the pos position of the menu.
on('menu-will-close', listener)thisRegisters an event listener that is invoked when a popup is closed either manually or with ElectronMenu.closePopup.
on('menu-will-show', listener)thisRegisters an event listener that is invoked when ElectronMenu.popup is called.
once(event, listener)thisRegisters a one-time event listener that is invoked when a popup is closed either manually or with ElectronMenu.closePopup.
once(event, listener)thisRegisters a one-time event listener that is invoked when ElectronMenu.popup is called.
popup(options?)voidPops up this menu as a context menu in the BrowserWindow.
removeListener(event, listener)thisRemoves the event listener for a menu popup being closed.
removeListener(event, listener)thisRemoves the event listener for a menu popup being shown.
sendActionToFirstResponder(action)voidSends 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)voidSets 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: