electron-menubar 1.0.1 → 10.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,329 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { BrowserWindow, BrowserWindowConstructorOptions, LoadURLOptions, Menu, Rectangle, Tray } from "electron";
3
+
4
+ //#region src/Positioner.d.ts
5
+ /**
6
+ * Named anchor points for placing the menubar window. The `tray*` values are
7
+ * relative to the tray icon's bounds; the rest are relative to the work area
8
+ * of the display containing the cursor (or the tray, when bounds are given).
9
+ */
10
+ type WindowPosition$1 = 'trayLeft' | 'trayBottomLeft' | 'trayRight' | 'trayBottomRight' | 'trayCenter' | 'trayBottomCenter' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'topCenter' | 'bottomCenter' | 'leftCenter' | 'rightCenter' | 'center';
11
+ /**
12
+ * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named
13
+ * position, optionally relative to a tray icon's bounds. Ported from
14
+ * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency.
15
+ */
16
+ declare class Positioner {
17
+ private readonly browserWindow;
18
+ constructor(browserWindow: BrowserWindow);
19
+ calculate(position?: WindowPosition$1, trayBounds?: Rectangle): {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ }
24
+ //#endregion
25
+ //#region src/types.d.ts
26
+ /**
27
+ * Options for creating a menubar application
28
+ */
29
+ interface Options {
30
+ /**
31
+ * Listen on `app.on('activate')` to open menubar when app is activated.
32
+ * @default `true`
33
+ */
34
+ activateWithApp?: boolean;
35
+ /**
36
+ * An Electron BrowserWindow instance, or an options object to be passed into
37
+ * the BrowserWindow constructor.
38
+ * @example
39
+ * ```typescript
40
+ * const options = { height: 640, width: 480 };
41
+ *
42
+ * const mb = new Menubar({
43
+ * browserWindow: options
44
+ * });
45
+ * ```
46
+ */
47
+ browserWindow: BrowserWindowConstructorOptions;
48
+ /**
49
+ * A native context menu to attach to the tray icon.
50
+ *
51
+ * On Linux this is bound via {@link Tray.setContextMenu} (required by
52
+ * libappindicator / StatusNotifierItem) and re-published whenever the
53
+ * menubar window shows or hides to defeat the indicator's menu cache.
54
+ *
55
+ * On macOS and Windows it is shown via {@link Tray.popUpContextMenu} on
56
+ * right-click, so left-click continues to toggle the menubar window.
57
+ * Setting this option therefore implies `trigger: 'click'` on those
58
+ * platforms — pass `trigger: 'none'` to disable left-click toggling
59
+ * entirely.
60
+ */
61
+ contextMenu?: Menu;
62
+ /**
63
+ * The app source directory.
64
+ */
65
+ dir: string;
66
+ /**
67
+ * Register this accelerator as a global shortcut that toggles the menubar
68
+ * window. Calls
69
+ * [`globalShortcut.register`](https://electronjs.org/docs/api/global-shortcut#globalshortcutregisteraccelerator-callback)
70
+ * after `ready` and unregisters it on {@link Menubar.destroy}. The same
71
+ * accelerator can be set or cleared later via
72
+ * {@link Menubar.setGlobalShortcut}.
73
+ */
74
+ globalShortcut?: Electron.Accelerator;
75
+ /**
76
+ * Hide the window on `close` instead of letting it be destroyed, so the
77
+ * next tray click re-uses the same {@link BrowserWindow} instance. On
78
+ * Linux/Wayland the hide is deferred via `setImmediate` to work around a
79
+ * compositor bug that leaves frameless surfaces in a half-closed state
80
+ * when hidden synchronously from the `close` handler.
81
+ *
82
+ * Respects `app.isQuitting === true` (set this in your `before-quit`
83
+ * handler) so the close goes through during real quits. Has no effect
84
+ * when the close event was triggered by {@link Menubar.destroy}.
85
+ * @default `false`
86
+ */
87
+ hideOnClose?: boolean;
88
+ /**
89
+ * Hide the menubar window when the user presses `Escape` while it has
90
+ * focus. Wires up a `before-input-event` listener on the BrowserWindow.
91
+ * @default `false`
92
+ */
93
+ escapeToHide?: boolean;
94
+ /**
95
+ * The png icon to use for the menubar. A good size to start with is 20x20.
96
+ * To support retina, supply a 2x sized image (e.g. 40x40) with @2x added to
97
+ * the end of the name, so icon.png and icon@2x.png and Electron will
98
+ * automatically use your @2x version on retina screens.
99
+ */
100
+ icon?: string | Electron.NativeImage;
101
+ /**
102
+ * The URL to load the menubar's browserWindow with. The url can be a remote
103
+ * address (e.g. `http://`) or a path to a local HTML file using the
104
+ * `file://` protocol. If false, then menubar won't call `loadURL` on
105
+ * start.
106
+ * @default `file:// + options.dir + index.html`
107
+ * @see https://electronjs.org/docs/api/browser-window#winloadurlurl-options
108
+ */
109
+ index: string | false;
110
+ /**
111
+ * The options passed when loading the index URL in the menubar's
112
+ * browserWindow. Everything browserWindow.loadURL supports is supported;
113
+ * this object is simply passed onto browserWindow.loadURL
114
+ * @default `{}`
115
+ * @see https://electronjs.org/docs/api/browser-window#winloadurlurl-options
116
+ */
117
+ loadUrlOptions?: LoadURLOptions;
118
+ /**
119
+ * Ignore the tray's `double-click` event on macOS. Prevents a flicker
120
+ * caused by the close-on-blur handler racing the second click of an
121
+ * accidental double-click. No-op on Linux/Windows. Calls
122
+ * [`tray.setIgnoreDoubleClickEvents`](https://electronjs.org/docs/api/tray#traysetignoredoubleclickeventsignore-macos).
123
+ * @default `true`
124
+ */
125
+ ignoreDoubleClickEvents?: boolean;
126
+ /**
127
+ * Create BrowserWindow instance before it is used -- increasing resource
128
+ * usage, but making the click on the menubar load faster.
129
+ */
130
+ preloadWindow?: boolean;
131
+ /**
132
+ * Configure the visibility of the application dock icon, macOS only. Calls
133
+ * [`app.dock.hide`](https://electronjs.org/docs/api/app#appdockhide-macos).
134
+ */
135
+ showDockIcon?: boolean;
136
+ /**
137
+ * Makes the window available on all OS X workspaces. Calls
138
+ * [`setVisibleOnAllWorkspaces`](https://electronjs.org/docs/api/browser-window#winsetvisibleonallworkspacesvisible-options).
139
+ */
140
+ showOnAllWorkspaces?: boolean;
141
+ /**
142
+ * Show the window on 'right-click' event instead of regular 'click'.
143
+ * @deprecated Use {@link Options.trigger} instead. Will be removed in the
144
+ * next major release.
145
+ */
146
+ showOnRightClick?: boolean;
147
+ /**
148
+ * Tray event that toggles the menubar window. Set to `'none'` to disable
149
+ * automatic toggling — the window can still be shown by calling
150
+ * {@link Menubar.showWindow} directly. Useful when a single tray icon serves
151
+ * multiple windows.
152
+ * @default `'click'` (or `'right-click'` if the deprecated
153
+ * {@link Options.showOnRightClick} is `true`)
154
+ */
155
+ trigger?: 'click' | 'right-click' | 'none';
156
+ /**
157
+ * Menubar tray icon tooltip text. Calls [`tray.setTooltip`](https://electronjs.org/docs/api/tray#traysettooltiptooltip).
158
+ */
159
+ tooltip: string;
160
+ /**
161
+ * An electron Tray instance. If provided, `options.icon` will be ignored.
162
+ */
163
+ tray?: Tray;
164
+ /**
165
+ * Sets the window position (x and y will still override this). See
166
+ * {@link WindowPosition} for the list of valid values.
167
+ */
168
+ windowPosition?: WindowPosition$1;
169
+ }
170
+ //#endregion
171
+ //#region src/Menubar.d.ts
172
+ /**
173
+ * The main Menubar class.
174
+ */
175
+ declare class Menubar extends EventEmitter {
176
+ private _app;
177
+ private _browserWindow?;
178
+ private _contextMenu?;
179
+ private _blurTimeout;
180
+ private _isDestroyed;
181
+ private _isQuitting;
182
+ private _isVisible;
183
+ private _cachedBounds?;
184
+ private _options;
185
+ private _positioner;
186
+ private _shortcut?;
187
+ private _rightClickContextMenuBound;
188
+ private _tray?;
189
+ constructor(app: Electron.App, options?: Partial<Options>);
190
+ /**
191
+ * The Electron [App](https://electronjs.org/docs/api/app)
192
+ * instance.
193
+ */
194
+ get app(): Electron.App;
195
+ /**
196
+ * The {@link Positioner} instance used to compute where the menubar window
197
+ * should appear on screen. Available after the `after-create-window` event.
198
+ */
199
+ get positioner(): Positioner;
200
+ /**
201
+ * The Electron [Tray](https://electronjs.org/docs/api/tray) instance.
202
+ */
203
+ get tray(): Tray;
204
+ /**
205
+ * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)
206
+ * instance, if it's present.
207
+ */
208
+ get window(): BrowserWindow | undefined;
209
+ /**
210
+ * Tear down the menubar instance: destroy the window, remove the tray, and
211
+ * detach all listeners. Subsequent clicks on the tray will be no-ops until a
212
+ * new {@link Menubar} instance is created.
213
+ */
214
+ destroy(): void;
215
+ /**
216
+ * Whether {@link destroy} has been called on this menubar instance.
217
+ */
218
+ isDestroyed(): boolean;
219
+ /**
220
+ * Retrieve a menubar option.
221
+ *
222
+ * @param key - The option key to retrieve, see {@link Options}.
223
+ */
224
+ getOption<K extends keyof Options>(key: K): Options[K];
225
+ /**
226
+ * Hide the menubar window.
227
+ */
228
+ hideWindow(): void;
229
+ /**
230
+ * Register a global keyboard accelerator that toggles the menubar window.
231
+ * Replaces any previously registered shortcut owned by this Menubar.
232
+ * Pass `undefined` to clear the current shortcut without registering a new
233
+ * one. Returns whether the registration succeeded.
234
+ *
235
+ * @param accelerator - An Electron
236
+ * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or
237
+ * `undefined` to clear.
238
+ */
239
+ setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean;
240
+ /**
241
+ * Toggle the menubar window: hide it if visible, show it otherwise.
242
+ * Resolves once the window finishes showing or hiding.
243
+ */
244
+ toggleWindow(): Promise<void>;
245
+ /**
246
+ * Re-center the menubar window over the tray icon. Convenience wrapper for
247
+ * `positioner.move('trayCenter', tray.getBounds())` that's safe to call
248
+ * after the `after-create-window` event. No-op if the window doesn't
249
+ * exist yet.
250
+ */
251
+ recenterOnTray(): void;
252
+ /**
253
+ * Replace the tray context menu after construction. On Linux this also
254
+ * re-publishes the menu to the SNI host, which is required after mutating
255
+ * items in-place since libappindicator caches the previous serialization.
256
+ * On macOS/Windows the right-click popup handler reads the current menu
257
+ * reference, so swapping or clearing here takes effect immediately.
258
+ *
259
+ * @param menu - The new menu, or `null` to clear it.
260
+ */
261
+ setContextMenu(menu: Menu | null): void;
262
+ /**
263
+ * Change an option after menubar is created.
264
+ *
265
+ * @param key - The option key to modify, see {@link Options}.
266
+ * @param value - The value to set.
267
+ */
268
+ setOption<K extends keyof Options>(key: K, value: Options[K]): void;
269
+ /**
270
+ * Show the menubar window.
271
+ *
272
+ * @param trayPos - The bounds to show the window in.
273
+ */
274
+ showWindow(trayPos?: Electron.Rectangle): Promise<void>;
275
+ /**
276
+ * Compute and apply the tray-anchored position of the browser window. Safe
277
+ * to call any time after `createWindow` has run — invoked from
278
+ * {@link showWindow} on every show, and from the window's `resize` event so
279
+ * `setSize` calls reposition the window correctly.
280
+ */
281
+ private positionWindow;
282
+ private appReady;
283
+ /**
284
+ * Callback on tray icon click or double-click.
285
+ *
286
+ * @param e
287
+ * @param bounds
288
+ */
289
+ private clicked;
290
+ private onAppActivate;
291
+ private onBeforeQuit;
292
+ private bindContextMenu;
293
+ private bindRightClickContextMenu;
294
+ private refreshLinuxContextMenu;
295
+ private onAppReady;
296
+ private createWindow;
297
+ private windowClear;
298
+ }
299
+ //#endregion
300
+ //#region src/util/getWindowPosition.d.ts
301
+ type TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';
302
+ /**
303
+ * Determine taskbard location: "top", "bottom", "left" or "right".
304
+ *
305
+ * Only tested on Windows for now, and only used in Windows.
306
+ *
307
+ * @param tray - The Electron Tray instance.
308
+ */
309
+ declare function taskbarLocation(tray: Tray): TaskbarLocation;
310
+ type WindowPosition = 'trayCenter' | 'topRight' | 'trayBottomCenter' | 'leftCenter' | 'bottomRight';
311
+ /**
312
+ * Depending on where the taskbar is, determine where the window should be
313
+ * positioned.
314
+ *
315
+ * @param tray - The Electron Tray instance.
316
+ */
317
+ declare function getWindowPosition(tray: Tray): WindowPosition;
318
+ //#endregion
319
+ //#region src/index.d.ts
320
+ /**
321
+ * Factory function to create a menubar application
322
+ *
323
+ * @param options - Options for creating a menubar application, see
324
+ * {@link Options}
325
+ */
326
+ declare function menubar(options?: Partial<Options>): Menubar;
327
+ //#endregion
328
+ export { Menubar, getWindowPosition, menubar, taskbarLocation };
329
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,329 @@
1
+ import { BrowserWindow, BrowserWindowConstructorOptions, LoadURLOptions, Menu, Rectangle, Tray } from "electron";
2
+ import { EventEmitter } from "node:events";
3
+
4
+ //#region src/Positioner.d.ts
5
+ /**
6
+ * Named anchor points for placing the menubar window. The `tray*` values are
7
+ * relative to the tray icon's bounds; the rest are relative to the work area
8
+ * of the display containing the cursor (or the tray, when bounds are given).
9
+ */
10
+ type WindowPosition$1 = 'trayLeft' | 'trayBottomLeft' | 'trayRight' | 'trayBottomRight' | 'trayCenter' | 'trayBottomCenter' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'topCenter' | 'bottomCenter' | 'leftCenter' | 'rightCenter' | 'center';
11
+ /**
12
+ * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named
13
+ * position, optionally relative to a tray icon's bounds. Ported from
14
+ * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency.
15
+ */
16
+ declare class Positioner {
17
+ private readonly browserWindow;
18
+ constructor(browserWindow: BrowserWindow);
19
+ calculate(position?: WindowPosition$1, trayBounds?: Rectangle): {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ }
24
+ //#endregion
25
+ //#region src/types.d.ts
26
+ /**
27
+ * Options for creating a menubar application
28
+ */
29
+ interface Options {
30
+ /**
31
+ * Listen on `app.on('activate')` to open menubar when app is activated.
32
+ * @default `true`
33
+ */
34
+ activateWithApp?: boolean;
35
+ /**
36
+ * An Electron BrowserWindow instance, or an options object to be passed into
37
+ * the BrowserWindow constructor.
38
+ * @example
39
+ * ```typescript
40
+ * const options = { height: 640, width: 480 };
41
+ *
42
+ * const mb = new Menubar({
43
+ * browserWindow: options
44
+ * });
45
+ * ```
46
+ */
47
+ browserWindow: BrowserWindowConstructorOptions;
48
+ /**
49
+ * A native context menu to attach to the tray icon.
50
+ *
51
+ * On Linux this is bound via {@link Tray.setContextMenu} (required by
52
+ * libappindicator / StatusNotifierItem) and re-published whenever the
53
+ * menubar window shows or hides to defeat the indicator's menu cache.
54
+ *
55
+ * On macOS and Windows it is shown via {@link Tray.popUpContextMenu} on
56
+ * right-click, so left-click continues to toggle the menubar window.
57
+ * Setting this option therefore implies `trigger: 'click'` on those
58
+ * platforms — pass `trigger: 'none'` to disable left-click toggling
59
+ * entirely.
60
+ */
61
+ contextMenu?: Menu;
62
+ /**
63
+ * The app source directory.
64
+ */
65
+ dir: string;
66
+ /**
67
+ * Register this accelerator as a global shortcut that toggles the menubar
68
+ * window. Calls
69
+ * [`globalShortcut.register`](https://electronjs.org/docs/api/global-shortcut#globalshortcutregisteraccelerator-callback)
70
+ * after `ready` and unregisters it on {@link Menubar.destroy}. The same
71
+ * accelerator can be set or cleared later via
72
+ * {@link Menubar.setGlobalShortcut}.
73
+ */
74
+ globalShortcut?: Electron.Accelerator;
75
+ /**
76
+ * Hide the window on `close` instead of letting it be destroyed, so the
77
+ * next tray click re-uses the same {@link BrowserWindow} instance. On
78
+ * Linux/Wayland the hide is deferred via `setImmediate` to work around a
79
+ * compositor bug that leaves frameless surfaces in a half-closed state
80
+ * when hidden synchronously from the `close` handler.
81
+ *
82
+ * Respects `app.isQuitting === true` (set this in your `before-quit`
83
+ * handler) so the close goes through during real quits. Has no effect
84
+ * when the close event was triggered by {@link Menubar.destroy}.
85
+ * @default `false`
86
+ */
87
+ hideOnClose?: boolean;
88
+ /**
89
+ * Hide the menubar window when the user presses `Escape` while it has
90
+ * focus. Wires up a `before-input-event` listener on the BrowserWindow.
91
+ * @default `false`
92
+ */
93
+ escapeToHide?: boolean;
94
+ /**
95
+ * The png icon to use for the menubar. A good size to start with is 20x20.
96
+ * To support retina, supply a 2x sized image (e.g. 40x40) with @2x added to
97
+ * the end of the name, so icon.png and icon@2x.png and Electron will
98
+ * automatically use your @2x version on retina screens.
99
+ */
100
+ icon?: string | Electron.NativeImage;
101
+ /**
102
+ * The URL to load the menubar's browserWindow with. The url can be a remote
103
+ * address (e.g. `http://`) or a path to a local HTML file using the
104
+ * `file://` protocol. If false, then menubar won't call `loadURL` on
105
+ * start.
106
+ * @default `file:// + options.dir + index.html`
107
+ * @see https://electronjs.org/docs/api/browser-window#winloadurlurl-options
108
+ */
109
+ index: string | false;
110
+ /**
111
+ * The options passed when loading the index URL in the menubar's
112
+ * browserWindow. Everything browserWindow.loadURL supports is supported;
113
+ * this object is simply passed onto browserWindow.loadURL
114
+ * @default `{}`
115
+ * @see https://electronjs.org/docs/api/browser-window#winloadurlurl-options
116
+ */
117
+ loadUrlOptions?: LoadURLOptions;
118
+ /**
119
+ * Ignore the tray's `double-click` event on macOS. Prevents a flicker
120
+ * caused by the close-on-blur handler racing the second click of an
121
+ * accidental double-click. No-op on Linux/Windows. Calls
122
+ * [`tray.setIgnoreDoubleClickEvents`](https://electronjs.org/docs/api/tray#traysetignoredoubleclickeventsignore-macos).
123
+ * @default `true`
124
+ */
125
+ ignoreDoubleClickEvents?: boolean;
126
+ /**
127
+ * Create BrowserWindow instance before it is used -- increasing resource
128
+ * usage, but making the click on the menubar load faster.
129
+ */
130
+ preloadWindow?: boolean;
131
+ /**
132
+ * Configure the visibility of the application dock icon, macOS only. Calls
133
+ * [`app.dock.hide`](https://electronjs.org/docs/api/app#appdockhide-macos).
134
+ */
135
+ showDockIcon?: boolean;
136
+ /**
137
+ * Makes the window available on all OS X workspaces. Calls
138
+ * [`setVisibleOnAllWorkspaces`](https://electronjs.org/docs/api/browser-window#winsetvisibleonallworkspacesvisible-options).
139
+ */
140
+ showOnAllWorkspaces?: boolean;
141
+ /**
142
+ * Show the window on 'right-click' event instead of regular 'click'.
143
+ * @deprecated Use {@link Options.trigger} instead. Will be removed in the
144
+ * next major release.
145
+ */
146
+ showOnRightClick?: boolean;
147
+ /**
148
+ * Tray event that toggles the menubar window. Set to `'none'` to disable
149
+ * automatic toggling — the window can still be shown by calling
150
+ * {@link Menubar.showWindow} directly. Useful when a single tray icon serves
151
+ * multiple windows.
152
+ * @default `'click'` (or `'right-click'` if the deprecated
153
+ * {@link Options.showOnRightClick} is `true`)
154
+ */
155
+ trigger?: 'click' | 'right-click' | 'none';
156
+ /**
157
+ * Menubar tray icon tooltip text. Calls [`tray.setTooltip`](https://electronjs.org/docs/api/tray#traysettooltiptooltip).
158
+ */
159
+ tooltip: string;
160
+ /**
161
+ * An electron Tray instance. If provided, `options.icon` will be ignored.
162
+ */
163
+ tray?: Tray;
164
+ /**
165
+ * Sets the window position (x and y will still override this). See
166
+ * {@link WindowPosition} for the list of valid values.
167
+ */
168
+ windowPosition?: WindowPosition$1;
169
+ }
170
+ //#endregion
171
+ //#region src/Menubar.d.ts
172
+ /**
173
+ * The main Menubar class.
174
+ */
175
+ declare class Menubar extends EventEmitter {
176
+ private _app;
177
+ private _browserWindow?;
178
+ private _contextMenu?;
179
+ private _blurTimeout;
180
+ private _isDestroyed;
181
+ private _isQuitting;
182
+ private _isVisible;
183
+ private _cachedBounds?;
184
+ private _options;
185
+ private _positioner;
186
+ private _shortcut?;
187
+ private _rightClickContextMenuBound;
188
+ private _tray?;
189
+ constructor(app: Electron.App, options?: Partial<Options>);
190
+ /**
191
+ * The Electron [App](https://electronjs.org/docs/api/app)
192
+ * instance.
193
+ */
194
+ get app(): Electron.App;
195
+ /**
196
+ * The {@link Positioner} instance used to compute where the menubar window
197
+ * should appear on screen. Available after the `after-create-window` event.
198
+ */
199
+ get positioner(): Positioner;
200
+ /**
201
+ * The Electron [Tray](https://electronjs.org/docs/api/tray) instance.
202
+ */
203
+ get tray(): Tray;
204
+ /**
205
+ * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)
206
+ * instance, if it's present.
207
+ */
208
+ get window(): BrowserWindow | undefined;
209
+ /**
210
+ * Tear down the menubar instance: destroy the window, remove the tray, and
211
+ * detach all listeners. Subsequent clicks on the tray will be no-ops until a
212
+ * new {@link Menubar} instance is created.
213
+ */
214
+ destroy(): void;
215
+ /**
216
+ * Whether {@link destroy} has been called on this menubar instance.
217
+ */
218
+ isDestroyed(): boolean;
219
+ /**
220
+ * Retrieve a menubar option.
221
+ *
222
+ * @param key - The option key to retrieve, see {@link Options}.
223
+ */
224
+ getOption<K extends keyof Options>(key: K): Options[K];
225
+ /**
226
+ * Hide the menubar window.
227
+ */
228
+ hideWindow(): void;
229
+ /**
230
+ * Register a global keyboard accelerator that toggles the menubar window.
231
+ * Replaces any previously registered shortcut owned by this Menubar.
232
+ * Pass `undefined` to clear the current shortcut without registering a new
233
+ * one. Returns whether the registration succeeded.
234
+ *
235
+ * @param accelerator - An Electron
236
+ * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or
237
+ * `undefined` to clear.
238
+ */
239
+ setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean;
240
+ /**
241
+ * Toggle the menubar window: hide it if visible, show it otherwise.
242
+ * Resolves once the window finishes showing or hiding.
243
+ */
244
+ toggleWindow(): Promise<void>;
245
+ /**
246
+ * Re-center the menubar window over the tray icon. Convenience wrapper for
247
+ * `positioner.move('trayCenter', tray.getBounds())` that's safe to call
248
+ * after the `after-create-window` event. No-op if the window doesn't
249
+ * exist yet.
250
+ */
251
+ recenterOnTray(): void;
252
+ /**
253
+ * Replace the tray context menu after construction. On Linux this also
254
+ * re-publishes the menu to the SNI host, which is required after mutating
255
+ * items in-place since libappindicator caches the previous serialization.
256
+ * On macOS/Windows the right-click popup handler reads the current menu
257
+ * reference, so swapping or clearing here takes effect immediately.
258
+ *
259
+ * @param menu - The new menu, or `null` to clear it.
260
+ */
261
+ setContextMenu(menu: Menu | null): void;
262
+ /**
263
+ * Change an option after menubar is created.
264
+ *
265
+ * @param key - The option key to modify, see {@link Options}.
266
+ * @param value - The value to set.
267
+ */
268
+ setOption<K extends keyof Options>(key: K, value: Options[K]): void;
269
+ /**
270
+ * Show the menubar window.
271
+ *
272
+ * @param trayPos - The bounds to show the window in.
273
+ */
274
+ showWindow(trayPos?: Electron.Rectangle): Promise<void>;
275
+ /**
276
+ * Compute and apply the tray-anchored position of the browser window. Safe
277
+ * to call any time after `createWindow` has run — invoked from
278
+ * {@link showWindow} on every show, and from the window's `resize` event so
279
+ * `setSize` calls reposition the window correctly.
280
+ */
281
+ private positionWindow;
282
+ private appReady;
283
+ /**
284
+ * Callback on tray icon click or double-click.
285
+ *
286
+ * @param e
287
+ * @param bounds
288
+ */
289
+ private clicked;
290
+ private onAppActivate;
291
+ private onBeforeQuit;
292
+ private bindContextMenu;
293
+ private bindRightClickContextMenu;
294
+ private refreshLinuxContextMenu;
295
+ private onAppReady;
296
+ private createWindow;
297
+ private windowClear;
298
+ }
299
+ //#endregion
300
+ //#region src/util/getWindowPosition.d.ts
301
+ type TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';
302
+ /**
303
+ * Determine taskbard location: "top", "bottom", "left" or "right".
304
+ *
305
+ * Only tested on Windows for now, and only used in Windows.
306
+ *
307
+ * @param tray - The Electron Tray instance.
308
+ */
309
+ declare function taskbarLocation(tray: Tray): TaskbarLocation;
310
+ type WindowPosition = 'trayCenter' | 'topRight' | 'trayBottomCenter' | 'leftCenter' | 'bottomRight';
311
+ /**
312
+ * Depending on where the taskbar is, determine where the window should be
313
+ * positioned.
314
+ *
315
+ * @param tray - The Electron Tray instance.
316
+ */
317
+ declare function getWindowPosition(tray: Tray): WindowPosition;
318
+ //#endregion
319
+ //#region src/index.d.ts
320
+ /**
321
+ * Factory function to create a menubar application
322
+ *
323
+ * @param options - Options for creating a menubar application, see
324
+ * {@link Options}
325
+ */
326
+ declare function menubar(options?: Partial<Options>): Menubar;
327
+ //#endregion
328
+ export { Menubar, getWindowPosition, menubar, taskbarLocation };
329
+ //# sourceMappingURL=index.d.mts.map