Menus
Menus are reusable objects that can be attached to four different contexts: a context menu (right-click), a tray menu, a dock menu (macOS), or a menu bar (application menu on macOS, window menu bar on Windows/Linux).
The creation flow is the same for all four: you define a menu template (array of items) and pass it to the matching create* method. Each method returns a menuId you can use later to destroy, re-attach, or detach the menu.
Templates can be defined inline (passed directly to a create* method) or stored once and reused via templateId. Templates are useful when the same menu structure is used in multiple contexts.
macOS specifics: On macOS, the menu bar is a single application-wide menu, not per-window. Clipboard shortcuts (Cut/Copy/Paste/Select All) only work when the application menu is configured with those roles — consider always defining at least a minimal Edit submenu on macOS.
Methods
Create Context Menu
Creates a context menu that shows up when the user right-clicks.
await window.deskifier.menus.createContext({ arguments })
Arguments
templateArray
Array of Electron.MenuItem entries. Required unlesstemplateIdis provided.templateIdString
ID of a previously-stored template (see Add Menu Template). Required unlesstemplateis provided.idString
The ID for this menu. If omitted, one will be generated.selectorsArray Of Strings
An optional list of CSS selectors that control when the context menu is shown. When selectors are provided, the context menu will only appear when the user right-clicks on an element that matches one of the specified selectors. Default behavior is to show the context menu on any right-click target.
Returns
menuIdString
The ID of the new menu.successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Example
<pre class="language-javascript" data-overflow="wrap"><code class="lang-javascript">const template = [ { label: "File", submenu: [ { label: "New", accelerator: "CmdOrCtrl+N" }, { label: "Open", accelerator: "CmdOrCtrl+O" }, { type: "separator" }, { role: "quit" } ] }, { label: "View", submenu: [ { role: "toggledevtools" }, { role: "reload" }, { type: "separator" }, { role: "togglefullscreen" } ] }, { label: "Settings", submenu: [ { label: "Dark Mode", type: "checkbox", checked: false }, { label: "Enable Notifications", type: "radio", checked: true } ] } ];
<strong>const menu = await window.deskifier.menus.createContext({ </strong><strong> template, </strong><strong> selectors: ['#specificId', '.class1', '.class2'] </strong><strong>}); </strong> console.log(menu.menuId) // '7795d507-bf71-41d2-a505-16a0e48fe651' </code></pre>
Create Tray Menu
Creates a menu and attaches it to an existing tray icon.
await window.deskifier.menus.createTray({ arguments })
Arguments
templateArray
Array of Electron.MenuItem entries. Required unlesstemplateIdis provided.templateIdString
ID of a previously-stored template. Required unlesstemplateis provided.trayIdString (Required)
The ID of the tray to attach the menu to.idString
The ID for this menu. If omitted, one will be generated.
Returns
menuIdString
The ID of the new menu.successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Create Dock Menu
macOS Creates a dock menu. This appears when the user right-clicks the app's dock icon on macOS.
await window.deskifier.menus.createDock({ arguments })
Arguments
templateArray
Array of Electron.MenuItem entries. Required unlesstemplateIdis provided.templateIdString
ID of a previously-stored template. Required unlesstemplateis provided.idString
The ID for this menu. If omitted, one will be generated.
Returns
menuIdString
The ID of the new menu.successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Example
await window.deskifier.menus.createDock({
template: [
{ id: 'new-window', label: 'New Window' },
{ id: 'preferences', label: 'Preferences...' },
{ type: 'separator' },
{ role: 'quit' }
]
});
Create Menubar Menu
Creates a menu for use in a menu bar or an application menu.
Menu bars are per-window on Windows and Linux. On macOS, this sets the application menu — all windows share it, and the windowId argument is ignored.
await window.deskifier.menus.createMenubar({ arguments })
Arguments
templateArray
Array of Electron.MenuItem entries. Required unlesstemplateIdis provided.templateIdString
ID of a previously-stored template. Required unlesstemplateis provided.windowIdString
The ID of the window the menu bar should be attached to. Defaults to the current window. Ignored on macOS — the application menu is set instead.idString
The ID for this menu. If omitted, one will be generated.
Returns
menuIdString
The ID of the new menu.successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Example
<pre class="language-javascript" data-overflow="wrap"><code class="lang-javascript">const template = [ { label: "File", submenu: [ { label: "New", accelerator: "CmdOrCtrl+N" }, { label: "Open", accelerator: "CmdOrCtrl+O" }, { type: "separator" }, { role: "quit" } ] } ];
<strong>const menu = await window.deskifier.menus.createMenubar({ </strong><strong> template </strong><strong>}); </strong> console.log(menu.menuId) // '7795d507-bf71-41d2-a505-16a0e48fe651'
</code></pre>
Destroy Menu
Destroys a menu. Automatically detaches it from any tray, dock, menu bar, or context it was attached to.
await window.deskifier.menus.destroy({ arguments })
Arguments
menuIdString (Required)
Returns
successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Attach Menu
Attaches an existing menu to a new context. Useful for swapping a menu's role at runtime — for example, turning a context menu into a tray menu, or re-attaching a menu bar to a different window.
await window.deskifier.menus.attach({ arguments })
Arguments
menuIdString (Required)
The menu to attach.typeString (Required)
Target context type. Possible values:menuBar— attach as the menu bar. On macOS this sets the application menu; otherwise attaches towindowId(or the sender window).contextMenu— attach as a context (right-click) menu. Can be scoped withselectors.trayMenu— attach to the tray specified bytrayId.dockMenu— attach as the macOS dock menu.
trayIdString
Required whentypeistrayMenu.windowIdString
Used whentypeismenuBaron Windows/Linux. Defaults to the sender window.selectorsArray Of Strings
Used whentypeiscontextMenu. CSS selectors that gate when the menu appears.
Returns
successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Detach Menu
Detaches a menu from a context without destroying it. The menu can be re-attached later via Attach Menu.
await window.deskifier.menus.detach({ arguments })
Arguments
menuIdString (Required)typeString (Required)
The context type to detach from. Possible values:menuBar,contextMenu,trayMenu,dockMenu.
Returns
successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Popup Menu
Programmatically opens a menu at a specified location. Fires the Popup Menu Closed event when dismissed.
await window.deskifier.menus.popup({ arguments })
Arguments
menuIdString (Required)windowIdString
Optional. Defaults to the sender window.xNumber
Optional. Default is current mouse cursor position. Required ifyis declared.yNumber
Optional. Default is current mouse cursor position. Required ifxis declared.
Returns
successBoolean
If the action was successful.
Add Menu Template
Stores a menu template for reuse. Once added, any create* method can reference it by templateId instead of inlining the template.
await window.deskifier.menus.addTemplate({ arguments })
Arguments
idString (Required)
The ID to store this template under.templateArray (Required)
Array of Electron.MenuItem entries.nameString
Optional human-readable name shown in Get Available Menu Templates.menuTypeString
Optional hint about which context this template is intended for. Possible values:menuBar,contextMenu,trayMenu,dockMenu. Purely informational.
Returns
successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Delete Menu Template
Removes a stored template. Does not affect menus already created from it.
await window.deskifier.menus.deleteTemplate({ arguments })
Arguments
idString (Required)
Returns
successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Properties
Get Menus
Returns details about all active menus.
await window.deskifier.menus.getAll()
Returns
menusArray of ObjectsidString
ID of the menu.menuTypeString
Possible values:menuBar,trayMenu,contextMenu,dockMenu, ornullif the menu has been created but not yet attached.itemsArray of Electron.MenuItemcheckedBoolean
If the type is a checkbox or radio button this will indicate the value.enabledBooleanidString
ID of the Menu Item.labelString
Label of the Menu Item.submenuArray of Electron.MenuItemtypeString
Possible values:normal,separator,submenu,checkbox,radio.
trayIdString
The tray ID if themenuTypeistrayMenu. Otherwisenull.selectorsArray Of Strings
CSS selectors that gate when acontextMenuis shown. Empty means match any right-click target.windowIdString
The window a menu bar is attached to. Empty on macOS since menu bars are app-wide.
successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Example
<pre class="language-javascript"><code class="lang-javascript">const menus = await window.deskifier.menus.getAll();
console.log(menus.menus) <strong> </strong>/* [ { "id": "056dc6eb-c0d1-4b7d-91b4-7041a82f3a5e", "menuType": "trayMenu", "items": [{ checked: false, enabled: true, id: "id-i6naztjkh", label: "File", submenu: [], type: "normal" }], "trayId": "dca8a7f9-fcfc-4284-9353-c567491adb11", "windowId": null, "selectors": [] } ] */ </code></pre>
Get Available Menu Templates
Returns all menu templates previously stored via Add Menu Template.
await window.deskifier.menus.getAvailableTemplates()
Returns
templatesArray of Objects
Each object represents a stored template with itsid, optionalname, optionalmenuType, and the template structure itself.successBoolean
If the action was successful.messageString
Additional confirmation, or error details if action was unsuccessful.
Events
Menu Item Clicked
Fires when a menu item is clicked. Also fires for checkbox/radio state changes.
window.deskifier.menus.onItemClicked((data) => {})
Arguments
menuIdString
The menu ID.itemIdString
The menu item ID.contextIdString
The parent context ID (e.g., if the click came from a tray menu, this is thetrayId). May be undefined.labelString
The menu item label.checkedBoolean
If the menu item is a checkbox or radio button, this is its state.
Example
<pre class="language-javascript"><code class="lang-javascript">window.deskifier.menus.onItemClicked((data) => { console.log(data); }); <strong> </strong>/* { "menuId": "490b59d9-27c1-410d-99be-e4ed39ab6c32", "itemId": "exampleMenuItem", "contextId": "ed4b2aec-6a06-4589-9734-ee8ce3a06a86", "label": "New", "checked": false } */ </code></pre>
Context Menu Opened
Fires when a custom context menu opens in response to a right-click.
window.deskifier.menus.onContextMenuOpened((data) => {})
Arguments
menuIdString
The menu ID.nullfor native/built-in context menus that aren't tied to a custom menu.
Context Menu Closed
Fires when a context menu is dismissed.
window.deskifier.menus.onContextMenuClosed((data) => {})
Arguments
menuIdString
The menu ID.nullfor native/built-in context menus.
Popup Menu Closed
Fires when a menu opened via Popup Menu is dismissed.
window.deskifier.menus.onPopupClosed((data) => {})
Arguments
menuIdString
The menu ID.
Menu Object Updated
Fires whenever the set of menus changes — a menu is created, destroyed, attached, or detached. Useful for keeping a list of known menus in sync without polling.
window.deskifier.menus.onObjectUpdated((data) => {})
Arguments
menusArray of Objects
The full current menu list, same shape as Get Menus.