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

  • template Array
    Array of Electron.MenuItem entries. Required unless templateId is provided.
  • templateId String
    ID of a previously-stored template (see Add Menu Template). Required unless template is provided.
  • id String
    The ID for this menu. If omitted, one will be generated.
  • selectors Array 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

  • menuId String
    The ID of the new menu.
  • success Boolean
    If the action was successful.
  • message String
    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

  • template Array
    Array of Electron.MenuItem entries. Required unless templateId is provided.
  • templateId String
    ID of a previously-stored template. Required unless template is provided.
  • trayId String (Required)
    The ID of the tray to attach the menu to.
  • id String
    The ID for this menu. If omitted, one will be generated.

Returns

  • menuId String
    The ID of the new menu.
  • success Boolean
    If the action was successful.
  • message String
    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

  • template Array
    Array of Electron.MenuItem entries. Required unless templateId is provided.
  • templateId String
    ID of a previously-stored template. Required unless template is provided.
  • id String
    The ID for this menu. If omitted, one will be generated.

Returns

  • menuId String
    The ID of the new menu.
  • success Boolean
    If the action was successful.
  • message String
    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

  • template Array
    Array of Electron.MenuItem entries. Required unless templateId is provided.
  • templateId String
    ID of a previously-stored template. Required unless template is provided.
  • windowId String
    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.
  • id String
    The ID for this menu. If omitted, one will be generated.

Returns

  • menuId String
    The ID of the new menu.
  • success Boolean
    If the action was successful.
  • message String
    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

  • menuId String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    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

  • menuId String (Required)
    The menu to attach.
  • type String (Required)
    Target context type. Possible values:
    • menuBar — attach as the menu bar. On macOS this sets the application menu; otherwise attaches to windowId (or the sender window).
    • contextMenu — attach as a context (right-click) menu. Can be scoped with selectors.
    • trayMenu — attach to the tray specified by trayId.
    • dockMenu — attach as the macOS dock menu.
  • trayId String
    Required when type is trayMenu.
  • windowId String
    Used when type is menuBar on Windows/Linux. Defaults to the sender window.
  • selectors Array Of Strings
    Used when type is contextMenu. CSS selectors that gate when the menu appears.

Returns

  • success Boolean
    If the action was successful.
  • message String
    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

  • menuId String (Required)
  • type String (Required)
    The context type to detach from. Possible values: menuBar, contextMenu, trayMenu, dockMenu.

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Programmatically opens a menu at a specified location. Fires the Popup Menu Closed event when dismissed.

await window.deskifier.menus.popup({ arguments })

Arguments

  • menuId String (Required)
  • windowId String
    Optional. Defaults to the sender window.
  • x Number
    Optional. Default is current mouse cursor position. Required if y is declared.
  • y Number
    Optional. Default is current mouse cursor position. Required if x is declared.

Returns

  • success Boolean
    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

  • id String (Required)
    The ID to store this template under.
  • template Array (Required)
    Array of Electron.MenuItem entries.
  • name String
    Optional human-readable name shown in Get Available Menu Templates.
  • menuType String
    Optional hint about which context this template is intended for. Possible values: menuBar, contextMenu, trayMenu, dockMenu. Purely informational.

Returns

  • success Boolean
    If the action was successful.
  • message String
    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

  • id String (Required)

Returns

  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Properties

Get Menus

Returns details about all active menus.

await window.deskifier.menus.getAll()

Returns

  • menus Array of Objects
    • id String
      ID of the menu.
    • menuType String
      Possible values: menuBar, trayMenu, contextMenu, dockMenu, or null if the menu has been created but not yet attached.
    • items Array of Electron.MenuItem
      • checked Boolean
        If the type is a checkbox or radio button this will indicate the value.
      • enabled Boolean
      • id String
        ID of the Menu Item.
      • label String
        Label of the Menu Item.
      • submenu Array of Electron.MenuItem
      • type String
        Possible values: normal, separator, submenu, checkbox, radio.
    • trayId String
      The tray ID if the menuType is trayMenu. Otherwise null.
    • selectors Array Of Strings
      CSS selectors that gate when a contextMenu is shown. Empty means match any right-click target.
    • windowId String
      The window a menu bar is attached to. Empty on macOS since menu bars are app-wide.
  • success Boolean
    If the action was successful.
  • message String
    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

  • templates Array of Objects
    Each object represents a stored template with its id, optional name, optional menuType, and the template structure itself.
  • success Boolean
    If the action was successful.
  • message String
    Additional confirmation, or error details if action was unsuccessful.

Events

Fires when a menu item is clicked. Also fires for checkbox/radio state changes.

window.deskifier.menus.onItemClicked((data) => {})

Arguments

  • menuId String
    The menu ID.
  • itemId String
    The menu item ID.
  • contextId String
    The parent context ID (e.g., if the click came from a tray menu, this is the trayId). May be undefined.
  • label String
    The menu item label.
  • checked Boolean
    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

  • menuId String
    The menu ID. null for 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

  • menuId String
    The menu ID. null for native/built-in context menus.

Fires when a menu opened via Popup Menu is dismissed.

window.deskifier.menus.onPopupClosed((data) => {})

Arguments

  • menuId String
    The menu ID.

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

  • menus Array of Objects
    The full current menu list, same shape as Get Menus.