new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

app/menu

54 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

app.applicationMenu property

A read-write property that is Menu | null. Returns Menu if one has been set and null otherwise. Users can pass a Menu to set this property.

Menu constructor

The Menu class can be instantiated with new Menu() to create a new menu instance.

menu.popup([options]) instance method

Pops up a menu as a context menu in a BaseWindow. The options parameter is optional and includes: window (BaseWindow, optional, default focused window), frame (WebFrameMain, optional, for OS-level features like macOS Writing Tools), x (number, optional, default current mouse cursor position, must be declared if y is declared), y (number, optional, default current mouse cursor position, must be declared if x is declared), positioningItem (number, optional, macOS only, index of menu item to position under cursor, default -1), sourceType (string, optional, Windows and Linux only, maps to menuSourceType from context-menu event, can be 'none', 'mouse', 'keyboard', 'touch', 'touchMenu', 'longPress', 'longTap', 'touchHandle', 'stylus', 'adjustSelection', or 'adjustSelectionReset'), and callback (Function, optional, called when menu is closed).

menu.closePopup([window]) instance method

Closes the context menu in the specified window. The window parameter is a BaseWindow and is optional, defaulting to the focused window.

menu.append(menuItem) instance method

Appends a MenuItem to the menu. The menuItem parameter is a MenuItem instance.

menu.getMenuItemById(id) instance method

Returns a MenuItem or null. Takes a string id parameter and returns the menu item with the specified id, or null if not found.

menu.insert(pos, menuItem) instance method

Inserts a MenuItem at a specified position in the menu. The pos parameter is an Integer and menuItem is a MenuItem instance.

Menu class overview

The Menu class is used to create application menus and context menus. It is a main-process module. The presentation of menus varies by operating system: on Windows and Linux, menus are visually similar to Chromium, while on macOS, menus are native.

Menu class inheritance restriction

Electron's built-in Menu class cannot be subclassed in user code.

Menu.setApplicationMenu(menu) static method

Sets a menu as the application menu. The parameter menu is of type Menu or null. On macOS, this sets the application menu. On Windows and Linux, the menu is set as each window's top menu. Passing null suppresses the default menu and on Windows and Linux removes the menu bar from the window. You can use a & in top-level item names to generate accelerators (e.g., &File generates Alt-F). Use && to display a literal & character in the label.

Menu.getApplicationMenu() static method

Returns the application menu if set, or null if not set. The returned Menu instance does not support dynamic addition or removal of menu items, but instance properties can still be dynamically modified.

Menu.sendActionToFirstResponder(action) static method macOS

A macOS-only method that sends an action to the first responder of the application. The action parameter is a string. This is used for emulating default macOS menu behaviors and typically the role property of a MenuItem is used instead.

Menu.buildFromTemplate(template) static method

Takes a template array containing MenuItemConstructorOptions or MenuItem objects and returns a Menu. The template is an array of options for constructing MenuItem instances. Additional fields can be attached to template elements and will become properties of the constructed menu items.

Default menu behavior

The default menu is created automatically if the app does not set one. It contains standard items such as File, Edit, View, and Window.

MenuItem constructor options - registerAccelerator

The registerAccelerator option is Linux and Windows only and defaults to true. If false, the accelerator won't be registered with the system, but it will still be displayed.

MenuItem constructor options - sharingItem

The sharingItem option is macOS-only and accepts a SharingItem indicating the item to share when the role is shareMenu.

MenuItem constructor options - submenu

The submenu option accepts an array of MenuItemConstructorOptions or a Menu instance, and should be specified for submenu type menu items. If submenu is specified, the type: 'submenu' can be omitted. If the value is not a Menu, it will be automatically converted to one using Menu.buildFromTemplate.

MenuItem constructor options - id

The id option is an optional string that must be unique within a single menu and can be used as a reference to this item by the position attribute.

MenuItem constructor options - before

The before option is an optional string array that inserts this item before the item with the specified id. If the referenced item doesn't exist, the item will be inserted at the end of the menu. It also implies that the menu item should be placed in the same group as the item.

MenuItem constructor options - after

The after option is an optional string array that inserts this item after the item with the specified id. If the referenced item doesn't exist, the item will be inserted at the end of the menu.

MenuItem constructor options - beforeGroupContaining

The beforeGroupContaining option is an optional string array that provides a means for a single context menu to declare the placement of their containing group before the containing group of the item with the specified id.

MenuItem constructor options - afterGroupContaining

The afterGroupContaining option is an optional string array that provides a means for a single context menu to declare the placement of their containing group after the containing group of the item with the specified id.

MenuItem.id property

The id property is a string indicating the item's unique id and can be dynamically changed.

MenuItem.label property

The label property is a string indicating the item's visible label and can be dynamically changed.

MenuItem.accessibilityLabel property

The accessibilityLabel property is a macOS-only string indicating the item's accessibility label used by assistive technology, if set, and can be dynamically changed.

MenuItem.click property

The click property is a function fired when the MenuItem receives a click event. It can be called with menuItem.click(event, focusedWindow, focusedWebContents) where event is a KeyboardEvent, focusedWindow is a BaseWindow, and focusedWebContents is a WebContents.

MenuItem.submenu property

