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:

FieldTypePurpose
labelstringVisible item text. Optional when a role supplies its standard label.
actionstringCustom action emitted when selected.
rolestringNative menu command. Do not combine it with action.
submenuApplicationMenuItemConfig[]Nested items.
enabledbooleanDisable interaction when false.
checkedbooleanShow the checked state.
hiddenbooleanHide the item.
tooltipstringNative tooltip where supported.
acceleratorstringSingle-key custom shortcut; Command on macOS and Control on Windows.
dataunknownSerializable application data attached to the action.

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

Roles

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.

Stateful items

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.