electron-menubar 1.0.2 → 10.1.1
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.
- package/LICENSE +22 -17
- package/README.md +171 -51
- package/assets/IconTemplate.png +0 -0
- package/assets/IconTemplate@2x.png +0 -0
- package/lib/index.cjs +564 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +330 -0
- package/lib/index.d.mts +330 -0
- package/lib/index.mjs +535 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +66 -26
- package/.travis.yml +0 -4
- package/index.js +0 -7
- package/menubar.js +0 -179
- package/positioner.js +0 -211
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
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 _warnedNoPositioning;
|
|
189
|
+
private _tray?;
|
|
190
|
+
constructor(app: Electron.App, options?: Partial<Options>);
|
|
191
|
+
/**
|
|
192
|
+
* The Electron [App](https://electronjs.org/docs/api/app)
|
|
193
|
+
* instance.
|
|
194
|
+
*/
|
|
195
|
+
get app(): Electron.App;
|
|
196
|
+
/**
|
|
197
|
+
* The {@link Positioner} instance used to compute where the menubar window
|
|
198
|
+
* should appear on screen. Available after the `after-create-window` event.
|
|
199
|
+
*/
|
|
200
|
+
get positioner(): Positioner;
|
|
201
|
+
/**
|
|
202
|
+
* The Electron [Tray](https://electronjs.org/docs/api/tray) instance.
|
|
203
|
+
*/
|
|
204
|
+
get tray(): Tray;
|
|
205
|
+
/**
|
|
206
|
+
* The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)
|
|
207
|
+
* instance, if it's present.
|
|
208
|
+
*/
|
|
209
|
+
get window(): BrowserWindow | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Tear down the menubar instance: destroy the window, remove the tray, and
|
|
212
|
+
* detach all listeners. Subsequent clicks on the tray will be no-ops until a
|
|
213
|
+
* new {@link Menubar} instance is created.
|
|
214
|
+
*/
|
|
215
|
+
destroy(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Whether {@link destroy} has been called on this menubar instance.
|
|
218
|
+
*/
|
|
219
|
+
isDestroyed(): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Retrieve a menubar option.
|
|
222
|
+
*
|
|
223
|
+
* @param key - The option key to retrieve, see {@link Options}.
|
|
224
|
+
*/
|
|
225
|
+
getOption<K extends keyof Options>(key: K): Options[K];
|
|
226
|
+
/**
|
|
227
|
+
* Hide the menubar window.
|
|
228
|
+
*/
|
|
229
|
+
hideWindow(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Register a global keyboard accelerator that toggles the menubar window.
|
|
232
|
+
* Replaces any previously registered shortcut owned by this Menubar.
|
|
233
|
+
* Pass `undefined` to clear the current shortcut without registering a new
|
|
234
|
+
* one. Returns whether the registration succeeded.
|
|
235
|
+
*
|
|
236
|
+
* @param accelerator - An Electron
|
|
237
|
+
* [Accelerator](https://electronjs.org/docs/api/accelerator) string, or
|
|
238
|
+
* `undefined` to clear.
|
|
239
|
+
*/
|
|
240
|
+
setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Toggle the menubar window: hide it if visible, show it otherwise.
|
|
243
|
+
* Resolves once the window finishes showing or hiding.
|
|
244
|
+
*/
|
|
245
|
+
toggleWindow(): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Re-center the menubar window over the tray icon. Convenience wrapper for
|
|
248
|
+
* `positioner.move('trayCenter', tray.getBounds())` that's safe to call
|
|
249
|
+
* after the `after-create-window` event. No-op if the window doesn't
|
|
250
|
+
* exist yet.
|
|
251
|
+
*/
|
|
252
|
+
recenterOnTray(): void;
|
|
253
|
+
/**
|
|
254
|
+
* Replace the tray context menu after construction. On Linux this also
|
|
255
|
+
* re-publishes the menu to the SNI host, which is required after mutating
|
|
256
|
+
* items in-place since libappindicator caches the previous serialization.
|
|
257
|
+
* On macOS/Windows the right-click popup handler reads the current menu
|
|
258
|
+
* reference, so swapping or clearing here takes effect immediately.
|
|
259
|
+
*
|
|
260
|
+
* @param menu - The new menu, or `null` to clear it.
|
|
261
|
+
*/
|
|
262
|
+
setContextMenu(menu: Menu | null): void;
|
|
263
|
+
/**
|
|
264
|
+
* Change an option after menubar is created.
|
|
265
|
+
*
|
|
266
|
+
* @param key - The option key to modify, see {@link Options}.
|
|
267
|
+
* @param value - The value to set.
|
|
268
|
+
*/
|
|
269
|
+
setOption<K extends keyof Options>(key: K, value: Options[K]): void;
|
|
270
|
+
/**
|
|
271
|
+
* Show the menubar window.
|
|
272
|
+
*
|
|
273
|
+
* @param trayPos - The bounds to show the window in.
|
|
274
|
+
*/
|
|
275
|
+
showWindow(trayPos?: Electron.Rectangle): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Compute and apply the tray-anchored position of the browser window. Safe
|
|
278
|
+
* to call any time after `createWindow` has run — invoked from
|
|
279
|
+
* {@link showWindow} on every show, and from the window's `resize` event so
|
|
280
|
+
* `setSize` calls reposition the window correctly.
|
|
281
|
+
*/
|
|
282
|
+
private positionWindow;
|
|
283
|
+
private appReady;
|
|
284
|
+
/**
|
|
285
|
+
* Callback on tray icon click or double-click.
|
|
286
|
+
*
|
|
287
|
+
* @param e
|
|
288
|
+
* @param bounds
|
|
289
|
+
*/
|
|
290
|
+
private clicked;
|
|
291
|
+
private onAppActivate;
|
|
292
|
+
private onBeforeQuit;
|
|
293
|
+
private bindContextMenu;
|
|
294
|
+
private bindRightClickContextMenu;
|
|
295
|
+
private refreshLinuxContextMenu;
|
|
296
|
+
private onAppReady;
|
|
297
|
+
private createWindow;
|
|
298
|
+
private windowClear;
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/util/getWindowPosition.d.ts
|
|
302
|
+
type TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';
|
|
303
|
+
/**
|
|
304
|
+
* Determine taskbard location: "top", "bottom", "left" or "right".
|
|
305
|
+
*
|
|
306
|
+
* Only tested on Windows for now, and only used in Windows.
|
|
307
|
+
*
|
|
308
|
+
* @param tray - The Electron Tray instance.
|
|
309
|
+
*/
|
|
310
|
+
declare function taskbarLocation(tray: Tray): TaskbarLocation;
|
|
311
|
+
type WindowPosition = 'trayCenter' | 'topRight' | 'trayBottomCenter' | 'leftCenter' | 'bottomRight';
|
|
312
|
+
/**
|
|
313
|
+
* Depending on where the taskbar is, determine where the window should be
|
|
314
|
+
* positioned.
|
|
315
|
+
*
|
|
316
|
+
* @param tray - The Electron Tray instance.
|
|
317
|
+
*/
|
|
318
|
+
declare function getWindowPosition(tray: Tray): WindowPosition;
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/index.d.ts
|
|
321
|
+
/**
|
|
322
|
+
* Factory function to create a menubar application
|
|
323
|
+
*
|
|
324
|
+
* @param options - Options for creating a menubar application, see
|
|
325
|
+
* {@link Options}
|
|
326
|
+
*/
|
|
327
|
+
declare function menubar(options?: Partial<Options>): Menubar;
|
|
328
|
+
//#endregion
|
|
329
|
+
export { Menubar, getWindowPosition, menubar, taskbarLocation };
|
|
330
|
+
//# sourceMappingURL=index.d.cts.map
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
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 _warnedNoPositioning;
|
|
189
|
+
private _tray?;
|
|
190
|
+
constructor(app: Electron.App, options?: Partial<Options>);
|
|
191
|
+
/**
|
|
192
|
+
* The Electron [App](https://electronjs.org/docs/api/app)
|
|
193
|
+
* instance.
|
|
194
|
+
*/
|
|
195
|
+
get app(): Electron.App;
|
|
196
|
+
/**
|
|
197
|
+
* The {@link Positioner} instance used to compute where the menubar window
|
|
198
|
+
* should appear on screen. Available after the `after-create-window` event.
|
|
199
|
+
*/
|
|
200
|
+
get positioner(): Positioner;
|
|
201
|
+
/**
|
|
202
|
+
* The Electron [Tray](https://electronjs.org/docs/api/tray) instance.
|
|
203
|
+
*/
|
|
204
|
+
get tray(): Tray;
|
|
205
|
+
/**
|
|
206
|
+
* The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)
|
|
207
|
+
* instance, if it's present.
|
|
208
|
+
*/
|
|
209
|
+
get window(): BrowserWindow | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Tear down the menubar instance: destroy the window, remove the tray, and
|
|
212
|
+
* detach all listeners. Subsequent clicks on the tray will be no-ops until a
|
|
213
|
+
* new {@link Menubar} instance is created.
|
|
214
|
+
*/
|
|
215
|
+
destroy(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Whether {@link destroy} has been called on this menubar instance.
|
|
218
|
+
*/
|
|
219
|
+
isDestroyed(): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Retrieve a menubar option.
|
|
222
|
+
*
|
|
223
|
+
* @param key - The option key to retrieve, see {@link Options}.
|
|
224
|
+
*/
|
|
225
|
+
getOption<K extends keyof Options>(key: K): Options[K];
|
|
226
|
+
/**
|
|
227
|
+
* Hide the menubar window.
|
|
228
|
+
*/
|
|
229
|
+
hideWindow(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Register a global keyboard accelerator that toggles the menubar window.
|
|
232
|
+
* Replaces any previously registered shortcut owned by this Menubar.
|
|
233
|
+
* Pass `undefined` to clear the current shortcut without registering a new
|
|
234
|
+
* one. Returns whether the registration succeeded.
|
|
235
|
+
*
|
|
236
|
+
* @param accelerator - An Electron
|
|
237
|
+
* [Accelerator](https://electronjs.org/docs/api/accelerator) string, or
|
|
238
|
+
* `undefined` to clear.
|
|
239
|
+
*/
|
|
240
|
+
setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Toggle the menubar window: hide it if visible, show it otherwise.
|
|
243
|
+
* Resolves once the window finishes showing or hiding.
|
|
244
|
+
*/
|
|
245
|
+
toggleWindow(): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Re-center the menubar window over the tray icon. Convenience wrapper for
|
|
248
|
+
* `positioner.move('trayCenter', tray.getBounds())` that's safe to call
|
|
249
|
+
* after the `after-create-window` event. No-op if the window doesn't
|
|
250
|
+
* exist yet.
|
|
251
|
+
*/
|
|
252
|
+
recenterOnTray(): void;
|
|
253
|
+
/**
|
|
254
|
+
* Replace the tray context menu after construction. On Linux this also
|
|
255
|
+
* re-publishes the menu to the SNI host, which is required after mutating
|
|
256
|
+
* items in-place since libappindicator caches the previous serialization.
|
|
257
|
+
* On macOS/Windows the right-click popup handler reads the current menu
|
|
258
|
+
* reference, so swapping or clearing here takes effect immediately.
|
|
259
|
+
*
|
|
260
|
+
* @param menu - The new menu, or `null` to clear it.
|
|
261
|
+
*/
|
|
262
|
+
setContextMenu(menu: Menu | null): void;
|
|
263
|
+
/**
|
|
264
|
+
* Change an option after menubar is created.
|
|
265
|
+
*
|
|
266
|
+
* @param key - The option key to modify, see {@link Options}.
|
|
267
|
+
* @param value - The value to set.
|
|
268
|
+
*/
|
|
269
|
+
setOption<K extends keyof Options>(key: K, value: Options[K]): void;
|
|
270
|
+
/**
|
|
271
|
+
* Show the menubar window.
|
|
272
|
+
*
|
|
273
|
+
* @param trayPos - The bounds to show the window in.
|
|
274
|
+
*/
|
|
275
|
+
showWindow(trayPos?: Electron.Rectangle): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Compute and apply the tray-anchored position of the browser window. Safe
|
|
278
|
+
* to call any time after `createWindow` has run — invoked from
|
|
279
|
+
* {@link showWindow} on every show, and from the window's `resize` event so
|
|
280
|
+
* `setSize` calls reposition the window correctly.
|
|
281
|
+
*/
|
|
282
|
+
private positionWindow;
|
|
283
|
+
private appReady;
|
|
284
|
+
/**
|
|
285
|
+
* Callback on tray icon click or double-click.
|
|
286
|
+
*
|
|
287
|
+
* @param e
|
|
288
|
+
* @param bounds
|
|
289
|
+
*/
|
|
290
|
+
private clicked;
|
|
291
|
+
private onAppActivate;
|
|
292
|
+
private onBeforeQuit;
|
|
293
|
+
private bindContextMenu;
|
|
294
|
+
private bindRightClickContextMenu;
|
|
295
|
+
private refreshLinuxContextMenu;
|
|
296
|
+
private onAppReady;
|
|
297
|
+
private createWindow;
|
|
298
|
+
private windowClear;
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/util/getWindowPosition.d.ts
|
|
302
|
+
type TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';
|
|
303
|
+
/**
|
|
304
|
+
* Determine taskbard location: "top", "bottom", "left" or "right".
|
|
305
|
+
*
|
|
306
|
+
* Only tested on Windows for now, and only used in Windows.
|
|
307
|
+
*
|
|
308
|
+
* @param tray - The Electron Tray instance.
|
|
309
|
+
*/
|
|
310
|
+
declare function taskbarLocation(tray: Tray): TaskbarLocation;
|
|
311
|
+
type WindowPosition = 'trayCenter' | 'topRight' | 'trayBottomCenter' | 'leftCenter' | 'bottomRight';
|
|
312
|
+
/**
|
|
313
|
+
* Depending on where the taskbar is, determine where the window should be
|
|
314
|
+
* positioned.
|
|
315
|
+
*
|
|
316
|
+
* @param tray - The Electron Tray instance.
|
|
317
|
+
*/
|
|
318
|
+
declare function getWindowPosition(tray: Tray): WindowPosition;
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/index.d.ts
|
|
321
|
+
/**
|
|
322
|
+
* Factory function to create a menubar application
|
|
323
|
+
*
|
|
324
|
+
* @param options - Options for creating a menubar application, see
|
|
325
|
+
* {@link Options}
|
|
326
|
+
*/
|
|
327
|
+
declare function menubar(options?: Partial<Options>): Menubar;
|
|
328
|
+
//#endregion
|
|
329
|
+
export { Menubar, getWindowPosition, menubar, taskbarLocation };
|
|
330
|
+
//# sourceMappingURL=index.d.mts.map
|