The submenu property is an optional Menu containing the menu item's submenu, if present.

MenuItem.type property

The type property is a string indicating the type of the item and can be normal, separator, submenu, checkbox, radio, header, or palette. The header and palette types are only available on macOS 14 and up.

MenuItem.role property

The role property is an optional string indicating the item's role if set. It can be undo, redo, cut, copy, paste, pasteAndMatchStyle, delete, selectAll, reload, forceReload, toggleDevTools, resetZoom, zoomIn, zoomOut, toggleSpellChecker, togglefullscreen, window, minimize, close, help, about, services, hide, hideOthers, unhide, quit, startSpeaking, stopSpeaking, zoom, front, appMenu, fileMenu, editMenu, viewMenu, shareMenu, recentDocuments, toggleTabBar, selectNextTab, selectPreviousTab, showAllTabs, mergeAllWindows, clearRecentDocuments, moveTabToNewWindow, or windowMenu.

MenuItem.accelerator property

The accelerator property is an Accelerator or null indicating the item's accelerator if set.

MenuItem.userAccelerator property

The userAccelerator property is a macOS-only read-only Accelerator or null indicating the item's user-assigned accelerator. This property is only initialized after the MenuItem has been added to a Menu via Menu.buildFromTemplate or Menu.append()/insert(). Accessing it before initialization returns null.

MenuItem.icon property

The icon property is an optional NativeImage or string indicating the item's icon if set, and can be dynamically changed.

MenuItem.sublabel property

The sublabel property is a string indicating the item's sublabel and can be dynamically changed.

MenuItem.toolTip property

The toolTip property is a macOS-only string indicating the item's hover text.

MenuItem.enabled property

The enabled property is a boolean indicating whether the item is enabled and can be dynamically changed.

MenuItem.visible property

The visible property is a boolean indicating whether the item is visible and can be dynamically changed.

MenuItem.checked property behavior

The checked property is a boolean indicating whether the item is checked and can be dynamically changed. A checkbox menu item toggles the checked property on and off when selected. A radio menu item turns on its checked property when clicked and turns off that property for all adjacent items in the same menu. A click function can be added for additional behavior.

MenuItem.registerAccelerator property

The registerAccelerator property is a boolean indicating if the accelerator should be registered with the system or just displayed, and can be dynamically changed.

MenuItem.sharingItem property

The sharingItem property is a macOS-only SharingItem indicating the item to share when the role is shareMenu, and can be dynamically changed.

MenuItem.commandId property

The commandId property is a read-only number indicating an item's sequential unique id.

MenuItem.menu property

The menu property is a Menu that the item is a part of.

MenuItem constructor options - toolTip

The toolTip option is an optional macOS-only string that provides hover text for the menu item.

MenuItem constructor options - accelerator

The accelerator option is an optional Accelerator string that defines keyboard shortcuts for the menu item.

MenuItem constructor options - icon

The icon option accepts a NativeImage or string (file path) and is optional.

MenuItem constructor options - enabled

The enabled option is an optional boolean. If false, the menu item will be greyed out and unclickable.

MenuItem constructor options - acceleratorWorksWhenHidden

The acceleratorWorksWhenHidden option is macOS-only and defaults to true. When false, it prevents the accelerator from triggering if the item is not visible. On Windows and Linux, accelerators always work when items are hidden, so this option is exposed to give users the ability to disable it for macOS parity.

MenuItem constructor options - visible

The visible option is an optional boolean. If false, the menu item will be entirely hidden.

MenuItem constructor options - checked

The checked option is an optional boolean that should only be specified for checkbox or radio type menu items.

MenuItem constructor options - label and sublabel

The label option is an optional string for the menu item's visible label. The sublabel option is an optional string available on macOS 14 and later.

MenuItem constructor options - accessibilityLabel

The accessibilityLabel option is an optional macOS-only string used by assistive technology.

MenuItem class overview

MenuItem is a class that adds items to native application menus and context menus. It runs in the Main process only. Electron's built-in classes cannot be subclassed in user code.

MenuItem constructor options - click callback

The click option is an optional function called when a menu item is clicked. The callback signature is click(menuItem, window, event) where menuItem is a MenuItem, window is a BaseWindow or undefined if no window is open, and event is a KeyboardEvent.

MenuItem constructor options - role

The role option defines the action of the menu item and accepts: undo, redo, cut, copy, paste, pasteAndMatchStyle, delete, selectAll, reload, forceReload, toggleDevTools, resetZoom, zoomIn, zoomOut, toggleSpellChecker, togglefullscreen, window, minimize, close, help, about, services, hide, hideOthers, unhide, quit, showSubstitutions, toggleSmartQuotes, toggleSmartDashes, toggleTextReplacement, startSpeaking, stopSpeaking, zoom, front, appMenu, fileMenu, editMenu, viewMenu, shareMenu, recentDocuments, toggleTabBar, selectNextTab, selectPreviousTab, showAllTabs, mergeAllWindows, clearRecentDocuments, moveTabToNewWindow, or windowMenu. When role is specified, the click property is ignored.

MenuItem constructor options - type

The type option accepts: normal, separator, submenu, checkbox, radio, header (macOS 14 and up only), or palette (macOS 14 and up only).

Give your agent this brain