Skip to content

Application Menu

Use ApplicationMenu.setApplicationMenu() in the main process. A role invokes native operating-system behavior; an action emits an event for application code.

import { ApplicationMenu } from "electrobun/main";
ApplicationMenu.setApplicationMenu([
{
label: "File",
submenu: [
{
label: "New project",
action: "new-project",
accelerator: "n",
},
{ type: "separator" },
{ role: "close" },
{ role: "quit" },
],
},
{
label: "Edit",
submenu: [
{ role: "undo" },
{ role: "redo" },
{ type: "separator" },
{ role: "cut" },
{ role: "copy" },
{ role: "paste" },
{ role: "selectAll" },
],
},
]);
ApplicationMenu.on("application-menu-clicked", (event: unknown) => {
console.log("Application menu action", event);
});

A normal item supports these fields:

Field Type Purpose
label string Visible item text. Optional when a role supplies its standard label.
action string Custom action emitted when selected.
role string Native menu command. Do not combine it with action.
submenu ApplicationMenuItemConfig[] Nested items.
enabled boolean Disable interaction when false.
checked boolean Show the checked state.
hidden boolean Hide the item.
tooltip string Native tooltip where supported.
accelerator string Single-key custom shortcut; Command on macOS and Control on Windows.
data unknown Serializable application data attached to the action.

Use { type: "separator" } or { type: "divider" } for a divider.

Common roles include about, quit, hide, hideOthers, showAll, minimize, zoom, close, toggleFullScreen, undo, redo, cut, copy, paste, pasteAndMatchStyle, delete, and selectAll.

Electrobun also accepts native text movement, selection, deletion, insertion, speech, and scrolling roles. Roles are forwarded to the platform menu system; unsupported roles have no native action on that platform.

Rebuild the menu when application state changes:

import { ApplicationMenu } from "electrobun/main";
let sidebarVisible = true;
function updateMenu() {
ApplicationMenu.setApplicationMenu([
{
label: "View",
submenu: [
{
label: "Show sidebar",
action: "toggle-sidebar",
checked: sidebarVisible,
},
],
},
]);
}
ApplicationMenu.on("application-menu-clicked", (event: unknown) => {
console.log(event);
sidebarVisible = !sidebarVisible;
updateMenu();
});
updateMenu();

Application menus are currently implemented on macOS and Windows. Linux apps should expose essential actions in application UI or a supported tray menu.