> ## Documentation Index
> Fetch the complete documentation index at: https://electron-menubar.gitify.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Menubar class: properties and methods reference

> Reference for the Menubar class returned by menubar(): the app, window, tray, and positioner properties plus every method for showing, hiding, and cleanup.

The return value of `menubar()` is a `Menubar` class instance, which exposes the following properties and methods. `Menubar` is also an event emitter; see [Events](https://electron-menubar.gitify.io/api-reference/events.md).

```typescript theme={null}
import { menubar } from 'electron-menubar';

const mb = menubar({/* options */});
```

The `menubar(options?: Partial<Options>)` factory creates a `Menubar` using Electron's `app`. See [Options](https://electron-menubar.gitify.io/api-reference/options.md) for every option.

## Properties

**app** `Electron.App`

The [Electron App](https://electronjs.org/docs/api/app) instance.

**window** `BrowserWindow | undefined`

The [Electron Browser Window](https://electronjs.org/docs/api/browser-window)
instance.

**tray** `Tray`

The [Electron Tray](https://electronjs.org/docs/api/tray) instance.

**positioner** `Positioner`

The `Positioner` instance used to compute the window's on-screen coordinates.

## Methods

| Method | Description |
| - | - |
| `setOption(option, value)` | Change an option after menubar is created. |
| `getOption(option)` | Get a menubar option. |
| `showWindow()` | Show the menubar window. |
| `hideWindow()` | Hide the menubar window. |
| `toggleWindow()` | Show the window if hidden, hide it if visible. |
| `recenterOnTray()` | Re-center the window over the tray icon. |
| `setContextMenu(menu)` | Replace the tray context menu (auto-re-publishes on Linux). |
| `refreshContextMenu()` | Re-publish the current context menu after mutating its items in place. Required on Linux, a no-op elsewhere. |
| `setGlobalShortcut(accelerator)` | Register a global accelerator that toggles the window. Returns `false` on registration failure. |
| `destroy()` | Tear down the menubar instance. |
| `isDestroyed()` | Whether the menubar is currently destroyed. |

> [!TIP]
>
> On macOS, show the window with `showWindow()` rather than `window.show()` or
> `window.showInactive()`, so it rejoins all workspaces when
> `showOnAllWorkspaces` is enabled.

## Example

```javascript theme={null}
const { menubar } = require('electron-menubar');

const mb = menubar({ globalShortcut: 'CommandOrControl+Shift+M' });

mb.on('ready', () => {
  mb.setOption('hideOnBlur', false);
  mb.showWindow();
});

// Later, clean up listeners and the global shortcut.
mb.destroy();
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.