electron-menubar 10.3.0 → 11.1.0

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/README.md CHANGED
@@ -36,31 +36,35 @@
36
36
 
37
37
  `electron-menubar` builds on [max-mapper/menubar][github-upstream-repo], with fixes and controls developed for [Gitify](https://github.com/gitify-app/gitify). The original provides the tray-app foundation. This fork brings more of the platform-specific behavior into the library so applications have less to implement themselves.
38
38
 
39
- | Area | What this fork adds |
40
- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41
- | Windows focus and positioning | Ignores transient blur events immediately after opening, keeps resized windows clear of the taskbar, handles left-side taskbars, and prevents recursive resize events during repositioning. |
42
- | Windows tray overflow | The new `hideOnBlur` option separates click-away dismissal from always-on-top behavior. Apps can keep their window above the hidden-icons panel and still dismiss it when focus moves away. See the configuration below. **Unreleased.** |
43
- | macOS | Opens on the active Space when another app is fullscreen, hides the Dock icon again after Electron's startup race, and ignores tray double-clicks by default to avoid flicker. |
44
- | Linux tray menus | Publishes native tray context menus and provides `refreshContextMenu()` to update them after menu items change. Documents native Wayland positioning limits and the XWayland workaround. |
45
- | Window controls | Built-in `hideOnClose`, `escapeToHide`, configurable tray triggers, global shortcuts, `toggleWindow()`, and `recenterOnTray()`. Closing can hide the window while real quits and updater restarts still work. |
46
- | Instance cleanup | `destroy()` removes the instance's listeners and unregisters its global shortcut. |
47
- | Packaging | Zero runtime dependencies, including a built-in positioner. Ships CommonJS and ESM entry points with TypeScript declarations. |
48
- | Verification | Unit tests, native Electron end-to-end tests on macOS, Windows, and Linux, and visual checks that the tray icon and window render. The [platform report][platforms] includes screenshots and positioning limitations. |
39
+ | Area | What this fork adds |
40
+ | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | Windows focus and positioning | Ignores transient blur events immediately after opening, keeps resized windows clear of the taskbar, handles left-side taskbars, and prevents recursive resize events during repositioning. |
42
+ | Windows tray overflow | Raises popups above the hidden-icons panel automatically and still dismisses on click-away. Apps use the same keep-open option on every platform. **Available since 11.0.0.** |
43
+ | macOS | Opens on the active Space when another app is fullscreen, hides the Dock icon again after Electron's startup race, and ignores tray double-clicks by default to avoid flicker. |
44
+ | Linux tray menus | Publishes native tray context menus and provides `refreshContextMenu()` to update them after menu items change. Documents native Wayland positioning limits and the XWayland workaround. |
45
+ | Window controls | Built-in `hideOnClose`, `escapeToHide`, configurable tray triggers, global shortcuts, `toggleWindow()`, and `recenterOnTray()`. Closing can hide the window while real quits and updater restarts still work. |
46
+ | Instance cleanup | `destroy()` removes the instance's listeners and unregisters its global shortcut. |
47
+ | Packaging | Zero runtime dependencies, including a built-in positioner. Ships CommonJS and ESM entry points with TypeScript declarations. |
48
+ | Verification | Unit tests, native Electron end-to-end tests on macOS, Windows, and Linux, and visual checks that the tray icon and window render. The [platform report][platforms] includes screenshots and positioning limitations. |
49
49
 
50
- ### Keeping Windows popups above the hidden-icons panel
50
+ ### Popup behavior without platform checks
51
51
 
52
- With the unreleased `hideOnBlur` option, use Electron's `pop-up-menu` level to address [Gitify #1048](https://github.com/gitify-app/gitify/issues/1048). The option controls dismissal; the Electron call controls window stacking.
52
+ Menubar manages popup stacking and focus on every platform. A plain `menubar()` dismisses on click-away and opens above the Windows hidden-icons panel. To keep it open, change one option:
53
53
 
54
54
  ```javascript
55
- const mb = menubar({ hideOnBlur: true });
55
+ const mb = menubar();
56
56
 
57
- mb.on('after-create-window', () => {
58
- if (process.platform === 'win32') {
59
- mb.window.setAlwaysOnTop(true, 'pop-up-menu');
60
- }
61
- });
57
+ mb.setOption('hideOnBlur', false); // Keep open and on top.
58
+ mb.setOption('hideOnBlur', true); // Resume click-away dismissal.
62
59
  ```
63
60
 
61
+ Opening DevTools temporarily keeps the popup open. Closing DevTools restores the latest `hideOnBlur` preference. Options set before window creation also apply when the window is recreated.
62
+
63
+ #### Migrating from 10.x
64
+
65
+ These defaults apply starting with 11.0.0. Previously, menubar inferred dismissal from `window.isAlwaysOnTop()`. Use `hideOnBlur: false` for persistent popups instead of `browserWindow.alwaysOnTop: true` or runtime `window.setAlwaysOnTop(true)` calls. `browserWindow.alwaysOnTop` now controls stacking only; it does not disable dismissal. Setting `hideOnBlur: false` also keeps the popup on top on macOS and Linux.
66
+
67
+ Remove Windows `pop-up-menu` workarounds and DevTools focus handlers from apps. Menubar owns stacking during window creation, showing, preference changes, and DevTools transitions. Apps can still customize DevTools dimensions and layout.
64
68
  See the [changelog](CHANGELOG.md) for released changes and the [API documentation](#api-documentation) for all options.
65
69
 
66
70
  ## Installation
@@ -141,19 +145,19 @@ You can pass an optional options object into the `menubar({ ... })` function:
141
145
  | ------------------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142
146
  | `dir` | `process.cwd()` | The app source directory. |
143
147
  | `index` | `file:// + opts.dir + index.html` | The URL to load the menubar's `browserWindow` with. The url can be a remote address (e.g. `http://`) or a path to a local HTML file using the `file://` protocol. |
144
- | `browserWindow` | | BrowserWindow options passed to the BrowserWindow constructor, see [Electron docs][electron-docs-browserwindow-options]. <details><summary>Useful fields</summary>• `x` (default `undefined`) - the x position of the window<br>• `y` (default `undefined`) - the y position of the window<br>• `width` (default `400`) - window width<br>• `height` (default `400`) - window height<br>• `alwaysOnTop` (default `false`) - if `true`, the window will not hide on blur unless `hideOnBlur` is explicitly `true`</details> |
148
+ | `browserWindow` | | BrowserWindow options passed to the BrowserWindow constructor, see [Electron docs][electron-docs-browserwindow-options]. <details><summary>Useful fields</summary>• `x` (default `undefined`) - the x position of the window<br>• `y` (default `undefined`) - the y position of the window<br>• `width` (default `400`) - window width<br>• `height` (default `400`) - window height<br>• `alwaysOnTop` (default `false`) - keeps the window on top without changing click-away dismissal; Windows popups are always raised above the tray</details> |
145
149
  | `icon` | `opts.dir + IconTemplate.png` | The png icon to use for the menubar. A good size to start with is 20x20. To support retina, supply a 2x sized image (e.g. 40x40) with `@2x` added to the end of the name, so `icon.png` and `icon@2x.png`, and Electron will automatically use your `@2x` version on retina screens. |
146
150
  | `tooltip` | empty | Menubar tray icon tooltip text. |
147
151
  | `tray` | created on-the-fly | An Electron `Tray` instance. If provided, `opts.icon` will be ignored. |
148
152
  | `preloadWindow` | `false` | Create [BrowserWindow][electron-docs-browserwindow-options] instance before it is used, increasing resource usage but making the click on the menubar load faster. |
149
153
  | `loadUrlOptions` | `undefined` | The options passed when loading the index URL in the menubar's `browserWindow`. Everything `browserWindow.loadURL` supports is supported; this object is simply passed onto [browserWindow.loadURL][electron-docs-browserwindow-loadurl]. |
150
- | `showOnAllWorkspaces` | `true` | Makes the window available on all macOS workspaces. |
154
+ | `showOnAllWorkspaces` | `true` | Makes the window available on all macOS workspaces. On macOS the window leaves all workspaces while hidden and rejoins them on `showWindow()`, so show it with `showWindow()` rather than `window.show()` or `window.showInactive()`. |
151
155
  | `windowPosition` | `trayCenter` (macOS/Linux), `trayBottomCenter` (Windows) | Sets the window position (`browserWindow.x` / `browserWindow.y` will still override this). Valid values: `trayLeft`, `trayBottomLeft`, `trayRight`, `trayBottomRight`, `trayCenter`, `trayBottomCenter`, `topLeft`, `topRight`, `bottomLeft`, `bottomRight`, `topCenter`, `bottomCenter`, `leftCenter`, `rightCenter`, `center`. |
152
156
  | `showDockIcon` | `false` | Configure the visibility of the application dock icon, macOS only. <details><summary>Hiding reliably</summary>When `false`, the library calls [`app.dock.hide()`](https://www.electronjs.org/docs/latest/api/app#appdockhide-macos) at startup and re-asserts it once shortly after, because macOS can silently drop the underlying process transform when it races the launch activation. The transform only runs after the process has already launched as a regular dock app, so the tile briefly exists on every launch and hiding it stays best-effort. Packaged apps that never want a dock tile should also declare [`LSUIElement`](https://developer.apple.com/documentation/bundleresources/information-property-list/lsuielement) in their `Info.plist` (with electron-builder: `mac.extendInfo.LSUIElement: true`), so the process starts as an agent app and no tile is ever created. `showDockIcon: false` then still covers development runs, where the stock Electron binary's plist is not under your control.</details> |
153
157
  | `trigger` | `'click'` | Tray event that toggles the menubar window. One of `'click'`, `'right-click'`, or `'none'`. Use `'none'` to disable automatic toggling, useful when a single tray icon serves multiple windows. The window can still be shown by calling `mb.showWindow()` directly. |
154
158
  | `showOnRightClick` | `false` | **Deprecated**, use `trigger: 'right-click'` instead. Show the window on `right-click` event instead of regular `click`. |
155
159
  | `contextMenu` | | An Electron `Menu` to attach to the tray icon. <details><summary>Platform behavior</summary>On Linux it is bound via `tray.setContextMenu` (required by libappindicator / StatusNotifierItem) and re-published on every show/hide to defeat the indicator's menu cache. On macOS and Windows it pops up on right-click via `tray.popUpContextMenu`, so left-click continues to toggle the window. Combine with `trigger: 'none'` if you want right-click to be the only interaction.</details> |
156
- | `hideOnBlur` | inferred from `alwaysOnTop` | Set `true` to hide on click-away even when the window is always on top, or `false` to emit `focus-lost` and stay open. Omit to preserve the default: always-on-top windows stay open, other windows hide. Supports runtime changes through `setOption`. |
160
+ | `hideOnBlur` | `true` | Set `false` to keep the popup open and on top, emitting `focus-lost` on click-away. Defaults to `true`. DevTools temporarily suspends dismissal without changing this preference. Supports runtime changes through `setOption`. |
157
161
  | `hideOnClose` | `false` | Hide the window on `close` instead of destroying it, so the next tray click re-uses the same `BrowserWindow`. <details><summary>Platform notes</summary>On Linux/Wayland the hide is deferred via `setImmediate` to work around a compositor bug that leaves frameless surfaces in a half-closed state when hidden synchronously from the `close` handler. The library tracks the app's `before-quit` event and the auto updater's `before-quit-for-update` event internally, so real quits and update restarts go through unimpeded.</details> |
158
162
  | `escapeToHide` | `false` | Hide the menubar window when the user presses `Escape` while it has focus. |
159
163
  | `ignoreDoubleClickEvents` | `true` (macOS only) | Calls `tray.setIgnoreDoubleClickEvents(true)` so an accidental double-click doesn't race the close-on-blur handler and flicker the tray icon. Pass `false` to opt out. No-op on Linux/Windows. |
@@ -174,12 +178,12 @@ The `Menubar` class is an event emitter:
174
178
  | `hide` | The line before `window.hide()` is called (on window blur). |
175
179
  | `after-hide` | The line after `window.hide()` is called. |
176
180
  | `after-close` | After the `.window` (BrowserWindow) property has been deleted. |
177
- | `focus-lost` | Emitted on click-away when `hideOnBlur` is `false`, or when it is omitted and the window is always on top. |
181
+ | `focus-lost` | Emitted on click-away when `hideOnBlur` is `false` or DevTools is open. |
178
182
 
179
183
  ## Tips
180
184
 
181
185
  - Use `mb.on('after-create-window', callback)` to run things after your app has loaded. For example you could run `mb.window.openDevTools()` to open the developer tools for debugging, or load a different URL with `mb.window.loadURL()`
182
- - Use `mb.on('focus-lost')` if you would like to perform some operation when using the option `browserWindow.alwaysOnTop: true`
186
+ - Use `mb.on('focus-lost')` if you would like to perform some operation when using the option `hideOnBlur: false`
183
187
  - To restore focus of previous window after menubar hide, use `mb.on('after-hide', () => { mb.app.hide() } )` or similar
184
188
  - To attach a native context menu, pass it as `contextMenu`: `menubar({ contextMenu })`. The library wires it via `setContextMenu` on Linux and `popUpContextMenu` on right-click on macOS/Windows so left-click still toggles the window. See [this example][examples-native] for more information.
185
189
  - To avoid a flash when opening your menubar app, you can disable backgrounding the app using the following: `mb.app.commandLine.appendSwitch('disable-backgrounding-occluded-windows', 'true');`
package/lib/index.cjs CHANGED
@@ -256,6 +256,7 @@ var Menubar = class extends node_events.EventEmitter {
256
256
  _lastShowTime = 0;
257
257
  _dockRehideTimeout;
258
258
  _repositioning = false;
259
+ _showOnAllWorkspaces = false;
259
260
  _tray;
260
261
  constructor(app, options) {
261
262
  super();
@@ -353,6 +354,7 @@ var Menubar = class extends node_events.EventEmitter {
353
354
  if (!this._browserWindow || !this._isVisible) return;
354
355
  this.emit("hide");
355
356
  this._browserWindow.hide();
357
+ if (process.platform === "darwin") this.applyWorkspaceVisibility(false);
356
358
  this.emit("after-hide");
357
359
  this._isVisible = false;
358
360
  if (this._blurTimeout) {
@@ -445,6 +447,22 @@ var Menubar = class extends node_events.EventEmitter {
445
447
  */
446
448
  setOption(key, value) {
447
449
  this._options[key] = value;
450
+ if (key === "hideOnBlur" || key === "browserWindow") this.applyWindowFocusBehavior();
451
+ }
452
+ shouldHideOnBlur() {
453
+ const win = this._browserWindow;
454
+ return !!win && !win.isDestroyed() && this._options.hideOnBlur !== false && !win.webContents.isDevToolsOpened();
455
+ }
456
+ applyWindowFocusBehavior() {
457
+ const win = this._browserWindow;
458
+ if (!win || win.isDestroyed()) return;
459
+ const keepOpen = !this.shouldHideOnBlur();
460
+ if (this._blurTimeout) {
461
+ clearTimeout(this._blurTimeout);
462
+ this._blurTimeout = null;
463
+ }
464
+ if (process.platform === "win32") win.setAlwaysOnTop(true, "pop-up-menu");
465
+ else win.setAlwaysOnTop(keepOpen || this._options.browserWindow.alwaysOnTop === true);
448
466
  }
449
467
  /**
450
468
  * Show the menubar window.
@@ -458,7 +476,9 @@ var Menubar = class extends node_events.EventEmitter {
458
476
  this.emit("show");
459
477
  if (trayPos && trayPos.x !== 0) this._cachedBounds = trayPos;
460
478
  else if (!this._cachedBounds && this.tray.getBounds) this._cachedBounds = this.tray.getBounds();
479
+ if (process.platform === "darwin") this.applyWorkspaceVisibility(true);
461
480
  this.positionWindow();
481
+ this.applyWindowFocusBehavior();
462
482
  this._lastShowTime = Date.now();
463
483
  this._browserWindow.show();
464
484
  this._isVisible = true;
@@ -592,21 +612,28 @@ var Menubar = class extends node_events.EventEmitter {
592
612
  ...this._options.browserWindow
593
613
  });
594
614
  this._positioner = new Positioner(this._browserWindow);
615
+ this.applyWindowFocusBehavior();
616
+ this._browserWindow.webContents.on("devtools-opened", () => {
617
+ this.applyWindowFocusBehavior();
618
+ });
619
+ this._browserWindow.webContents.on("devtools-closed", () => {
620
+ this.applyWindowFocusBehavior();
621
+ });
595
622
  this._browserWindow.on("blur", () => {
596
623
  if (!this._browserWindow) return;
597
- if (!(this._options.hideOnBlur ?? !this._browserWindow.isAlwaysOnTop())) {
624
+ if (!this.shouldHideOnBlur()) {
598
625
  this.emit("focus-lost");
599
626
  return;
600
627
  }
601
628
  if (process.platform === "win32" && Date.now() - this._lastShowTime < BLUR_HIDE_GRACE_MS) return;
629
+ if (this._blurTimeout) clearTimeout(this._blurTimeout);
602
630
  this._blurTimeout = setTimeout(() => {
603
- this.hideWindow();
631
+ this._blurTimeout = null;
632
+ if (this.shouldHideOnBlur()) this.hideWindow();
604
633
  }, 100);
605
634
  });
606
- if (this._options.showOnAllWorkspaces !== false) this._browserWindow.setVisibleOnAllWorkspaces(true, {
607
- visibleOnFullScreen: true,
608
- skipTransformProcessType: true
609
- });
635
+ this._showOnAllWorkspaces = this._options.showOnAllWorkspaces !== false;
636
+ this.applyWorkspaceVisibility(true);
610
637
  if (this._options.hideOnClose) this._browserWindow.on("close", (event) => {
611
638
  if (this._isDestroyed || this._isQuitting) return;
612
639
  event.preventDefault();
@@ -621,6 +648,25 @@ var Menubar = class extends node_events.EventEmitter {
621
648
  if (this._options.index !== false) await this._browserWindow.loadURL(this._options.index, this._options.loadUrlOptions);
622
649
  this.emit("after-create-window");
623
650
  }
651
+ /**
652
+ * Join or leave every workspace when `showOnAllWorkspaces` is enabled.
653
+ *
654
+ * On macOS the hidden popup leaves every Space in {@link hideWindow} and
655
+ * rejoins them right before `show()` in {@link showWindow}. macOS can drop
656
+ * a hidden window from all but one Space while `isVisibleOnAllWorkspaces()`
657
+ * still reports `true`, e.g. when the fullscreen Space the popup was last
658
+ * shown on closes. Showing it then switches to that one Space, and setting
659
+ * the flag again to the value it already has does not re-add the window.
660
+ * Clearing the flag while hidden makes the next show a real change, which
661
+ * re-adds the window to every Space before it appears.
662
+ */
663
+ applyWorkspaceVisibility(visible) {
664
+ if (!this._browserWindow || this._browserWindow.isDestroyed() || !this._showOnAllWorkspaces) return;
665
+ this._browserWindow.setVisibleOnAllWorkspaces(visible, {
666
+ visibleOnFullScreen: visible,
667
+ skipTransformProcessType: true
668
+ });
669
+ }
624
670
  windowClear() {
625
671
  this._browserWindow = void 0;
626
672
  this.emit("after-close");
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["screen","app","path","url","electronScreen","EventEmitter","globalShortcut","path","fs","Tray","BrowserWindow","app"],"sources":["../src/Positioner.ts","../src/util/cleanOptions.ts","../src/util/getWindowPosition.ts","../src/Menubar.ts","../src/index.ts"],"sourcesContent":["import { type BrowserWindow, type Rectangle, screen } from 'electron';\n\n/**\n * Named anchor points for placing the menubar window. The `tray*` values are\n * relative to the tray icon's bounds; the rest are relative to the work area\n * of the display containing the cursor (or the tray, when bounds are given).\n */\nexport type WindowPosition =\n | 'trayLeft'\n | 'trayBottomLeft'\n | 'trayRight'\n | 'trayBottomRight'\n | 'trayCenter'\n | 'trayBottomCenter'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'topCenter'\n | 'bottomCenter'\n | 'leftCenter'\n | 'rightCenter'\n | 'center';\n\n/**\n * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named\n * position, optionally relative to a tray icon's bounds. Ported from\n * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency.\n */\nexport class Positioner {\n private readonly browserWindow: BrowserWindow;\n\n constructor(browserWindow: BrowserWindow) {\n this.browserWindow = browserWindow;\n }\n\n calculate(\n position?: WindowPosition,\n trayBounds?: Rectangle,\n ): { x: number; y: number } {\n if (!position) {\n throw new TypeError(\n 'Positioner.calculate: a `position` argument is required.',\n );\n }\n\n const screenSize = trayBounds\n ? screen.getDisplayMatching(trayBounds).workArea\n : screen.getDisplayNearestPoint(screen.getCursorScreenPoint()).workArea;\n const [windowWidth, windowHeight] = this.browserWindow.getSize();\n const trayX = trayBounds?.x ?? Number.NaN;\n const trayWidth = trayBounds?.width ?? Number.NaN;\n\n const positions: Record<WindowPosition, { x: number; y: number }> = {\n trayLeft: {\n x: Math.floor(trayX),\n y: screenSize.y,\n },\n trayBottomLeft: {\n x: Math.floor(trayX),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: screenSize.y,\n },\n trayBottomRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: screenSize.y,\n },\n trayBottomCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topLeft: {\n x: screenSize.x,\n y: screenSize.y,\n },\n topRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: screenSize.y,\n },\n bottomLeft: {\n x: screenSize.x,\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n bottomRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: screenSize.y,\n },\n bottomCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n leftCenter: {\n x: screenSize.x,\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n rightCenter: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n center: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(\n (screenSize.height + screenSize.y) / 2 - windowHeight / 2,\n ),\n },\n };\n\n const coords = positions[position];\n\n // On Windows, a tray-relative position can push the window past the right\n // edge of the work area. Snap back to `topRight` x in that case so it stays\n // visible. See https://github.com/jenslind/electron-positioner.\n if (position.startsWith('tray')) {\n if (coords.x + windowWidth > screenSize.width + screenSize.x) {\n return { x: positions.topRight.x, y: coords.y };\n }\n }\n\n return coords;\n }\n}\n","/**\n * @ignore\n */\n\n/** */\n\nimport path from 'node:path';\nimport url from 'node:url';\n\nimport { app } from 'electron';\n\nimport type { Options } from '../types';\n\nconst DEFAULT_WINDOW_HEIGHT = 400;\nconst DEFAULT_WINDOW_WIDTH = 400;\n\n/**\n * Take as input some options, and return a sanitized version of it.\n *\n * @param opts - The options to clean.\n * @ignore\n */\nexport function cleanOptions(opts?: Partial<Options>): Options {\n const options: Partial<Options> = { ...opts };\n\n if (options.activateWithApp === undefined) {\n options.activateWithApp = true;\n }\n if (options.ignoreDoubleClickEvents === undefined) {\n options.ignoreDoubleClickEvents = true;\n }\n if (!options.dir) {\n options.dir = app.getAppPath();\n }\n if (!path.isAbsolute(options.dir)) {\n options.dir = path.resolve(options.dir);\n }\n // Note: options.index can be `false`\n if (options.index === undefined) {\n options.index = url.format({\n pathname: path.join(options.dir, 'index.html'),\n protocol: 'file:',\n slashes: true,\n });\n }\n options.loadUrlOptions = options.loadUrlOptions || {};\n\n options.tooltip = options.tooltip || '';\n\n // `icon`, `preloadWindow`, `showDockIcon`, `showOnAllWorkspaces`,\n // `showOnRightClick` don't need any special treatment\n\n // Now we take care of `browserWindow`\n if (!options.browserWindow) {\n options.browserWindow = {};\n }\n\n // Set width/height on options to be usable before the window is created\n options.browserWindow.width =\n // Note: not using `options.browserWindow.width || DEFAULT_WINDOW_WIDTH` so\n // that users can put a 0 width\n options.browserWindow.width !== undefined\n ? options.browserWindow.width\n : DEFAULT_WINDOW_WIDTH;\n options.browserWindow.height =\n options.browserWindow.height !== undefined\n ? options.browserWindow.height\n : DEFAULT_WINDOW_HEIGHT;\n\n return options as Options;\n}\n","/**\n * Utilities to get taskbar position and consequently menubar's position\n */\n\n/** */\n\nimport { screen as electronScreen, type Rectangle, type Tray } from 'electron';\n\nconst isLinux = process.platform === 'linux';\n\nconst trayToScreenRects = (trayBounds: Rectangle): [Rectangle, Rectangle] => {\n // There may be more than one screen, so we need to figure out on which screen our tray icon lives.\n const { workArea, bounds: screenBounds } =\n electronScreen.getDisplayMatching(trayBounds);\n\n return [\n screenBounds,\n {\n ...workArea,\n x: workArea.x - screenBounds.x,\n y: workArea.y - screenBounds.y,\n },\n ];\n};\n\ntype TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';\n\n/**\n * Determine taskbard location: \"top\", \"bottom\", \"left\" or \"right\".\n *\n * Only tested on Windows for now, and only used in Windows.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function taskbarLocation(tray: Tray): TaskbarLocation {\n const trayBounds = tray.getBounds();\n const [screenBounds, workArea] = trayToScreenRects(trayBounds);\n\n if (\n process.platform === 'win32' &&\n trayBounds.width > 0 &&\n trayBounds.height > 0\n ) {\n // Other appbars also reserve work-area space. The tray's nearest display\n // edge identifies the taskbar without mistaking a PowerToys dock for it.\n const x = trayBounds.x + trayBounds.width / 2 - screenBounds.x;\n const y = trayBounds.y + trayBounds.height / 2 - screenBounds.y;\n const insets: Record<TaskbarLocation, number> = {\n top: workArea.y,\n bottom: screenBounds.height - workArea.y - workArea.height,\n left: workArea.x,\n right: screenBounds.width - workArea.x - workArea.width,\n };\n let nearest: [TaskbarLocation, number] = [\n 'bottom',\n Math.abs(screenBounds.height - y),\n ];\n const edges: [TaskbarLocation, number][] = [\n ['top', Math.abs(y)],\n ['left', Math.abs(x)],\n ['right', Math.abs(screenBounds.width - x)],\n ];\n for (const edge of edges) {\n // At a corner, prefer the edge that actually reserves work-area space.\n if (\n edge[1] < nearest[1] ||\n (edge[1] === nearest[1] && insets[edge[0]] > insets[nearest[0]])\n )\n nearest = edge;\n }\n return nearest[0];\n }\n\n // TASKBAR LEFT\n if (workArea.x > 0) {\n // Most likely Ubuntu hence assuming the window should be on top\n if (isLinux && workArea.y > 0) return 'top';\n // The workspace starts more on the right\n return 'left';\n }\n\n // TASKBAR TOP\n if (workArea.y > 0) {\n return 'top';\n }\n\n // TASKBAR RIGHT\n // Here both workArea.y and workArea.x are 0 so we can no longer leverage them.\n // We can use the workarea and display width though.\n // Determine taskbar location\n if (workArea.width < screenBounds.width) {\n // The taskbar is either on the left or right, but since the LEFT case was handled above,\n // we can be sure we're dealing with a right taskbar\n return 'right';\n }\n\n // TASKBAR BOTTOM\n // Since all the other cases were handled, we can be sure we're dealing with a bottom taskbar\n return 'bottom';\n}\n\ntype WindowPosition =\n | 'trayCenter'\n | 'topRight'\n | 'trayBottomCenter'\n | 'leftCenter'\n | 'bottomRight';\n\n/**\n * Depending on where the taskbar is, determine where the window should be\n * positioned.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function getWindowPosition(tray: Tray): WindowPosition {\n switch (process.platform) {\n // macOS\n // Supports top taskbars\n case 'darwin':\n return 'trayCenter';\n // Linux\n // Windows\n // Supports top/bottom/left/right taskbar\n case 'linux':\n case 'win32': {\n const traySide = taskbarLocation(tray);\n\n // Assign position for menubar\n if (traySide === 'top') {\n return isLinux ? 'topRight' : 'trayCenter';\n }\n if (traySide === 'bottom') {\n return 'bottomRight';\n }\n if (traySide === 'left') {\n // Vertically centered against the left edge of the work area.\n // `bottomLeft` would put the window in the screen's bottom-left\n // corner — visually disconnected from the tray icon, which sits\n // somewhere on the left strip. Tray-anchored y isn't available\n // through `Positioner` for side taskbars, so center is the best\n // compromise that stays close to the tray.\n return 'leftCenter';\n }\n if (traySide === 'right') {\n return 'bottomRight';\n }\n }\n }\n\n // When we really don't know, we just show the menubar on the top-right\n return 'topRight';\n}\n","import { EventEmitter } from 'node:events';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n autoUpdater,\n BrowserWindow,\n globalShortcut,\n type Menu,\n Tray,\n} from 'electron';\n\nimport { Positioner } from './Positioner';\nimport type { Options } from './types';\nimport { cleanOptions } from './util/cleanOptions';\nimport { getWindowPosition } from './util/getWindowPosition';\n\n/**\n * Grace period after `showWindow()` during which a `blur` on the popup is\n * treated as the spurious Windows post-show blur and ignored instead of\n * triggering the auto-hide. See the `blur` handler in {@link Menubar.createWindow}.\n */\nconst BLUR_HIDE_GRACE_MS = 400;\n\n/**\n * Delay before re-asserting the hidden dock after startup. macOS can silently\n * drop an `app.dock.hide()` that races the app's launch activation\n * transition, leaving the dock icon stuck for the whole session. See the\n * re-check in {@link Menubar.appReady}.\n */\nconst DOCK_REHIDE_DELAY_MS = 2_000;\n\n/**\n * The main Menubar class.\n */\nexport class Menubar extends EventEmitter {\n private _app: Electron.App;\n private _browserWindow?: BrowserWindow;\n private _contextMenu?: Menu;\n private _blurTimeout: NodeJS.Timeout | null = null; // track blur events with timeout\n private _isDestroyed: boolean;\n private _isQuitting: boolean; // set when the app is shutting down, used by hideOnClose\n private _isVisible: boolean; // track visibility\n private _cachedBounds?: Electron.Rectangle; // _cachedBounds are needed for double-clicked event\n private _options: Options;\n private _positioner: Positioner | undefined;\n private _shortcut?: Electron.Accelerator;\n private _rightClickContextMenuBound = false;\n private _warnedNoPositioning = false; // guards the one-time Wayland warning\n private _lastShowTime = 0; // timestamp of last show(), debounces the post-show blur on Windows\n private _dockRehideTimeout?: NodeJS.Timeout; // pending post-startup dock re-hide check\n private _repositioning = false; // guards against re-entrant positionWindow calls\n private _tray?: Tray;\n\n constructor(app: Electron.App, options?: Partial<Options>) {\n super();\n this._app = app;\n this._options = cleanOptions(options);\n this._isDestroyed = false;\n this._isQuitting = false;\n this._isVisible = false;\n\n app.on('before-quit', this.onBeforeQuit);\n autoUpdater.on('before-quit-for-update', this.onBeforeQuit);\n\n if (app.isReady()) {\n // See https://github.com/maxogden/menubar/pull/151\n process.nextTick(this.onAppReady);\n } else {\n app.on('ready', this.onAppReady);\n }\n }\n\n /**\n * The Electron [App](https://electronjs.org/docs/api/app)\n * instance.\n */\n get app(): Electron.App {\n return this._app;\n }\n\n /**\n * The {@link Positioner} instance used to compute where the menubar window\n * should appear on screen. Available after the `after-create-window` event.\n */\n get positioner(): Positioner {\n if (!this._positioner) {\n throw new Error(\n 'Please access `this.positioner` after the `after-create-window` event has fired.',\n );\n }\n\n return this._positioner;\n }\n\n /**\n * The Electron [Tray](https://electronjs.org/docs/api/tray) instance.\n */\n get tray(): Tray {\n if (!this._tray) {\n throw new Error(\n 'Please access `this.tray` after the `ready` event has fired.',\n );\n }\n\n return this._tray;\n }\n\n /**\n * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)\n * instance, if it's present.\n */\n get window(): BrowserWindow | undefined {\n return this._browserWindow;\n }\n\n /**\n * Tear down the menubar instance: destroy the window, remove the tray, and\n * detach all listeners. Subsequent clicks on the tray will be no-ops until a\n * new {@link Menubar} instance is created.\n */\n destroy(): void {\n if (this.isDestroyed()) {\n return;\n }\n // Set first so `hideOnClose` lets the close go through instead of\n // intercepting it.\n this._isDestroyed = true;\n\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n\n if (this._dockRehideTimeout) {\n clearTimeout(this._dockRehideTimeout);\n this._dockRehideTimeout = undefined;\n }\n\n if (this._browserWindow) {\n this._browserWindow.destroy();\n this._browserWindow = undefined;\n }\n\n if (this._tray) {\n // Ensure all potential listeners are removed.\n for (const event of ['click', 'right-click', 'double-click']) {\n this._tray.removeListener(\n event as Parameters<Tray['on']>[0],\n this.clicked,\n );\n }\n this._tray.setToolTip('');\n this._tray = undefined;\n }\n\n this._app.removeListener('ready', this.onAppReady);\n this._app.removeListener('activate', this.onAppActivate);\n this._app.removeListener('before-quit', this.onBeforeQuit);\n autoUpdater.removeListener('before-quit-for-update', this.onBeforeQuit);\n }\n\n /**\n * Whether {@link destroy} has been called on this menubar instance.\n */\n isDestroyed(): boolean {\n return this._isDestroyed;\n }\n\n /**\n * Retrieve a menubar option.\n *\n * @param key - The option key to retrieve, see {@link Options}.\n */\n getOption<K extends keyof Options>(key: K): Options[K] {\n return this._options[key];\n }\n\n /**\n * Hide the menubar window.\n */\n hideWindow(): void {\n if (!this._browserWindow || !this._isVisible) {\n return;\n }\n this.emit('hide');\n this._browserWindow.hide();\n this.emit('after-hide');\n this._isVisible = false;\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n this._blurTimeout = null;\n }\n this.refreshContextMenu();\n }\n\n /**\n * Register a global keyboard accelerator that toggles the menubar window.\n * Replaces any previously registered shortcut owned by this Menubar.\n * Pass `undefined` to clear the current shortcut without registering a new\n * one. Returns whether the registration succeeded.\n *\n * @param accelerator - An Electron\n * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or\n * `undefined` to clear.\n */\n setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean {\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n this._options.globalShortcut = accelerator;\n if (!accelerator) {\n return true;\n }\n const ok = globalShortcut.register(accelerator, () => this.toggleWindow());\n if (ok) {\n this._shortcut = accelerator;\n }\n return ok;\n }\n\n /**\n * Toggle the menubar window: hide it if visible, show it otherwise.\n * Resolves once the window finishes showing or hiding.\n */\n async toggleWindow(): Promise<void> {\n if (this._browserWindow && this._isVisible) {\n this.hideWindow();\n return;\n }\n await this.showWindow();\n }\n\n /**\n * Re-center the menubar window over the tray icon. Convenience wrapper for\n * `positioner.move('trayCenter', tray.getBounds())` that's safe to call\n * after the `after-create-window` event. No-op if the window doesn't\n * exist yet.\n */\n recenterOnTray(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n const bounds = this._tray.getBounds();\n const { x, y } = this.positioner.calculate('trayCenter', bounds);\n this._browserWindow.setPosition(Math.round(x), Math.round(y));\n }\n\n /**\n * Replace the tray context menu after construction. On Linux this also\n * re-publishes the menu to the SNI host, which is required after mutating\n * items in-place since libappindicator caches the previous serialization.\n * On macOS/Windows the right-click popup handler reads the current menu\n * reference, so swapping or clearing here takes effect immediately.\n *\n * @param menu - The new menu, or `null` to clear it.\n */\n setContextMenu(menu: Menu | null): void {\n this._contextMenu = menu ?? undefined;\n this._options.contextMenu = menu ?? undefined;\n if (!this._tray) {\n return;\n }\n if (process.platform === 'linux') {\n // `setContextMenu(null)` clears the menu on Linux.\n this._tray.setContextMenu(menu);\n return;\n }\n // macOS / Windows: bind the right-click popup once on first non-empty\n // assignment. The handler reads `this._contextMenu` at invoke time, so\n // later swaps and clears take effect without rebinding (and never leak\n // a stale closure reference).\n if (menu && !this._rightClickContextMenuBound) {\n this.bindRightClickContextMenu();\n }\n }\n\n /**\n * Re-publish the current context menu so in-place mutations of its items\n * (`visible`, `enabled`, `checked`, `label`) become visible to the user.\n *\n * Only Linux needs this: libappindicator / StatusNotifierItem serializes the\n * menu once and serves that copy until it is set again, so a mutated item\n * would otherwise keep rendering its old state until the next show or hide.\n * A no-op on macOS and Windows, where the menu is read at popup time — call\n * it unconditionally after mutating items.\n */\n refreshContextMenu(): void {\n if (\n process.platform === 'linux' &&\n this._contextMenu &&\n this._tray &&\n !this._tray.isDestroyed?.()\n ) {\n this._tray.setContextMenu(this._contextMenu);\n }\n }\n\n /**\n * Change an option after menubar is created.\n *\n * @param key - The option key to modify, see {@link Options}.\n * @param value - The value to set.\n */\n setOption<K extends keyof Options>(key: K, value: Options[K]): void {\n this._options[key] = value;\n }\n\n /**\n * Show the menubar window.\n *\n * @param trayPos - The bounds to show the window in.\n */\n async showWindow(trayPos?: Electron.Rectangle): Promise<void> {\n if (!this.tray) {\n throw new Error('Tray should have been instantiated by now');\n }\n\n if (!this._browserWindow) {\n await this.createWindow();\n }\n\n // Use guard for TypeScript, to avoid ! everywhere\n if (!this._browserWindow) {\n throw new Error('Window has been initialized just above. qed.');\n }\n\n this.emit('show');\n\n // Cache fresh tray bounds (or fall back to existing cache / tray bounds)\n // so `positionWindow` can reposition without an event payload — for\n // example when the window resizes via `setSize`.\n if (trayPos && trayPos.x !== 0) {\n this._cachedBounds = trayPos;\n } else if (!this._cachedBounds && this.tray.getBounds) {\n this._cachedBounds = this.tray.getBounds();\n }\n\n this.positionWindow();\n // Record the show time before `show()` so the blur handler can recognise\n // and ignore the transient blur Windows fires right after (see below).\n this._lastShowTime = Date.now();\n this._browserWindow.show();\n this._isVisible = true;\n this.emit('after-show');\n this.refreshContextMenu();\n }\n\n /**\n * Compute and apply the tray-anchored position of the browser window. Safe\n * to call any time after `createWindow` has run — invoked from\n * {@link showWindow} on every show, and from the window's `resize` event so\n * `setSize` calls reposition the window correctly.\n */\n private positionWindow = (): void => {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // `setPosition` below can make Windows emit `resize` synchronously, which\n // re-enters this method through the window's `resize` listener. Each pass\n // nudges the window again, so the recursion never unwinds: the main\n // process wedges with the event loop blocked and the window grows past\n // screen size (gitify-app/gitify#3064). Ignore re-entrant calls; the\n // outermost one already applies the final position.\n if (this._repositioning) {\n return;\n }\n this._repositioning = true;\n try {\n this.applyWindowPosition();\n } finally {\n this._repositioning = false;\n }\n };\n\n /**\n * Compute and apply the tray-anchored position. Always call through\n * {@link positionWindow}, which guards against re-entrancy.\n */\n private applyWindowPosition(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // 'Windows' taskbar: sync window position each time before positioning.\n // https://github.com/maxogden/menubar/issues/232\n if (['win32', 'linux'].includes(process.platform)) {\n this._options.windowPosition = getWindowPosition(this._tray);\n }\n\n const trayPos = this._cachedBounds ?? this._tray.getBounds?.();\n\n // Default the window to the right if `trayPos` bounds are undefined or null.\n let noBoundsPosition: Options['windowPosition'];\n if (\n (trayPos === undefined || trayPos.x === 0) &&\n this._options.windowPosition?.startsWith('tray')\n ) {\n noBoundsPosition =\n process.platform === 'win32' ? 'bottomRight' : 'topRight';\n }\n\n const position = this.positioner.calculate(\n this._options.windowPosition || noBoundsPosition,\n trayPos,\n ) as { x: number; y: number };\n\n // Not using `||` because x and y can be zero.\n const x =\n this._options.browserWindow.x !== undefined\n ? this._options.browserWindow.x\n : position.x;\n const y =\n this._options.browserWindow.y !== undefined\n ? this._options.browserWindow.y\n : position.y;\n\n // `.setPosition` crashed on non-integers\n // https://github.com/maxogden/menubar/issues/233\n const targetX = Math.round(x);\n const targetY = Math.round(y);\n this._browserWindow.setPosition(targetX, targetY);\n\n // Native Wayland gives an application no way to position its own window:\n // `setPosition` is a no-op and `getPosition` reads back [0, 0]\n // (https://github.com/electron/electron/issues/40886). The compositor\n // decides where the window lands, usually centered, so the popover can't\n // be anchored to the tray. Detect that the move didn't take and warn once,\n // pointing at the X11 fallback. Gated on a Wayland session (`WAYLAND_DISPLAY`)\n // so pure X11 never trips it; the tolerance absorbs the few-pixel offsets\n // X11 window managers add for decorations, so XWayland (where positioning\n // works) doesn't trip it either.\n if (\n process.platform === 'linux' &&\n !!process.env.WAYLAND_DISPLAY &&\n !this._warnedNoPositioning\n ) {\n const [actualX, actualY] = this._browserWindow.getPosition();\n const ignored =\n Math.abs(actualX - targetX) > 24 || Math.abs(actualY - targetY) > 24;\n if (ignored) {\n this._warnedNoPositioning = true;\n console.warn(\n '[menubar] The window could not be positioned programmatically, ' +\n 'which is expected on native Wayland where the compositor controls ' +\n 'placement. The popover will not be anchored to the tray icon. Run ' +\n 'with --ozone-platform=x11 to restore tray-relative positioning.',\n );\n }\n }\n }\n\n private async appReady(): Promise<void> {\n if (this.app.dock && !this._options.showDockIcon) {\n this.app.dock.hide();\n\n // The hide above can be silently dropped when it races the launch\n // activation transition. Re-check once startup has settled; guarded on\n // visibility because `dock.hide()` also deactivates the app, so it must\n // not run when the dock is already hidden.\n this._dockRehideTimeout = setTimeout(() => {\n if (!this._isDestroyed && this.app.dock?.isVisible()) {\n this.app.dock.hide();\n }\n }, DOCK_REHIDE_DELAY_MS);\n }\n\n if (this._options.activateWithApp) {\n this.app.on('activate', this.onAppActivate);\n }\n\n let trayImage =\n this._options.icon || path.join(this._options.dir, 'IconTemplate.png');\n if (typeof trayImage === 'string' && !fs.existsSync(trayImage)) {\n trayImage = path.join(__dirname, '..', 'assets', 'IconTemplate.png'); // Default cat icon\n }\n\n const trigger =\n this._options.trigger ??\n (this._options.showOnRightClick ? 'right-click' : 'click');\n\n this._tray = this._options.tray || new Tray(trayImage);\n // Type guards for TS not to complain\n if (!this.tray) {\n throw new Error('Tray has been initialized above');\n }\n if (trigger !== 'none') {\n this.tray.on(trigger as Parameters<Tray['on']>[0], this.clicked);\n this.tray.on('double-click', this.clicked);\n }\n // macOS-only: ignore double-click so an accidental second click doesn't\n // race the blur handler and cause a tray-icon flicker.\n if (\n process.platform === 'darwin' &&\n this._options.ignoreDoubleClickEvents\n ) {\n this.tray.setIgnoreDoubleClickEvents(true);\n }\n this.tray.setToolTip(this._options.tooltip);\n\n if (this._options.contextMenu) {\n this.bindContextMenu(this._options.contextMenu);\n }\n\n if (this._options.globalShortcut) {\n this.setGlobalShortcut(this._options.globalShortcut);\n }\n\n if (!this._options.windowPosition) {\n this._options.windowPosition = getWindowPosition(this.tray);\n }\n\n if (this._options.preloadWindow) {\n await this.createWindow();\n }\n\n this.emit('ready');\n }\n\n /**\n * Callback on tray icon click or double-click.\n *\n * @param e\n * @param bounds\n */\n private clicked = async (\n event?: Electron.KeyboardEvent,\n bounds?: Electron.Rectangle,\n ): Promise<void> => {\n if (event && (event.shiftKey || event.ctrlKey || event.metaKey)) {\n return this.hideWindow();\n }\n\n // if blur was invoked clear timeout\n if (this._blurTimeout) {\n clearInterval(this._blurTimeout);\n }\n\n if (this._browserWindow && this._isVisible) {\n return this.hideWindow();\n }\n\n this._cachedBounds = bounds || this._cachedBounds;\n await this.showWindow(this._cachedBounds);\n };\n\n private onAppActivate = (\n _event: Electron.Event,\n hasVisibleWindows: boolean,\n ): void => {\n if (!hasVisibleWindows) {\n this.showWindow().catch(console.error);\n }\n };\n\n /**\n * Marks the app as shutting down so `hideOnClose` stops intercepting closes.\n *\n * Bound to both `app`'s `before-quit` and the auto updater's\n * `before-quit-for-update`. Installing an update never emits `before-quit`:\n * Electron closes every window first and only quits once the window list is\n * empty, so a `hideOnClose` veto there would leave the window open and the\n * install waiting forever.\n */\n private onBeforeQuit = (): void => {\n this._isQuitting = true;\n };\n\n private bindContextMenu(menu: Menu): void {\n this._contextMenu = menu;\n if (process.platform === 'linux') {\n // libappindicator / StatusNotifierItem requires the menu to live on the\n // tray itself; right-click is handled by the desktop environment.\n this.tray.setContextMenu(menu);\n return;\n }\n this.bindRightClickContextMenu();\n }\n\n private bindRightClickContextMenu(): void {\n // macOS / Windows: pop up the current menu on right-click so left-click\n // stays bound to toggling the menubar window. Read `this._contextMenu`\n // at invoke time so `setContextMenu()` swaps and clears take effect\n // without rebinding (and without leaking a stale closure reference).\n this.tray.on('right-click', (_event, bounds) => {\n const current = this._contextMenu;\n if (!current) {\n return;\n }\n this.tray.popUpContextMenu(current, { x: bounds.x, y: bounds.y });\n });\n this._rightClickContextMenuBound = true;\n }\n\n private onAppReady = (): void => {\n // Guard against `destroy()` being called between construction and the\n // scheduled `process.nextTick`/`'ready'` firing.\n if (this._isDestroyed) {\n return;\n }\n this.appReady().catch((err) => console.error('menubar: ', err));\n };\n\n private async createWindow(): Promise<void> {\n this.emit('create-window');\n\n // We add some default behavior for menubar's browserWindow, to make it\n // look like a menubar\n const defaults = {\n show: false, // Don't show it at first\n frame: false, // Remove window frame\n };\n\n this._browserWindow = new BrowserWindow({\n ...defaults,\n ...this._options.browserWindow,\n });\n\n this._positioner = new Positioner(this._browserWindow);\n\n this._browserWindow.on('blur', () => {\n if (!this._browserWindow) {\n return;\n }\n\n // Preserve the legacy pin behavior unless the host explicitly separates\n // click-away dismissal from the window's stacking level.\n const hideOnBlur =\n this._options.hideOnBlur ?? !this._browserWindow.isAlwaysOnTop();\n if (!hideOnBlur) {\n this.emit('focus-lost');\n return;\n }\n\n // Windows foreground-activation race: clicking the tray icon keeps the\n // shell (explorer.exe) as the foreground process, so `show()` cannot pull\n // focus to the popup and Windows immediately fires `blur`. Left unguarded,\n // the hide timer below fires before the first paint and the window never\n // visibly appears (gitify-app/gitify#3064). Ignore blur events that land\n // within the grace window right after a show; a genuine click-away\n // arrives well after it.\n if (\n process.platform === 'win32' &&\n Date.now() - this._lastShowTime < BLUR_HIDE_GRACE_MS\n ) {\n return;\n }\n\n this._blurTimeout = setTimeout(() => {\n this.hideWindow();\n }, 100);\n });\n\n if (this._options.showOnAllWorkspaces !== false) {\n // https://github.com/electron/electron/issues/37832#issuecomment-1497882944\n this._browserWindow.setVisibleOnAllWorkspaces(true, {\n // Maps to NSWindowCollectionBehaviorFullScreenAuxiliary, which\n // Electron clears when the flag is omitted. Without it the popup\n // cannot appear inside a fullscreen space, so macOS switches to\n // another space to show it.\n visibleOnFullScreen: true,\n skipTransformProcessType: true, // Avoid damaging the original visible state of app.dock\n });\n }\n\n if (this._options.hideOnClose) {\n this._browserWindow.on('close', (event) => {\n if (this._isDestroyed || this._isQuitting) {\n return;\n }\n event.preventDefault();\n // Defer the hide for Wayland: hiding synchronously from the `close`\n // handler can leave frameless surfaces in a half-closed state.\n setImmediate(() => this.hideWindow());\n });\n }\n\n if (this._options.escapeToHide) {\n this._browserWindow.webContents.on(\n 'before-input-event',\n (_event, input) => {\n if (input.type === 'keyDown' && input.key === 'Escape') {\n this.hideWindow();\n }\n },\n );\n }\n\n // Use `closed` (not `close`) so consumer `close` listeners can still read\n // `mb.window` and call `event.preventDefault()` without racing our cleanup.\n this._browserWindow.on('closed', this.windowClear.bind(this));\n\n // Re-anchor the window to the tray when its size changes (e.g. via\n // `mb.window.setSize(...)`), so the window doesn't end up clipped under\n // the taskbar. https://github.com/maxogden/menubar/issues/349\n this._browserWindow.on('resize', this.positionWindow);\n\n this.emit('before-load');\n\n // If the user explicity set options.index to false, we don't loadURL\n // https://github.com/maxogden/menubar/issues/255\n if (this._options.index !== false) {\n await this._browserWindow.loadURL(\n this._options.index,\n this._options.loadUrlOptions,\n );\n }\n this.emit('after-create-window');\n }\n\n private windowClear(): void {\n this._browserWindow = undefined;\n this.emit('after-close');\n }\n}\n","/**\n * Entry point of menubar\n * @example\n * ```typescript\n * import { menubar } from 'menubar';\n * ```\n */\n\n/** */\n\nimport { app } from 'electron';\n\nimport { Menubar } from './Menubar';\nimport type { Options } from './types';\n\nexport * from './util/getWindowPosition';\nexport { Menubar };\n\n/**\n * Factory function to create a menubar application\n *\n * @param options - Options for creating a menubar application, see\n * {@link Options}\n */\nexport function menubar(options?: Partial<Options>): Menubar {\n return new Menubar(app, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,aAAb,MAAwB;CACtB;CAEA,YAAY,eAA8B;EACxC,KAAK,gBAAgB;CACvB;CAEA,UACE,UACA,YAC0B;EAC1B,IAAI,CAAC,UACH,MAAM,IAAI,UACR,0DACF;EAGF,MAAM,aAAa,aACfA,SAAAA,OAAO,mBAAmB,UAAU,CAAC,CAAC,WACtCA,SAAAA,OAAO,uBAAuBA,SAAAA,OAAO,qBAAqB,CAAC,CAAC,CAAC;EACjE,MAAM,CAAC,aAAa,gBAAgB,KAAK,cAAc,QAAQ;EAC/D,MAAM,QAAQ,YAAY,KAAK;EAC/B,MAAM,YAAY,YAAY,SAAS;EAEvC,MAAM,YAA8D;GAClE,UAAU;IACR,GAAG,KAAK,MAAM,KAAK;IACnB,GAAG,WAAW;GAChB;GACA,gBAAgB;IACd,GAAG,KAAK,MAAM,KAAK;IACnB,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,WAAW;IACT,GAAG,KAAK,MAAM,QAAQ,cAAc,SAAS;IAC7C,GAAG,WAAW;GAChB;GACA,iBAAiB;IACf,GAAG,KAAK,MAAM,QAAQ,cAAc,SAAS;IAC7C,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,YAAY;IACV,GAAG,KAAK,MAAM,QAAQ,cAAc,IAAI,YAAY,CAAC;IACrD,GAAG,WAAW;GAChB;GACA,kBAAkB;IAChB,GAAG,KAAK,MAAM,QAAQ,cAAc,IAAI,YAAY,CAAC;IACrD,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,SAAS;IACP,GAAG,WAAW;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rB,0BAA0B;EAC5B,CAAC;EAGH,IAAI,KAAK,SAAS,aAChB,KAAK,eAAe,GAAG,UAAU,UAAU;GACzC,IAAI,KAAK,gBAAgB,KAAK,aAC5B;GAEF,MAAM,eAAe;GAGrB,mBAAmB,KAAK,WAAW,CAAC;EACtC,CAAC;EAGH,IAAI,KAAK,SAAS,cAChB,KAAK,eAAe,YAAY,GAC9B,uBACC,QAAQ,UAAU;GACjB,IAAI,MAAM,SAAS,aAAa,MAAM,QAAQ,UAC5C,KAAK,WAAW;EAEpB,CACF;EAKF,KAAK,eAAe,GAAG,UAAU,KAAK,YAAY,KAAK,IAAI,CAAC;EAK5D,KAAK,eAAe,GAAG,UAAU,KAAK,cAAc;EAEpD,KAAK,KAAK,aAAa;EAIvB,IAAI,KAAK,SAAS,UAAU,OAC1B,MAAM,KAAK,eAAe,QACxB,KAAK,SAAS,OACd,KAAK,SAAS,cAChB;EAEF,KAAK,KAAK,qBAAqB;CACjC;CAEA,cAA4B;EAC1B,KAAK,iBAAiB,KAAA;EACtB,KAAK,KAAK,aAAa;CACzB;AACF;;;;;;;;;;;;;;;;;ACprBA,SAAgB,QAAQ,SAAqC;CAC3D,OAAO,IAAI,QAAQC,SAAAA,KAAK,OAAO;AACjC"}
1
+ {"version":3,"file":"index.cjs","names":["screen","app","path","url","electronScreen","EventEmitter","globalShortcut","path","fs","Tray","BrowserWindow","app"],"sources":["../src/Positioner.ts","../src/util/cleanOptions.ts","../src/util/getWindowPosition.ts","../src/Menubar.ts","../src/index.ts"],"sourcesContent":["import { type BrowserWindow, type Rectangle, screen } from 'electron';\n\n/**\n * Named anchor points for placing the menubar window. The `tray*` values are\n * relative to the tray icon's bounds; the rest are relative to the work area\n * of the display containing the cursor (or the tray, when bounds are given).\n */\nexport type WindowPosition =\n | 'trayLeft'\n | 'trayBottomLeft'\n | 'trayRight'\n | 'trayBottomRight'\n | 'trayCenter'\n | 'trayBottomCenter'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'topCenter'\n | 'bottomCenter'\n | 'leftCenter'\n | 'rightCenter'\n | 'center';\n\n/**\n * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named\n * position, optionally relative to a tray icon's bounds. Ported from\n * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency.\n */\nexport class Positioner {\n private readonly browserWindow: BrowserWindow;\n\n constructor(browserWindow: BrowserWindow) {\n this.browserWindow = browserWindow;\n }\n\n calculate(\n position?: WindowPosition,\n trayBounds?: Rectangle,\n ): { x: number; y: number } {\n if (!position) {\n throw new TypeError(\n 'Positioner.calculate: a `position` argument is required.',\n );\n }\n\n const screenSize = trayBounds\n ? screen.getDisplayMatching(trayBounds).workArea\n : screen.getDisplayNearestPoint(screen.getCursorScreenPoint()).workArea;\n const [windowWidth, windowHeight] = this.browserWindow.getSize();\n const trayX = trayBounds?.x ?? Number.NaN;\n const trayWidth = trayBounds?.width ?? Number.NaN;\n\n const positions: Record<WindowPosition, { x: number; y: number }> = {\n trayLeft: {\n x: Math.floor(trayX),\n y: screenSize.y,\n },\n trayBottomLeft: {\n x: Math.floor(trayX),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: screenSize.y,\n },\n trayBottomRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: screenSize.y,\n },\n trayBottomCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topLeft: {\n x: screenSize.x,\n y: screenSize.y,\n },\n topRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: screenSize.y,\n },\n bottomLeft: {\n x: screenSize.x,\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n bottomRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: screenSize.y,\n },\n bottomCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n leftCenter: {\n x: screenSize.x,\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n rightCenter: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n center: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(\n (screenSize.height + screenSize.y) / 2 - windowHeight / 2,\n ),\n },\n };\n\n const coords = positions[position];\n\n // On Windows, a tray-relative position can push the window past the right\n // edge of the work area. Snap back to `topRight` x in that case so it stays\n // visible. See https://github.com/jenslind/electron-positioner.\n if (position.startsWith('tray')) {\n if (coords.x + windowWidth > screenSize.width + screenSize.x) {\n return { x: positions.topRight.x, y: coords.y };\n }\n }\n\n return coords;\n }\n}\n","/**\n * @ignore\n */\n\n/** */\n\nimport path from 'node:path';\nimport url from 'node:url';\n\nimport { app } from 'electron';\n\nimport type { Options } from '../types';\n\nconst DEFAULT_WINDOW_HEIGHT = 400;\nconst DEFAULT_WINDOW_WIDTH = 400;\n\n/**\n * Take as input some options, and return a sanitized version of it.\n *\n * @param opts - The options to clean.\n * @ignore\n */\nexport function cleanOptions(opts?: Partial<Options>): Options {\n const options: Partial<Options> = { ...opts };\n\n if (options.activateWithApp === undefined) {\n options.activateWithApp = true;\n }\n if (options.ignoreDoubleClickEvents === undefined) {\n options.ignoreDoubleClickEvents = true;\n }\n if (!options.dir) {\n options.dir = app.getAppPath();\n }\n if (!path.isAbsolute(options.dir)) {\n options.dir = path.resolve(options.dir);\n }\n // Note: options.index can be `false`\n if (options.index === undefined) {\n options.index = url.format({\n pathname: path.join(options.dir, 'index.html'),\n protocol: 'file:',\n slashes: true,\n });\n }\n options.loadUrlOptions = options.loadUrlOptions || {};\n\n options.tooltip = options.tooltip || '';\n\n // `icon`, `preloadWindow`, `showDockIcon`, `showOnAllWorkspaces`,\n // `showOnRightClick` don't need any special treatment\n\n // Now we take care of `browserWindow`\n if (!options.browserWindow) {\n options.browserWindow = {};\n }\n\n // Set width/height on options to be usable before the window is created\n options.browserWindow.width =\n // Note: not using `options.browserWindow.width || DEFAULT_WINDOW_WIDTH` so\n // that users can put a 0 width\n options.browserWindow.width !== undefined\n ? options.browserWindow.width\n : DEFAULT_WINDOW_WIDTH;\n options.browserWindow.height =\n options.browserWindow.height !== undefined\n ? options.browserWindow.height\n : DEFAULT_WINDOW_HEIGHT;\n\n return options as Options;\n}\n","/**\n * Utilities to get taskbar position and consequently menubar's position\n */\n\n/** */\n\nimport { screen as electronScreen, type Rectangle, type Tray } from 'electron';\n\nconst isLinux = process.platform === 'linux';\n\nconst trayToScreenRects = (trayBounds: Rectangle): [Rectangle, Rectangle] => {\n // There may be more than one screen, so we need to figure out on which screen our tray icon lives.\n const { workArea, bounds: screenBounds } =\n electronScreen.getDisplayMatching(trayBounds);\n\n return [\n screenBounds,\n {\n ...workArea,\n x: workArea.x - screenBounds.x,\n y: workArea.y - screenBounds.y,\n },\n ];\n};\n\ntype TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';\n\n/**\n * Determine taskbard location: \"top\", \"bottom\", \"left\" or \"right\".\n *\n * Only tested on Windows for now, and only used in Windows.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function taskbarLocation(tray: Tray): TaskbarLocation {\n const trayBounds = tray.getBounds();\n const [screenBounds, workArea] = trayToScreenRects(trayBounds);\n\n if (\n process.platform === 'win32' &&\n trayBounds.width > 0 &&\n trayBounds.height > 0\n ) {\n // Other appbars also reserve work-area space. The tray's nearest display\n // edge identifies the taskbar without mistaking a PowerToys dock for it.\n const x = trayBounds.x + trayBounds.width / 2 - screenBounds.x;\n const y = trayBounds.y + trayBounds.height / 2 - screenBounds.y;\n const insets: Record<TaskbarLocation, number> = {\n top: workArea.y,\n bottom: screenBounds.height - workArea.y - workArea.height,\n left: workArea.x,\n right: screenBounds.width - workArea.x - workArea.width,\n };\n let nearest: [TaskbarLocation, number] = [\n 'bottom',\n Math.abs(screenBounds.height - y),\n ];\n const edges: [TaskbarLocation, number][] = [\n ['top', Math.abs(y)],\n ['left', Math.abs(x)],\n ['right', Math.abs(screenBounds.width - x)],\n ];\n for (const edge of edges) {\n // At a corner, prefer the edge that actually reserves work-area space.\n if (\n edge[1] < nearest[1] ||\n (edge[1] === nearest[1] && insets[edge[0]] > insets[nearest[0]])\n )\n nearest = edge;\n }\n return nearest[0];\n }\n\n // TASKBAR LEFT\n if (workArea.x > 0) {\n // Most likely Ubuntu hence assuming the window should be on top\n if (isLinux && workArea.y > 0) return 'top';\n // The workspace starts more on the right\n return 'left';\n }\n\n // TASKBAR TOP\n if (workArea.y > 0) {\n return 'top';\n }\n\n // TASKBAR RIGHT\n // Here both workArea.y and workArea.x are 0 so we can no longer leverage them.\n // We can use the workarea and display width though.\n // Determine taskbar location\n if (workArea.width < screenBounds.width) {\n // The taskbar is either on the left or right, but since the LEFT case was handled above,\n // we can be sure we're dealing with a right taskbar\n return 'right';\n }\n\n // TASKBAR BOTTOM\n // Since all the other cases were handled, we can be sure we're dealing with a bottom taskbar\n return 'bottom';\n}\n\ntype WindowPosition =\n | 'trayCenter'\n | 'topRight'\n | 'trayBottomCenter'\n | 'leftCenter'\n | 'bottomRight';\n\n/**\n * Depending on where the taskbar is, determine where the window should be\n * positioned.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function getWindowPosition(tray: Tray): WindowPosition {\n switch (process.platform) {\n // macOS\n // Supports top taskbars\n case 'darwin':\n return 'trayCenter';\n // Linux\n // Windows\n // Supports top/bottom/left/right taskbar\n case 'linux':\n case 'win32': {\n const traySide = taskbarLocation(tray);\n\n // Assign position for menubar\n if (traySide === 'top') {\n return isLinux ? 'topRight' : 'trayCenter';\n }\n if (traySide === 'bottom') {\n return 'bottomRight';\n }\n if (traySide === 'left') {\n // Vertically centered against the left edge of the work area.\n // `bottomLeft` would put the window in the screen's bottom-left\n // corner — visually disconnected from the tray icon, which sits\n // somewhere on the left strip. Tray-anchored y isn't available\n // through `Positioner` for side taskbars, so center is the best\n // compromise that stays close to the tray.\n return 'leftCenter';\n }\n if (traySide === 'right') {\n return 'bottomRight';\n }\n }\n }\n\n // When we really don't know, we just show the menubar on the top-right\n return 'topRight';\n}\n","import { EventEmitter } from 'node:events';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n autoUpdater,\n BrowserWindow,\n globalShortcut,\n type Menu,\n Tray,\n} from 'electron';\n\nimport { Positioner } from './Positioner';\nimport type { Options } from './types';\nimport { cleanOptions } from './util/cleanOptions';\nimport { getWindowPosition } from './util/getWindowPosition';\n\n/**\n * Grace period after `showWindow()` during which a `blur` on the popup is\n * treated as the spurious Windows post-show blur and ignored instead of\n * triggering the auto-hide. See the `blur` handler in {@link Menubar.createWindow}.\n */\nconst BLUR_HIDE_GRACE_MS = 400;\n\n/**\n * Delay before re-asserting the hidden dock after startup. macOS can silently\n * drop an `app.dock.hide()` that races the app's launch activation\n * transition, leaving the dock icon stuck for the whole session. See the\n * re-check in {@link Menubar.appReady}.\n */\nconst DOCK_REHIDE_DELAY_MS = 2_000;\n\n/**\n * The main Menubar class.\n */\nexport class Menubar extends EventEmitter {\n private _app: Electron.App;\n private _browserWindow?: BrowserWindow;\n private _contextMenu?: Menu;\n private _blurTimeout: NodeJS.Timeout | null = null; // track blur events with timeout\n private _isDestroyed: boolean;\n private _isQuitting: boolean; // set when the app is shutting down, used by hideOnClose\n private _isVisible: boolean; // track visibility\n private _cachedBounds?: Electron.Rectangle; // _cachedBounds are needed for double-clicked event\n private _options: Options;\n private _positioner: Positioner | undefined;\n private _shortcut?: Electron.Accelerator;\n private _rightClickContextMenuBound = false;\n private _warnedNoPositioning = false; // guards the one-time Wayland warning\n private _lastShowTime = 0; // timestamp of last show(), debounces the post-show blur on Windows\n private _dockRehideTimeout?: NodeJS.Timeout; // pending post-startup dock re-hide check\n private _repositioning = false; // guards against re-entrant positionWindow calls\n private _showOnAllWorkspaces = false; // `showOnAllWorkspaces` as read when the window was created\n private _tray?: Tray;\n\n constructor(app: Electron.App, options?: Partial<Options>) {\n super();\n this._app = app;\n this._options = cleanOptions(options);\n this._isDestroyed = false;\n this._isQuitting = false;\n this._isVisible = false;\n\n app.on('before-quit', this.onBeforeQuit);\n autoUpdater.on('before-quit-for-update', this.onBeforeQuit);\n\n if (app.isReady()) {\n // See https://github.com/maxogden/menubar/pull/151\n process.nextTick(this.onAppReady);\n } else {\n app.on('ready', this.onAppReady);\n }\n }\n\n /**\n * The Electron [App](https://electronjs.org/docs/api/app)\n * instance.\n */\n get app(): Electron.App {\n return this._app;\n }\n\n /**\n * The {@link Positioner} instance used to compute where the menubar window\n * should appear on screen. Available after the `after-create-window` event.\n */\n get positioner(): Positioner {\n if (!this._positioner) {\n throw new Error(\n 'Please access `this.positioner` after the `after-create-window` event has fired.',\n );\n }\n\n return this._positioner;\n }\n\n /**\n * The Electron [Tray](https://electronjs.org/docs/api/tray) instance.\n */\n get tray(): Tray {\n if (!this._tray) {\n throw new Error(\n 'Please access `this.tray` after the `ready` event has fired.',\n );\n }\n\n return this._tray;\n }\n\n /**\n * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)\n * instance, if it's present.\n */\n get window(): BrowserWindow | undefined {\n return this._browserWindow;\n }\n\n /**\n * Tear down the menubar instance: destroy the window, remove the tray, and\n * detach all listeners. Subsequent clicks on the tray will be no-ops until a\n * new {@link Menubar} instance is created.\n */\n destroy(): void {\n if (this.isDestroyed()) {\n return;\n }\n // Set first so `hideOnClose` lets the close go through instead of\n // intercepting it.\n this._isDestroyed = true;\n\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n\n if (this._dockRehideTimeout) {\n clearTimeout(this._dockRehideTimeout);\n this._dockRehideTimeout = undefined;\n }\n\n if (this._browserWindow) {\n this._browserWindow.destroy();\n this._browserWindow = undefined;\n }\n\n if (this._tray) {\n // Ensure all potential listeners are removed.\n for (const event of ['click', 'right-click', 'double-click']) {\n this._tray.removeListener(\n event as Parameters<Tray['on']>[0],\n this.clicked,\n );\n }\n this._tray.setToolTip('');\n this._tray = undefined;\n }\n\n this._app.removeListener('ready', this.onAppReady);\n this._app.removeListener('activate', this.onAppActivate);\n this._app.removeListener('before-quit', this.onBeforeQuit);\n autoUpdater.removeListener('before-quit-for-update', this.onBeforeQuit);\n }\n\n /**\n * Whether {@link destroy} has been called on this menubar instance.\n */\n isDestroyed(): boolean {\n return this._isDestroyed;\n }\n\n /**\n * Retrieve a menubar option.\n *\n * @param key - The option key to retrieve, see {@link Options}.\n */\n getOption<K extends keyof Options>(key: K): Options[K] {\n return this._options[key];\n }\n\n /**\n * Hide the menubar window.\n */\n hideWindow(): void {\n if (!this._browserWindow || !this._isVisible) {\n return;\n }\n this.emit('hide');\n this._browserWindow.hide();\n if (process.platform === 'darwin') {\n this.applyWorkspaceVisibility(false);\n }\n this.emit('after-hide');\n this._isVisible = false;\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n this._blurTimeout = null;\n }\n this.refreshContextMenu();\n }\n\n /**\n * Register a global keyboard accelerator that toggles the menubar window.\n * Replaces any previously registered shortcut owned by this Menubar.\n * Pass `undefined` to clear the current shortcut without registering a new\n * one. Returns whether the registration succeeded.\n *\n * @param accelerator - An Electron\n * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or\n * `undefined` to clear.\n */\n setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean {\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n this._options.globalShortcut = accelerator;\n if (!accelerator) {\n return true;\n }\n const ok = globalShortcut.register(accelerator, () => this.toggleWindow());\n if (ok) {\n this._shortcut = accelerator;\n }\n return ok;\n }\n\n /**\n * Toggle the menubar window: hide it if visible, show it otherwise.\n * Resolves once the window finishes showing or hiding.\n */\n async toggleWindow(): Promise<void> {\n if (this._browserWindow && this._isVisible) {\n this.hideWindow();\n return;\n }\n await this.showWindow();\n }\n\n /**\n * Re-center the menubar window over the tray icon. Convenience wrapper for\n * `positioner.move('trayCenter', tray.getBounds())` that's safe to call\n * after the `after-create-window` event. No-op if the window doesn't\n * exist yet.\n */\n recenterOnTray(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n const bounds = this._tray.getBounds();\n const { x, y } = this.positioner.calculate('trayCenter', bounds);\n this._browserWindow.setPosition(Math.round(x), Math.round(y));\n }\n\n /**\n * Replace the tray context menu after construction. On Linux this also\n * re-publishes the menu to the SNI host, which is required after mutating\n * items in-place since libappindicator caches the previous serialization.\n * On macOS/Windows the right-click popup handler reads the current menu\n * reference, so swapping or clearing here takes effect immediately.\n *\n * @param menu - The new menu, or `null` to clear it.\n */\n setContextMenu(menu: Menu | null): void {\n this._contextMenu = menu ?? undefined;\n this._options.contextMenu = menu ?? undefined;\n if (!this._tray) {\n return;\n }\n if (process.platform === 'linux') {\n // `setContextMenu(null)` clears the menu on Linux.\n this._tray.setContextMenu(menu);\n return;\n }\n // macOS / Windows: bind the right-click popup once on first non-empty\n // assignment. The handler reads `this._contextMenu` at invoke time, so\n // later swaps and clears take effect without rebinding (and never leak\n // a stale closure reference).\n if (menu && !this._rightClickContextMenuBound) {\n this.bindRightClickContextMenu();\n }\n }\n\n /**\n * Re-publish the current context menu so in-place mutations of its items\n * (`visible`, `enabled`, `checked`, `label`) become visible to the user.\n *\n * Only Linux needs this: libappindicator / StatusNotifierItem serializes the\n * menu once and serves that copy until it is set again, so a mutated item\n * would otherwise keep rendering its old state until the next show or hide.\n * A no-op on macOS and Windows, where the menu is read at popup time — call\n * it unconditionally after mutating items.\n */\n refreshContextMenu(): void {\n if (\n process.platform === 'linux' &&\n this._contextMenu &&\n this._tray &&\n !this._tray.isDestroyed?.()\n ) {\n this._tray.setContextMenu(this._contextMenu);\n }\n }\n\n /**\n * Change an option after menubar is created.\n *\n * @param key - The option key to modify, see {@link Options}.\n * @param value - The value to set.\n */\n setOption<K extends keyof Options>(key: K, value: Options[K]): void {\n this._options[key] = value;\n if (key === 'hideOnBlur' || key === 'browserWindow') {\n this.applyWindowFocusBehavior();\n }\n }\n\n private shouldHideOnBlur(): boolean {\n const win = this._browserWindow;\n return (\n !!win &&\n !win.isDestroyed() &&\n this._options.hideOnBlur !== false &&\n !win.webContents.isDevToolsOpened()\n );\n }\n\n private applyWindowFocusBehavior(): void {\n const win = this._browserWindow;\n if (!win || win.isDestroyed()) {\n return;\n }\n\n const keepOpen = !this.shouldHideOnBlur();\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n this._blurTimeout = null;\n }\n\n if (process.platform === 'win32') {\n win.setAlwaysOnTop(true, 'pop-up-menu');\n } else {\n win.setAlwaysOnTop(\n keepOpen || this._options.browserWindow.alwaysOnTop === true,\n );\n }\n }\n\n /**\n * Show the menubar window.\n *\n * @param trayPos - The bounds to show the window in.\n */\n async showWindow(trayPos?: Electron.Rectangle): Promise<void> {\n if (!this.tray) {\n throw new Error('Tray should have been instantiated by now');\n }\n\n if (!this._browserWindow) {\n await this.createWindow();\n }\n\n // Use guard for TypeScript, to avoid ! everywhere\n if (!this._browserWindow) {\n throw new Error('Window has been initialized just above. qed.');\n }\n\n this.emit('show');\n\n // Cache fresh tray bounds (or fall back to existing cache / tray bounds)\n // so `positionWindow` can reposition without an event payload — for\n // example when the window resizes via `setSize`.\n if (trayPos && trayPos.x !== 0) {\n this._cachedBounds = trayPos;\n } else if (!this._cachedBounds && this.tray.getBounds) {\n this._cachedBounds = this.tray.getBounds();\n }\n\n if (process.platform === 'darwin') {\n this.applyWorkspaceVisibility(true);\n }\n this.positionWindow();\n // Record the show time before `show()` so the blur handler can recognise\n // and ignore the transient blur Windows fires right after (see below).\n this.applyWindowFocusBehavior();\n this._lastShowTime = Date.now();\n this._browserWindow.show();\n this._isVisible = true;\n this.emit('after-show');\n this.refreshContextMenu();\n }\n\n /**\n * Compute and apply the tray-anchored position of the browser window. Safe\n * to call any time after `createWindow` has run — invoked from\n * {@link showWindow} on every show, and from the window's `resize` event so\n * `setSize` calls reposition the window correctly.\n */\n private positionWindow = (): void => {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // `setPosition` below can make Windows emit `resize` synchronously, which\n // re-enters this method through the window's `resize` listener. Each pass\n // nudges the window again, so the recursion never unwinds: the main\n // process wedges with the event loop blocked and the window grows past\n // screen size (gitify-app/gitify#3064). Ignore re-entrant calls; the\n // outermost one already applies the final position.\n if (this._repositioning) {\n return;\n }\n this._repositioning = true;\n try {\n this.applyWindowPosition();\n } finally {\n this._repositioning = false;\n }\n };\n\n /**\n * Compute and apply the tray-anchored position. Always call through\n * {@link positionWindow}, which guards against re-entrancy.\n */\n private applyWindowPosition(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // 'Windows' taskbar: sync window position each time before positioning.\n // https://github.com/maxogden/menubar/issues/232\n if (['win32', 'linux'].includes(process.platform)) {\n this._options.windowPosition = getWindowPosition(this._tray);\n }\n\n const trayPos = this._cachedBounds ?? this._tray.getBounds?.();\n\n // Default the window to the right if `trayPos` bounds are undefined or null.\n let noBoundsPosition: Options['windowPosition'];\n if (\n (trayPos === undefined || trayPos.x === 0) &&\n this._options.windowPosition?.startsWith('tray')\n ) {\n noBoundsPosition =\n process.platform === 'win32' ? 'bottomRight' : 'topRight';\n }\n\n const position = this.positioner.calculate(\n this._options.windowPosition || noBoundsPosition,\n trayPos,\n ) as { x: number; y: number };\n\n // Not using `||` because x and y can be zero.\n const x =\n this._options.browserWindow.x !== undefined\n ? this._options.browserWindow.x\n : position.x;\n const y =\n this._options.browserWindow.y !== undefined\n ? this._options.browserWindow.y\n : position.y;\n\n // `.setPosition` crashed on non-integers\n // https://github.com/maxogden/menubar/issues/233\n const targetX = Math.round(x);\n const targetY = Math.round(y);\n this._browserWindow.setPosition(targetX, targetY);\n\n // Native Wayland gives an application no way to position its own window:\n // `setPosition` is a no-op and `getPosition` reads back [0, 0]\n // (https://github.com/electron/electron/issues/40886). The compositor\n // decides where the window lands, usually centered, so the popover can't\n // be anchored to the tray. Detect that the move didn't take and warn once,\n // pointing at the X11 fallback. Gated on a Wayland session (`WAYLAND_DISPLAY`)\n // so pure X11 never trips it; the tolerance absorbs the few-pixel offsets\n // X11 window managers add for decorations, so XWayland (where positioning\n // works) doesn't trip it either.\n if (\n process.platform === 'linux' &&\n !!process.env.WAYLAND_DISPLAY &&\n !this._warnedNoPositioning\n ) {\n const [actualX, actualY] = this._browserWindow.getPosition();\n const ignored =\n Math.abs(actualX - targetX) > 24 || Math.abs(actualY - targetY) > 24;\n if (ignored) {\n this._warnedNoPositioning = true;\n console.warn(\n '[menubar] The window could not be positioned programmatically, ' +\n 'which is expected on native Wayland where the compositor controls ' +\n 'placement. The popover will not be anchored to the tray icon. Run ' +\n 'with --ozone-platform=x11 to restore tray-relative positioning.',\n );\n }\n }\n }\n\n private async appReady(): Promise<void> {\n if (this.app.dock && !this._options.showDockIcon) {\n this.app.dock.hide();\n\n // The hide above can be silently dropped when it races the launch\n // activation transition. Re-check once startup has settled; guarded on\n // visibility because `dock.hide()` also deactivates the app, so it must\n // not run when the dock is already hidden.\n this._dockRehideTimeout = setTimeout(() => {\n if (!this._isDestroyed && this.app.dock?.isVisible()) {\n this.app.dock.hide();\n }\n }, DOCK_REHIDE_DELAY_MS);\n }\n\n if (this._options.activateWithApp) {\n this.app.on('activate', this.onAppActivate);\n }\n\n let trayImage =\n this._options.icon || path.join(this._options.dir, 'IconTemplate.png');\n if (typeof trayImage === 'string' && !fs.existsSync(trayImage)) {\n trayImage = path.join(__dirname, '..', 'assets', 'IconTemplate.png'); // Default cat icon\n }\n\n const trigger =\n this._options.trigger ??\n (this._options.showOnRightClick ? 'right-click' : 'click');\n\n this._tray = this._options.tray || new Tray(trayImage);\n // Type guards for TS not to complain\n if (!this.tray) {\n throw new Error('Tray has been initialized above');\n }\n if (trigger !== 'none') {\n this.tray.on(trigger as Parameters<Tray['on']>[0], this.clicked);\n this.tray.on('double-click', this.clicked);\n }\n // macOS-only: ignore double-click so an accidental second click doesn't\n // race the blur handler and cause a tray-icon flicker.\n if (\n process.platform === 'darwin' &&\n this._options.ignoreDoubleClickEvents\n ) {\n this.tray.setIgnoreDoubleClickEvents(true);\n }\n this.tray.setToolTip(this._options.tooltip);\n\n if (this._options.contextMenu) {\n this.bindContextMenu(this._options.contextMenu);\n }\n\n if (this._options.globalShortcut) {\n this.setGlobalShortcut(this._options.globalShortcut);\n }\n\n if (!this._options.windowPosition) {\n this._options.windowPosition = getWindowPosition(this.tray);\n }\n\n if (this._options.preloadWindow) {\n await this.createWindow();\n }\n\n this.emit('ready');\n }\n\n /**\n * Callback on tray icon click or double-click.\n *\n * @param e\n * @param bounds\n */\n private clicked = async (\n event?: Electron.KeyboardEvent,\n bounds?: Electron.Rectangle,\n ): Promise<void> => {\n if (event && (event.shiftKey || event.ctrlKey || event.metaKey)) {\n return this.hideWindow();\n }\n\n // if blur was invoked clear timeout\n if (this._blurTimeout) {\n clearInterval(this._blurTimeout);\n }\n\n if (this._browserWindow && this._isVisible) {\n return this.hideWindow();\n }\n\n this._cachedBounds = bounds || this._cachedBounds;\n await this.showWindow(this._cachedBounds);\n };\n\n private onAppActivate = (\n _event: Electron.Event,\n hasVisibleWindows: boolean,\n ): void => {\n if (!hasVisibleWindows) {\n this.showWindow().catch(console.error);\n }\n };\n\n /**\n * Marks the app as shutting down so `hideOnClose` stops intercepting closes.\n *\n * Bound to both `app`'s `before-quit` and the auto updater's\n * `before-quit-for-update`. Installing an update never emits `before-quit`:\n * Electron closes every window first and only quits once the window list is\n * empty, so a `hideOnClose` veto there would leave the window open and the\n * install waiting forever.\n */\n private onBeforeQuit = (): void => {\n this._isQuitting = true;\n };\n\n private bindContextMenu(menu: Menu): void {\n this._contextMenu = menu;\n if (process.platform === 'linux') {\n // libappindicator / StatusNotifierItem requires the menu to live on the\n // tray itself; right-click is handled by the desktop environment.\n this.tray.setContextMenu(menu);\n return;\n }\n this.bindRightClickContextMenu();\n }\n\n private bindRightClickContextMenu(): void {\n // macOS / Windows: pop up the current menu on right-click so left-click\n // stays bound to toggling the menubar window. Read `this._contextMenu`\n // at invoke time so `setContextMenu()` swaps and clears take effect\n // without rebinding (and without leaking a stale closure reference).\n this.tray.on('right-click', (_event, bounds) => {\n const current = this._contextMenu;\n if (!current) {\n return;\n }\n this.tray.popUpContextMenu(current, { x: bounds.x, y: bounds.y });\n });\n this._rightClickContextMenuBound = true;\n }\n\n private onAppReady = (): void => {\n // Guard against `destroy()` being called between construction and the\n // scheduled `process.nextTick`/`'ready'` firing.\n if (this._isDestroyed) {\n return;\n }\n this.appReady().catch((err) => console.error('menubar: ', err));\n };\n\n private async createWindow(): Promise<void> {\n this.emit('create-window');\n\n // We add some default behavior for menubar's browserWindow, to make it\n // look like a menubar\n const defaults = {\n show: false, // Don't show it at first\n frame: false, // Remove window frame\n };\n\n this._browserWindow = new BrowserWindow({\n ...defaults,\n ...this._options.browserWindow,\n });\n\n this._positioner = new Positioner(this._browserWindow);\n\n this.applyWindowFocusBehavior();\n this._browserWindow.webContents.on('devtools-opened', () => {\n this.applyWindowFocusBehavior();\n });\n this._browserWindow.webContents.on('devtools-closed', () => {\n this.applyWindowFocusBehavior();\n });\n\n this._browserWindow.on('blur', () => {\n if (!this._browserWindow) {\n return;\n }\n\n if (!this.shouldHideOnBlur()) {\n this.emit('focus-lost');\n return;\n }\n\n // Windows foreground-activation race: clicking the tray icon keeps the\n // shell (explorer.exe) as the foreground process, so `show()` cannot pull\n // focus to the popup and Windows immediately fires `blur`. Left unguarded,\n // the hide timer below fires before the first paint and the window never\n // visibly appears (gitify-app/gitify#3064). Ignore blur events that land\n // within the grace window right after a show; a genuine click-away\n // arrives well after it.\n if (\n process.platform === 'win32' &&\n Date.now() - this._lastShowTime < BLUR_HIDE_GRACE_MS\n ) {\n return;\n }\n\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n }\n this._blurTimeout = setTimeout(() => {\n this._blurTimeout = null;\n if (this.shouldHideOnBlur()) {\n this.hideWindow();\n }\n }, 100);\n });\n\n this._showOnAllWorkspaces = this._options.showOnAllWorkspaces !== false;\n this.applyWorkspaceVisibility(true);\n\n if (this._options.hideOnClose) {\n this._browserWindow.on('close', (event) => {\n if (this._isDestroyed || this._isQuitting) {\n return;\n }\n event.preventDefault();\n // Defer the hide for Wayland: hiding synchronously from the `close`\n // handler can leave frameless surfaces in a half-closed state.\n setImmediate(() => this.hideWindow());\n });\n }\n\n if (this._options.escapeToHide) {\n this._browserWindow.webContents.on(\n 'before-input-event',\n (_event, input) => {\n if (input.type === 'keyDown' && input.key === 'Escape') {\n this.hideWindow();\n }\n },\n );\n }\n\n // Use `closed` (not `close`) so consumer `close` listeners can still read\n // `mb.window` and call `event.preventDefault()` without racing our cleanup.\n this._browserWindow.on('closed', this.windowClear.bind(this));\n\n // Re-anchor the window to the tray when its size changes (e.g. via\n // `mb.window.setSize(...)`), so the window doesn't end up clipped under\n // the taskbar. https://github.com/maxogden/menubar/issues/349\n this._browserWindow.on('resize', this.positionWindow);\n\n this.emit('before-load');\n\n // If the user explicity set options.index to false, we don't loadURL\n // https://github.com/maxogden/menubar/issues/255\n if (this._options.index !== false) {\n await this._browserWindow.loadURL(\n this._options.index,\n this._options.loadUrlOptions,\n );\n }\n this.emit('after-create-window');\n }\n\n /**\n * Join or leave every workspace when `showOnAllWorkspaces` is enabled.\n *\n * On macOS the hidden popup leaves every Space in {@link hideWindow} and\n * rejoins them right before `show()` in {@link showWindow}. macOS can drop\n * a hidden window from all but one Space while `isVisibleOnAllWorkspaces()`\n * still reports `true`, e.g. when the fullscreen Space the popup was last\n * shown on closes. Showing it then switches to that one Space, and setting\n * the flag again to the value it already has does not re-add the window.\n * Clearing the flag while hidden makes the next show a real change, which\n * re-adds the window to every Space before it appears.\n */\n private applyWorkspaceVisibility(visible: boolean): void {\n if (\n !this._browserWindow ||\n this._browserWindow.isDestroyed() ||\n !this._showOnAllWorkspaces\n ) {\n return;\n }\n // https://github.com/electron/electron/issues/37832#issuecomment-1497882944\n this._browserWindow.setVisibleOnAllWorkspaces(visible, {\n // Maps to NSWindowCollectionBehaviorFullScreenAuxiliary, which\n // Electron clears when the flag is omitted. Without it the popup\n // cannot appear inside a fullscreen space, so macOS switches to\n // another space to show it.\n visibleOnFullScreen: visible,\n skipTransformProcessType: true, // Avoid damaging the original visible state of app.dock\n });\n }\n\n private windowClear(): void {\n this._browserWindow = undefined;\n this.emit('after-close');\n }\n}\n","/**\n * Entry point of menubar\n * @example\n * ```typescript\n * import { menubar } from 'menubar';\n * ```\n */\n\n/** */\n\nimport { app } from 'electron';\n\nimport { Menubar } from './Menubar';\nimport type { Options } from './types';\n\nexport * from './util/getWindowPosition';\nexport { Menubar };\n\n/**\n * Factory function to create a menubar application\n *\n * @param options - Options for creating a menubar application, see\n * {@link Options}\n */\nexport function menubar(options?: Partial<Options>): Menubar {\n return new Menubar(app, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,aAAb,MAAwB;CACtB;CAEA,YAAY,eAA8B;EACxC,KAAK,gBAAgB;CACvB;CAEA,UACE,UACA,YAC0B;EAC1B,IAAI,CAAC,UACH,MAAM,IAAI,UACR,0DACF;EAGF,MAAM,aAAa,aACfA,SAAAA,OAAO,mBAAmB,UAAU,CAAC,CAAC,WACtCA,SAAAA,OAAO,uBAAuBA,SAAAA,OAAO,qBAAqB,CAAC,CAAC,CAAC;EACjE,MAAM,CAAC,aAAa,gBAAgB,KAAK,cAAc,QAAQ;EAC/D,MAAM,QAAQ,YAAY,KAAK;EAC/B,MAAM,YAAY,YAAY,SAAS;EAEvC,MAA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12 @@ interface Options {
72
72
  */
73
73
  globalShortcut?: Electron.Accelerator;
74
74
  /**
75
- * Hide the window when it loses focus, independently of its stacking level.
76
- * When omitted, always-on-top windows stay open and other windows hide.
77
- * Set to `true` for an always-on-top popup that should dismiss on click-away,
78
- * or `false` to emit `focus-lost` without hiding. Can be changed at runtime
79
- * with {@link Menubar.setOption}.
75
+ * Hide the popup when it loses focus. Defaults to `true`, including when
76
+ * `browserWindow.alwaysOnTop` is set. Set to `false` to keep the popup open
77
+ * and on top, emitting `focus-lost` instead of hiding. Menubar manages the
78
+ * stacking level on each platform, including the Windows tray overflow.
79
+ * DevTools temporarily keeps the popup open without changing this option.
80
+ * Can be changed before or after window creation with {@link Menubar.setOption}.
80
81
  */
81
82
  hideOnBlur?: boolean;
82
83
  /**
@@ -153,6 +154,11 @@ interface Options {
153
154
  * [`setVisibleOnAllWorkspaces`](https://electronjs.org/docs/api/browser-window#winsetvisibleonallworkspacesvisible-options)
154
155
  * with `visibleOnFullScreen`, so the popup also opens over a fullscreen
155
156
  * space instead of macOS switching away to another space to show it.
157
+ *
158
+ * On macOS the window leaves every workspace when hidden with
159
+ * {@link Menubar.hideWindow} and rejoins them on {@link Menubar.showWindow},
160
+ * so show it through `showWindow()` rather than `window.show()` or
161
+ * `window.showInactive()`. Read when the window is created.
156
162
  */
157
163
  showOnAllWorkspaces?: boolean;
158
164
  /**
@@ -206,6 +212,7 @@ export declare class Menubar extends EventEmitter {
206
212
  private _lastShowTime;
207
213
  private _dockRehideTimeout?;
208
214
  private _repositioning;
215
+ private _showOnAllWorkspaces;
209
216
  private _tray?;
210
217
  constructor(app: Electron.App, options?: Partial<Options>);
211
218
  /**
@@ -298,6 +305,8 @@ export declare class Menubar extends EventEmitter {
298
305
  * @param value - The value to set.
299
306
  */
300
307
  setOption<K extends keyof Options>(key: K, value: Options[K]): void;
308
+ private shouldHideOnBlur;
309
+ private applyWindowFocusBehavior;
301
310
  /**
302
311
  * Show the menubar window.
303
312
  *
@@ -339,6 +348,19 @@ export declare class Menubar extends EventEmitter {
339
348
  private bindRightClickContextMenu;
340
349
  private onAppReady;
341
350
  private createWindow;
351
+ /**
352
+ * Join or leave every workspace when `showOnAllWorkspaces` is enabled.
353
+ *
354
+ * On macOS the hidden popup leaves every Space in {@link hideWindow} and
355
+ * rejoins them right before `show()` in {@link showWindow}. macOS can drop
356
+ * a hidden window from all but one Space while `isVisibleOnAllWorkspaces()`
357
+ * still reports `true`, e.g. when the fullscreen Space the popup was last
358
+ * shown on closes. Showing it then switches to that one Space, and setting
359
+ * the flag again to the value it already has does not re-add the window.
360
+ * Clearing the flag while hidden makes the next show a real change, which
361
+ * re-adds the window to every Space before it appears.
362
+ */
363
+ private applyWorkspaceVisibility;
342
364
  private windowClear;
343
365
  }
344
366
  //#endregion
package/lib/index.d.mts CHANGED
@@ -72,11 +72,12 @@ interface Options {
72
72
  */
73
73
  globalShortcut?: Electron.Accelerator;
74
74
  /**
75
- * Hide the window when it loses focus, independently of its stacking level.
76
- * When omitted, always-on-top windows stay open and other windows hide.
77
- * Set to `true` for an always-on-top popup that should dismiss on click-away,
78
- * or `false` to emit `focus-lost` without hiding. Can be changed at runtime
79
- * with {@link Menubar.setOption}.
75
+ * Hide the popup when it loses focus. Defaults to `true`, including when
76
+ * `browserWindow.alwaysOnTop` is set. Set to `false` to keep the popup open
77
+ * and on top, emitting `focus-lost` instead of hiding. Menubar manages the
78
+ * stacking level on each platform, including the Windows tray overflow.
79
+ * DevTools temporarily keeps the popup open without changing this option.
80
+ * Can be changed before or after window creation with {@link Menubar.setOption}.
80
81
  */
81
82
  hideOnBlur?: boolean;
82
83
  /**
@@ -153,6 +154,11 @@ interface Options {
153
154
  * [`setVisibleOnAllWorkspaces`](https://electronjs.org/docs/api/browser-window#winsetvisibleonallworkspacesvisible-options)
154
155
  * with `visibleOnFullScreen`, so the popup also opens over a fullscreen
155
156
  * space instead of macOS switching away to another space to show it.
157
+ *
158
+ * On macOS the window leaves every workspace when hidden with
159
+ * {@link Menubar.hideWindow} and rejoins them on {@link Menubar.showWindow},
160
+ * so show it through `showWindow()` rather than `window.show()` or
161
+ * `window.showInactive()`. Read when the window is created.
156
162
  */
157
163
  showOnAllWorkspaces?: boolean;
158
164
  /**
@@ -206,6 +212,7 @@ export declare class Menubar extends EventEmitter {
206
212
  private _lastShowTime;
207
213
  private _dockRehideTimeout?;
208
214
  private _repositioning;
215
+ private _showOnAllWorkspaces;
209
216
  private _tray?;
210
217
  constructor(app: Electron.App, options?: Partial<Options>);
211
218
  /**
@@ -298,6 +305,8 @@ export declare class Menubar extends EventEmitter {
298
305
  * @param value - The value to set.
299
306
  */
300
307
  setOption<K extends keyof Options>(key: K, value: Options[K]): void;
308
+ private shouldHideOnBlur;
309
+ private applyWindowFocusBehavior;
301
310
  /**
302
311
  * Show the menubar window.
303
312
  *
@@ -339,6 +348,19 @@ export declare class Menubar extends EventEmitter {
339
348
  private bindRightClickContextMenu;
340
349
  private onAppReady;
341
350
  private createWindow;
351
+ /**
352
+ * Join or leave every workspace when `showOnAllWorkspaces` is enabled.
353
+ *
354
+ * On macOS the hidden popup leaves every Space in {@link hideWindow} and
355
+ * rejoins them right before `show()` in {@link showWindow}. macOS can drop
356
+ * a hidden window from all but one Space while `isVisibleOnAllWorkspaces()`
357
+ * still reports `true`, e.g. when the fullscreen Space the popup was last
358
+ * shown on closes. Showing it then switches to that one Space, and setting
359
+ * the flag again to the value it already has does not re-add the window.
360
+ * Clearing the flag while hidden makes the next show a real change, which
361
+ * re-adds the window to every Space before it appears.
362
+ */
363
+ private applyWorkspaceVisibility;
342
364
  private windowClear;
343
365
  }
344
366
  //#endregion
package/lib/index.mjs CHANGED
@@ -230,6 +230,7 @@ var Menubar = class extends EventEmitter {
230
230
  _lastShowTime = 0;
231
231
  _dockRehideTimeout;
232
232
  _repositioning = false;
233
+ _showOnAllWorkspaces = false;
233
234
  _tray;
234
235
  constructor(app, options) {
235
236
  super();
@@ -327,6 +328,7 @@ var Menubar = class extends EventEmitter {
327
328
  if (!this._browserWindow || !this._isVisible) return;
328
329
  this.emit("hide");
329
330
  this._browserWindow.hide();
331
+ if (process.platform === "darwin") this.applyWorkspaceVisibility(false);
330
332
  this.emit("after-hide");
331
333
  this._isVisible = false;
332
334
  if (this._blurTimeout) {
@@ -419,6 +421,22 @@ var Menubar = class extends EventEmitter {
419
421
  */
420
422
  setOption(key, value) {
421
423
  this._options[key] = value;
424
+ if (key === "hideOnBlur" || key === "browserWindow") this.applyWindowFocusBehavior();
425
+ }
426
+ shouldHideOnBlur() {
427
+ const win = this._browserWindow;
428
+ return !!win && !win.isDestroyed() && this._options.hideOnBlur !== false && !win.webContents.isDevToolsOpened();
429
+ }
430
+ applyWindowFocusBehavior() {
431
+ const win = this._browserWindow;
432
+ if (!win || win.isDestroyed()) return;
433
+ const keepOpen = !this.shouldHideOnBlur();
434
+ if (this._blurTimeout) {
435
+ clearTimeout(this._blurTimeout);
436
+ this._blurTimeout = null;
437
+ }
438
+ if (process.platform === "win32") win.setAlwaysOnTop(true, "pop-up-menu");
439
+ else win.setAlwaysOnTop(keepOpen || this._options.browserWindow.alwaysOnTop === true);
422
440
  }
423
441
  /**
424
442
  * Show the menubar window.
@@ -432,7 +450,9 @@ var Menubar = class extends EventEmitter {
432
450
  this.emit("show");
433
451
  if (trayPos && trayPos.x !== 0) this._cachedBounds = trayPos;
434
452
  else if (!this._cachedBounds && this.tray.getBounds) this._cachedBounds = this.tray.getBounds();
453
+ if (process.platform === "darwin") this.applyWorkspaceVisibility(true);
435
454
  this.positionWindow();
455
+ this.applyWindowFocusBehavior();
436
456
  this._lastShowTime = Date.now();
437
457
  this._browserWindow.show();
438
458
  this._isVisible = true;
@@ -566,21 +586,28 @@ var Menubar = class extends EventEmitter {
566
586
  ...this._options.browserWindow
567
587
  });
568
588
  this._positioner = new Positioner(this._browserWindow);
589
+ this.applyWindowFocusBehavior();
590
+ this._browserWindow.webContents.on("devtools-opened", () => {
591
+ this.applyWindowFocusBehavior();
592
+ });
593
+ this._browserWindow.webContents.on("devtools-closed", () => {
594
+ this.applyWindowFocusBehavior();
595
+ });
569
596
  this._browserWindow.on("blur", () => {
570
597
  if (!this._browserWindow) return;
571
- if (!(this._options.hideOnBlur ?? !this._browserWindow.isAlwaysOnTop())) {
598
+ if (!this.shouldHideOnBlur()) {
572
599
  this.emit("focus-lost");
573
600
  return;
574
601
  }
575
602
  if (process.platform === "win32" && Date.now() - this._lastShowTime < BLUR_HIDE_GRACE_MS) return;
603
+ if (this._blurTimeout) clearTimeout(this._blurTimeout);
576
604
  this._blurTimeout = setTimeout(() => {
577
- this.hideWindow();
605
+ this._blurTimeout = null;
606
+ if (this.shouldHideOnBlur()) this.hideWindow();
578
607
  }, 100);
579
608
  });
580
- if (this._options.showOnAllWorkspaces !== false) this._browserWindow.setVisibleOnAllWorkspaces(true, {
581
- visibleOnFullScreen: true,
582
- skipTransformProcessType: true
583
- });
609
+ this._showOnAllWorkspaces = this._options.showOnAllWorkspaces !== false;
610
+ this.applyWorkspaceVisibility(true);
584
611
  if (this._options.hideOnClose) this._browserWindow.on("close", (event) => {
585
612
  if (this._isDestroyed || this._isQuitting) return;
586
613
  event.preventDefault();
@@ -595,6 +622,25 @@ var Menubar = class extends EventEmitter {
595
622
  if (this._options.index !== false) await this._browserWindow.loadURL(this._options.index, this._options.loadUrlOptions);
596
623
  this.emit("after-create-window");
597
624
  }
625
+ /**
626
+ * Join or leave every workspace when `showOnAllWorkspaces` is enabled.
627
+ *
628
+ * On macOS the hidden popup leaves every Space in {@link hideWindow} and
629
+ * rejoins them right before `show()` in {@link showWindow}. macOS can drop
630
+ * a hidden window from all but one Space while `isVisibleOnAllWorkspaces()`
631
+ * still reports `true`, e.g. when the fullscreen Space the popup was last
632
+ * shown on closes. Showing it then switches to that one Space, and setting
633
+ * the flag again to the value it already has does not re-add the window.
634
+ * Clearing the flag while hidden makes the next show a real change, which
635
+ * re-adds the window to every Space before it appears.
636
+ */
637
+ applyWorkspaceVisibility(visible) {
638
+ if (!this._browserWindow || this._browserWindow.isDestroyed() || !this._showOnAllWorkspaces) return;
639
+ this._browserWindow.setVisibleOnAllWorkspaces(visible, {
640
+ visibleOnFullScreen: visible,
641
+ skipTransformProcessType: true
642
+ });
643
+ }
598
644
  windowClear() {
599
645
  this._browserWindow = void 0;
600
646
  this.emit("after-close");
package/lib/index.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["electronScreen"],"sources":["../src/Positioner.ts","../src/util/cleanOptions.ts","../src/util/getWindowPosition.ts","../src/Menubar.ts","../src/index.ts"],"sourcesContent":["import { type BrowserWindow, type Rectangle, screen } from 'electron';\n\n/**\n * Named anchor points for placing the menubar window. The `tray*` values are\n * relative to the tray icon's bounds; the rest are relative to the work area\n * of the display containing the cursor (or the tray, when bounds are given).\n */\nexport type WindowPosition =\n | 'trayLeft'\n | 'trayBottomLeft'\n | 'trayRight'\n | 'trayBottomRight'\n | 'trayCenter'\n | 'trayBottomCenter'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'topCenter'\n | 'bottomCenter'\n | 'leftCenter'\n | 'rightCenter'\n | 'center';\n\n/**\n * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named\n * position, optionally relative to a tray icon's bounds. Ported from\n * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency.\n */\nexport class Positioner {\n private readonly browserWindow: BrowserWindow;\n\n constructor(browserWindow: BrowserWindow) {\n this.browserWindow = browserWindow;\n }\n\n calculate(\n position?: WindowPosition,\n trayBounds?: Rectangle,\n ): { x: number; y: number } {\n if (!position) {\n throw new TypeError(\n 'Positioner.calculate: a `position` argument is required.',\n );\n }\n\n const screenSize = trayBounds\n ? screen.getDisplayMatching(trayBounds).workArea\n : screen.getDisplayNearestPoint(screen.getCursorScreenPoint()).workArea;\n const [windowWidth, windowHeight] = this.browserWindow.getSize();\n const trayX = trayBounds?.x ?? Number.NaN;\n const trayWidth = trayBounds?.width ?? Number.NaN;\n\n const positions: Record<WindowPosition, { x: number; y: number }> = {\n trayLeft: {\n x: Math.floor(trayX),\n y: screenSize.y,\n },\n trayBottomLeft: {\n x: Math.floor(trayX),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: screenSize.y,\n },\n trayBottomRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: screenSize.y,\n },\n trayBottomCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topLeft: {\n x: screenSize.x,\n y: screenSize.y,\n },\n topRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: screenSize.y,\n },\n bottomLeft: {\n x: screenSize.x,\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n bottomRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: screenSize.y,\n },\n bottomCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n leftCenter: {\n x: screenSize.x,\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n rightCenter: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n center: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(\n (screenSize.height + screenSize.y) / 2 - windowHeight / 2,\n ),\n },\n };\n\n const coords = positions[position];\n\n // On Windows, a tray-relative position can push the window past the right\n // edge of the work area. Snap back to `topRight` x in that case so it stays\n // visible. See https://github.com/jenslind/electron-positioner.\n if (position.startsWith('tray')) {\n if (coords.x + windowWidth > screenSize.width + screenSize.x) {\n return { x: positions.topRight.x, y: coords.y };\n }\n }\n\n return coords;\n }\n}\n","/**\n * @ignore\n */\n\n/** */\n\nimport path from 'node:path';\nimport url from 'node:url';\n\nimport { app } from 'electron';\n\nimport type { Options } from '../types';\n\nconst DEFAULT_WINDOW_HEIGHT = 400;\nconst DEFAULT_WINDOW_WIDTH = 400;\n\n/**\n * Take as input some options, and return a sanitized version of it.\n *\n * @param opts - The options to clean.\n * @ignore\n */\nexport function cleanOptions(opts?: Partial<Options>): Options {\n const options: Partial<Options> = { ...opts };\n\n if (options.activateWithApp === undefined) {\n options.activateWithApp = true;\n }\n if (options.ignoreDoubleClickEvents === undefined) {\n options.ignoreDoubleClickEvents = true;\n }\n if (!options.dir) {\n options.dir = app.getAppPath();\n }\n if (!path.isAbsolute(options.dir)) {\n options.dir = path.resolve(options.dir);\n }\n // Note: options.index can be `false`\n if (options.index === undefined) {\n options.index = url.format({\n pathname: path.join(options.dir, 'index.html'),\n protocol: 'file:',\n slashes: true,\n });\n }\n options.loadUrlOptions = options.loadUrlOptions || {};\n\n options.tooltip = options.tooltip || '';\n\n // `icon`, `preloadWindow`, `showDockIcon`, `showOnAllWorkspaces`,\n // `showOnRightClick` don't need any special treatment\n\n // Now we take care of `browserWindow`\n if (!options.browserWindow) {\n options.browserWindow = {};\n }\n\n // Set width/height on options to be usable before the window is created\n options.browserWindow.width =\n // Note: not using `options.browserWindow.width || DEFAULT_WINDOW_WIDTH` so\n // that users can put a 0 width\n options.browserWindow.width !== undefined\n ? options.browserWindow.width\n : DEFAULT_WINDOW_WIDTH;\n options.browserWindow.height =\n options.browserWindow.height !== undefined\n ? options.browserWindow.height\n : DEFAULT_WINDOW_HEIGHT;\n\n return options as Options;\n}\n","/**\n * Utilities to get taskbar position and consequently menubar's position\n */\n\n/** */\n\nimport { screen as electronScreen, type Rectangle, type Tray } from 'electron';\n\nconst isLinux = process.platform === 'linux';\n\nconst trayToScreenRects = (trayBounds: Rectangle): [Rectangle, Rectangle] => {\n // There may be more than one screen, so we need to figure out on which screen our tray icon lives.\n const { workArea, bounds: screenBounds } =\n electronScreen.getDisplayMatching(trayBounds);\n\n return [\n screenBounds,\n {\n ...workArea,\n x: workArea.x - screenBounds.x,\n y: workArea.y - screenBounds.y,\n },\n ];\n};\n\ntype TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';\n\n/**\n * Determine taskbard location: \"top\", \"bottom\", \"left\" or \"right\".\n *\n * Only tested on Windows for now, and only used in Windows.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function taskbarLocation(tray: Tray): TaskbarLocation {\n const trayBounds = tray.getBounds();\n const [screenBounds, workArea] = trayToScreenRects(trayBounds);\n\n if (\n process.platform === 'win32' &&\n trayBounds.width > 0 &&\n trayBounds.height > 0\n ) {\n // Other appbars also reserve work-area space. The tray's nearest display\n // edge identifies the taskbar without mistaking a PowerToys dock for it.\n const x = trayBounds.x + trayBounds.width / 2 - screenBounds.x;\n const y = trayBounds.y + trayBounds.height / 2 - screenBounds.y;\n const insets: Record<TaskbarLocation, number> = {\n top: workArea.y,\n bottom: screenBounds.height - workArea.y - workArea.height,\n left: workArea.x,\n right: screenBounds.width - workArea.x - workArea.width,\n };\n let nearest: [TaskbarLocation, number] = [\n 'bottom',\n Math.abs(screenBounds.height - y),\n ];\n const edges: [TaskbarLocation, number][] = [\n ['top', Math.abs(y)],\n ['left', Math.abs(x)],\n ['right', Math.abs(screenBounds.width - x)],\n ];\n for (const edge of edges) {\n // At a corner, prefer the edge that actually reserves work-area space.\n if (\n edge[1] < nearest[1] ||\n (edge[1] === nearest[1] && insets[edge[0]] > insets[nearest[0]])\n )\n nearest = edge;\n }\n return nearest[0];\n }\n\n // TASKBAR LEFT\n if (workArea.x > 0) {\n // Most likely Ubuntu hence assuming the window should be on top\n if (isLinux && workArea.y > 0) return 'top';\n // The workspace starts more on the right\n return 'left';\n }\n\n // TASKBAR TOP\n if (workArea.y > 0) {\n return 'top';\n }\n\n // TASKBAR RIGHT\n // Here both workArea.y and workArea.x are 0 so we can no longer leverage them.\n // We can use the workarea and display width though.\n // Determine taskbar location\n if (workArea.width < screenBounds.width) {\n // The taskbar is either on the left or right, but since the LEFT case was handled above,\n // we can be sure we're dealing with a right taskbar\n return 'right';\n }\n\n // TASKBAR BOTTOM\n // Since all the other cases were handled, we can be sure we're dealing with a bottom taskbar\n return 'bottom';\n}\n\ntype WindowPosition =\n | 'trayCenter'\n | 'topRight'\n | 'trayBottomCenter'\n | 'leftCenter'\n | 'bottomRight';\n\n/**\n * Depending on where the taskbar is, determine where the window should be\n * positioned.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function getWindowPosition(tray: Tray): WindowPosition {\n switch (process.platform) {\n // macOS\n // Supports top taskbars\n case 'darwin':\n return 'trayCenter';\n // Linux\n // Windows\n // Supports top/bottom/left/right taskbar\n case 'linux':\n case 'win32': {\n const traySide = taskbarLocation(tray);\n\n // Assign position for menubar\n if (traySide === 'top') {\n return isLinux ? 'topRight' : 'trayCenter';\n }\n if (traySide === 'bottom') {\n return 'bottomRight';\n }\n if (traySide === 'left') {\n // Vertically centered against the left edge of the work area.\n // `bottomLeft` would put the window in the screen's bottom-left\n // corner — visually disconnected from the tray icon, which sits\n // somewhere on the left strip. Tray-anchored y isn't available\n // through `Positioner` for side taskbars, so center is the best\n // compromise that stays close to the tray.\n return 'leftCenter';\n }\n if (traySide === 'right') {\n return 'bottomRight';\n }\n }\n }\n\n // When we really don't know, we just show the menubar on the top-right\n return 'topRight';\n}\n","import { EventEmitter } from 'node:events';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n autoUpdater,\n BrowserWindow,\n globalShortcut,\n type Menu,\n Tray,\n} from 'electron';\n\nimport { Positioner } from './Positioner';\nimport type { Options } from './types';\nimport { cleanOptions } from './util/cleanOptions';\nimport { getWindowPosition } from './util/getWindowPosition';\n\n/**\n * Grace period after `showWindow()` during which a `blur` on the popup is\n * treated as the spurious Windows post-show blur and ignored instead of\n * triggering the auto-hide. See the `blur` handler in {@link Menubar.createWindow}.\n */\nconst BLUR_HIDE_GRACE_MS = 400;\n\n/**\n * Delay before re-asserting the hidden dock after startup. macOS can silently\n * drop an `app.dock.hide()` that races the app's launch activation\n * transition, leaving the dock icon stuck for the whole session. See the\n * re-check in {@link Menubar.appReady}.\n */\nconst DOCK_REHIDE_DELAY_MS = 2_000;\n\n/**\n * The main Menubar class.\n */\nexport class Menubar extends EventEmitter {\n private _app: Electron.App;\n private _browserWindow?: BrowserWindow;\n private _contextMenu?: Menu;\n private _blurTimeout: NodeJS.Timeout | null = null; // track blur events with timeout\n private _isDestroyed: boolean;\n private _isQuitting: boolean; // set when the app is shutting down, used by hideOnClose\n private _isVisible: boolean; // track visibility\n private _cachedBounds?: Electron.Rectangle; // _cachedBounds are needed for double-clicked event\n private _options: Options;\n private _positioner: Positioner | undefined;\n private _shortcut?: Electron.Accelerator;\n private _rightClickContextMenuBound = false;\n private _warnedNoPositioning = false; // guards the one-time Wayland warning\n private _lastShowTime = 0; // timestamp of last show(), debounces the post-show blur on Windows\n private _dockRehideTimeout?: NodeJS.Timeout; // pending post-startup dock re-hide check\n private _repositioning = false; // guards against re-entrant positionWindow calls\n private _tray?: Tray;\n\n constructor(app: Electron.App, options?: Partial<Options>) {\n super();\n this._app = app;\n this._options = cleanOptions(options);\n this._isDestroyed = false;\n this._isQuitting = false;\n this._isVisible = false;\n\n app.on('before-quit', this.onBeforeQuit);\n autoUpdater.on('before-quit-for-update', this.onBeforeQuit);\n\n if (app.isReady()) {\n // See https://github.com/maxogden/menubar/pull/151\n process.nextTick(this.onAppReady);\n } else {\n app.on('ready', this.onAppReady);\n }\n }\n\n /**\n * The Electron [App](https://electronjs.org/docs/api/app)\n * instance.\n */\n get app(): Electron.App {\n return this._app;\n }\n\n /**\n * The {@link Positioner} instance used to compute where the menubar window\n * should appear on screen. Available after the `after-create-window` event.\n */\n get positioner(): Positioner {\n if (!this._positioner) {\n throw new Error(\n 'Please access `this.positioner` after the `after-create-window` event has fired.',\n );\n }\n\n return this._positioner;\n }\n\n /**\n * The Electron [Tray](https://electronjs.org/docs/api/tray) instance.\n */\n get tray(): Tray {\n if (!this._tray) {\n throw new Error(\n 'Please access `this.tray` after the `ready` event has fired.',\n );\n }\n\n return this._tray;\n }\n\n /**\n * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)\n * instance, if it's present.\n */\n get window(): BrowserWindow | undefined {\n return this._browserWindow;\n }\n\n /**\n * Tear down the menubar instance: destroy the window, remove the tray, and\n * detach all listeners. Subsequent clicks on the tray will be no-ops until a\n * new {@link Menubar} instance is created.\n */\n destroy(): void {\n if (this.isDestroyed()) {\n return;\n }\n // Set first so `hideOnClose` lets the close go through instead of\n // intercepting it.\n this._isDestroyed = true;\n\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n\n if (this._dockRehideTimeout) {\n clearTimeout(this._dockRehideTimeout);\n this._dockRehideTimeout = undefined;\n }\n\n if (this._browserWindow) {\n this._browserWindow.destroy();\n this._browserWindow = undefined;\n }\n\n if (this._tray) {\n // Ensure all potential listeners are removed.\n for (const event of ['click', 'right-click', 'double-click']) {\n this._tray.removeListener(\n event as Parameters<Tray['on']>[0],\n this.clicked,\n );\n }\n this._tray.setToolTip('');\n this._tray = undefined;\n }\n\n this._app.removeListener('ready', this.onAppReady);\n this._app.removeListener('activate', this.onAppActivate);\n this._app.removeListener('before-quit', this.onBeforeQuit);\n autoUpdater.removeListener('before-quit-for-update', this.onBeforeQuit);\n }\n\n /**\n * Whether {@link destroy} has been called on this menubar instance.\n */\n isDestroyed(): boolean {\n return this._isDestroyed;\n }\n\n /**\n * Retrieve a menubar option.\n *\n * @param key - The option key to retrieve, see {@link Options}.\n */\n getOption<K extends keyof Options>(key: K): Options[K] {\n return this._options[key];\n }\n\n /**\n * Hide the menubar window.\n */\n hideWindow(): void {\n if (!this._browserWindow || !this._isVisible) {\n return;\n }\n this.emit('hide');\n this._browserWindow.hide();\n this.emit('after-hide');\n this._isVisible = false;\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n this._blurTimeout = null;\n }\n this.refreshContextMenu();\n }\n\n /**\n * Register a global keyboard accelerator that toggles the menubar window.\n * Replaces any previously registered shortcut owned by this Menubar.\n * Pass `undefined` to clear the current shortcut without registering a new\n * one. Returns whether the registration succeeded.\n *\n * @param accelerator - An Electron\n * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or\n * `undefined` to clear.\n */\n setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean {\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n this._options.globalShortcut = accelerator;\n if (!accelerator) {\n return true;\n }\n const ok = globalShortcut.register(accelerator, () => this.toggleWindow());\n if (ok) {\n this._shortcut = accelerator;\n }\n return ok;\n }\n\n /**\n * Toggle the menubar window: hide it if visible, show it otherwise.\n * Resolves once the window finishes showing or hiding.\n */\n async toggleWindow(): Promise<void> {\n if (this._browserWindow && this._isVisible) {\n this.hideWindow();\n return;\n }\n await this.showWindow();\n }\n\n /**\n * Re-center the menubar window over the tray icon. Convenience wrapper for\n * `positioner.move('trayCenter', tray.getBounds())` that's safe to call\n * after the `after-create-window` event. No-op if the window doesn't\n * exist yet.\n */\n recenterOnTray(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n const bounds = this._tray.getBounds();\n const { x, y } = this.positioner.calculate('trayCenter', bounds);\n this._browserWindow.setPosition(Math.round(x), Math.round(y));\n }\n\n /**\n * Replace the tray context menu after construction. On Linux this also\n * re-publishes the menu to the SNI host, which is required after mutating\n * items in-place since libappindicator caches the previous serialization.\n * On macOS/Windows the right-click popup handler reads the current menu\n * reference, so swapping or clearing here takes effect immediately.\n *\n * @param menu - The new menu, or `null` to clear it.\n */\n setContextMenu(menu: Menu | null): void {\n this._contextMenu = menu ?? undefined;\n this._options.contextMenu = menu ?? undefined;\n if (!this._tray) {\n return;\n }\n if (process.platform === 'linux') {\n // `setContextMenu(null)` clears the menu on Linux.\n this._tray.setContextMenu(menu);\n return;\n }\n // macOS / Windows: bind the right-click popup once on first non-empty\n // assignment. The handler reads `this._contextMenu` at invoke time, so\n // later swaps and clears take effect without rebinding (and never leak\n // a stale closure reference).\n if (menu && !this._rightClickContextMenuBound) {\n this.bindRightClickContextMenu();\n }\n }\n\n /**\n * Re-publish the current context menu so in-place mutations of its items\n * (`visible`, `enabled`, `checked`, `label`) become visible to the user.\n *\n * Only Linux needs this: libappindicator / StatusNotifierItem serializes the\n * menu once and serves that copy until it is set again, so a mutated item\n * would otherwise keep rendering its old state until the next show or hide.\n * A no-op on macOS and Windows, where the menu is read at popup time — call\n * it unconditionally after mutating items.\n */\n refreshContextMenu(): void {\n if (\n process.platform === 'linux' &&\n this._contextMenu &&\n this._tray &&\n !this._tray.isDestroyed?.()\n ) {\n this._tray.setContextMenu(this._contextMenu);\n }\n }\n\n /**\n * Change an option after menubar is created.\n *\n * @param key - The option key to modify, see {@link Options}.\n * @param value - The value to set.\n */\n setOption<K extends keyof Options>(key: K, value: Options[K]): void {\n this._options[key] = value;\n }\n\n /**\n * Show the menubar window.\n *\n * @param trayPos - The bounds to show the window in.\n */\n async showWindow(trayPos?: Electron.Rectangle): Promise<void> {\n if (!this.tray) {\n throw new Error('Tray should have been instantiated by now');\n }\n\n if (!this._browserWindow) {\n await this.createWindow();\n }\n\n // Use guard for TypeScript, to avoid ! everywhere\n if (!this._browserWindow) {\n throw new Error('Window has been initialized just above. qed.');\n }\n\n this.emit('show');\n\n // Cache fresh tray bounds (or fall back to existing cache / tray bounds)\n // so `positionWindow` can reposition without an event payload — for\n // example when the window resizes via `setSize`.\n if (trayPos && trayPos.x !== 0) {\n this._cachedBounds = trayPos;\n } else if (!this._cachedBounds && this.tray.getBounds) {\n this._cachedBounds = this.tray.getBounds();\n }\n\n this.positionWindow();\n // Record the show time before `show()` so the blur handler can recognise\n // and ignore the transient blur Windows fires right after (see below).\n this._lastShowTime = Date.now();\n this._browserWindow.show();\n this._isVisible = true;\n this.emit('after-show');\n this.refreshContextMenu();\n }\n\n /**\n * Compute and apply the tray-anchored position of the browser window. Safe\n * to call any time after `createWindow` has run — invoked from\n * {@link showWindow} on every show, and from the window's `resize` event so\n * `setSize` calls reposition the window correctly.\n */\n private positionWindow = (): void => {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // `setPosition` below can make Windows emit `resize` synchronously, which\n // re-enters this method through the window's `resize` listener. Each pass\n // nudges the window again, so the recursion never unwinds: the main\n // process wedges with the event loop blocked and the window grows past\n // screen size (gitify-app/gitify#3064). Ignore re-entrant calls; the\n // outermost one already applies the final position.\n if (this._repositioning) {\n return;\n }\n this._repositioning = true;\n try {\n this.applyWindowPosition();\n } finally {\n this._repositioning = false;\n }\n };\n\n /**\n * Compute and apply the tray-anchored position. Always call through\n * {@link positionWindow}, which guards against re-entrancy.\n */\n private applyWindowPosition(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // 'Windows' taskbar: sync window position each time before positioning.\n // https://github.com/maxogden/menubar/issues/232\n if (['win32', 'linux'].includes(process.platform)) {\n this._options.windowPosition = getWindowPosition(this._tray);\n }\n\n const trayPos = this._cachedBounds ?? this._tray.getBounds?.();\n\n // Default the window to the right if `trayPos` bounds are undefined or null.\n let noBoundsPosition: Options['windowPosition'];\n if (\n (trayPos === undefined || trayPos.x === 0) &&\n this._options.windowPosition?.startsWith('tray')\n ) {\n noBoundsPosition =\n process.platform === 'win32' ? 'bottomRight' : 'topRight';\n }\n\n const position = this.positioner.calculate(\n this._options.windowPosition || noBoundsPosition,\n trayPos,\n ) as { x: number; y: number };\n\n // Not using `||` because x and y can be zero.\n const x =\n this._options.browserWindow.x !== undefined\n ? this._options.browserWindow.x\n : position.x;\n const y =\n this._options.browserWindow.y !== undefined\n ? this._options.browserWindow.y\n : position.y;\n\n // `.setPosition` crashed on non-integers\n // https://github.com/maxogden/menubar/issues/233\n const targetX = Math.round(x);\n const targetY = Math.round(y);\n this._browserWindow.setPosition(targetX, targetY);\n\n // Native Wayland gives an application no way to position its own window:\n // `setPosition` is a no-op and `getPosition` reads back [0, 0]\n // (https://github.com/electron/electron/issues/40886). The compositor\n // decides where the window lands, usually centered, so the popover can't\n // be anchored to the tray. Detect that the move didn't take and warn once,\n // pointing at the X11 fallback. Gated on a Wayland session (`WAYLAND_DISPLAY`)\n // so pure X11 never trips it; the tolerance absorbs the few-pixel offsets\n // X11 window managers add for decorations, so XWayland (where positioning\n // works) doesn't trip it either.\n if (\n process.platform === 'linux' &&\n !!process.env.WAYLAND_DISPLAY &&\n !this._warnedNoPositioning\n ) {\n const [actualX, actualY] = this._browserWindow.getPosition();\n const ignored =\n Math.abs(actualX - targetX) > 24 || Math.abs(actualY - targetY) > 24;\n if (ignored) {\n this._warnedNoPositioning = true;\n console.warn(\n '[menubar] The window could not be positioned programmatically, ' +\n 'which is expected on native Wayland where the compositor controls ' +\n 'placement. The popover will not be anchored to the tray icon. Run ' +\n 'with --ozone-platform=x11 to restore tray-relative positioning.',\n );\n }\n }\n }\n\n private async appReady(): Promise<void> {\n if (this.app.dock && !this._options.showDockIcon) {\n this.app.dock.hide();\n\n // The hide above can be silently dropped when it races the launch\n // activation transition. Re-check once startup has settled; guarded on\n // visibility because `dock.hide()` also deactivates the app, so it must\n // not run when the dock is already hidden.\n this._dockRehideTimeout = setTimeout(() => {\n if (!this._isDestroyed && this.app.dock?.isVisible()) {\n this.app.dock.hide();\n }\n }, DOCK_REHIDE_DELAY_MS);\n }\n\n if (this._options.activateWithApp) {\n this.app.on('activate', this.onAppActivate);\n }\n\n let trayImage =\n this._options.icon || path.join(this._options.dir, 'IconTemplate.png');\n if (typeof trayImage === 'string' && !fs.existsSync(trayImage)) {\n trayImage = path.join(__dirname, '..', 'assets', 'IconTemplate.png'); // Default cat icon\n }\n\n const trigger =\n this._options.trigger ??\n (this._options.showOnRightClick ? 'right-click' : 'click');\n\n this._tray = this._options.tray || new Tray(trayImage);\n // Type guards for TS not to complain\n if (!this.tray) {\n throw new Error('Tray has been initialized above');\n }\n if (trigger !== 'none') {\n this.tray.on(trigger as Parameters<Tray['on']>[0], this.clicked);\n this.tray.on('double-click', this.clicked);\n }\n // macOS-only: ignore double-click so an accidental second click doesn't\n // race the blur handler and cause a tray-icon flicker.\n if (\n process.platform === 'darwin' &&\n this._options.ignoreDoubleClickEvents\n ) {\n this.tray.setIgnoreDoubleClickEvents(true);\n }\n this.tray.setToolTip(this._options.tooltip);\n\n if (this._options.contextMenu) {\n this.bindContextMenu(this._options.contextMenu);\n }\n\n if (this._options.globalShortcut) {\n this.setGlobalShortcut(this._options.globalShortcut);\n }\n\n if (!this._options.windowPosition) {\n this._options.windowPosition = getWindowPosition(this.tray);\n }\n\n if (this._options.preloadWindow) {\n await this.createWindow();\n }\n\n this.emit('ready');\n }\n\n /**\n * Callback on tray icon click or double-click.\n *\n * @param e\n * @param bounds\n */\n private clicked = async (\n event?: Electron.KeyboardEvent,\n bounds?: Electron.Rectangle,\n ): Promise<void> => {\n if (event && (event.shiftKey || event.ctrlKey || event.metaKey)) {\n return this.hideWindow();\n }\n\n // if blur was invoked clear timeout\n if (this._blurTimeout) {\n clearInterval(this._blurTimeout);\n }\n\n if (this._browserWindow && this._isVisible) {\n return this.hideWindow();\n }\n\n this._cachedBounds = bounds || this._cachedBounds;\n await this.showWindow(this._cachedBounds);\n };\n\n private onAppActivate = (\n _event: Electron.Event,\n hasVisibleWindows: boolean,\n ): void => {\n if (!hasVisibleWindows) {\n this.showWindow().catch(console.error);\n }\n };\n\n /**\n * Marks the app as shutting down so `hideOnClose` stops intercepting closes.\n *\n * Bound to both `app`'s `before-quit` and the auto updater's\n * `before-quit-for-update`. Installing an update never emits `before-quit`:\n * Electron closes every window first and only quits once the window list is\n * empty, so a `hideOnClose` veto there would leave the window open and the\n * install waiting forever.\n */\n private onBeforeQuit = (): void => {\n this._isQuitting = true;\n };\n\n private bindContextMenu(menu: Menu): void {\n this._contextMenu = menu;\n if (process.platform === 'linux') {\n // libappindicator / StatusNotifierItem requires the menu to live on the\n // tray itself; right-click is handled by the desktop environment.\n this.tray.setContextMenu(menu);\n return;\n }\n this.bindRightClickContextMenu();\n }\n\n private bindRightClickContextMenu(): void {\n // macOS / Windows: pop up the current menu on right-click so left-click\n // stays bound to toggling the menubar window. Read `this._contextMenu`\n // at invoke time so `setContextMenu()` swaps and clears take effect\n // without rebinding (and without leaking a stale closure reference).\n this.tray.on('right-click', (_event, bounds) => {\n const current = this._contextMenu;\n if (!current) {\n return;\n }\n this.tray.popUpContextMenu(current, { x: bounds.x, y: bounds.y });\n });\n this._rightClickContextMenuBound = true;\n }\n\n private onAppReady = (): void => {\n // Guard against `destroy()` being called between construction and the\n // scheduled `process.nextTick`/`'ready'` firing.\n if (this._isDestroyed) {\n return;\n }\n this.appReady().catch((err) => console.error('menubar: ', err));\n };\n\n private async createWindow(): Promise<void> {\n this.emit('create-window');\n\n // We add some default behavior for menubar's browserWindow, to make it\n // look like a menubar\n const defaults = {\n show: false, // Don't show it at first\n frame: false, // Remove window frame\n };\n\n this._browserWindow = new BrowserWindow({\n ...defaults,\n ...this._options.browserWindow,\n });\n\n this._positioner = new Positioner(this._browserWindow);\n\n this._browserWindow.on('blur', () => {\n if (!this._browserWindow) {\n return;\n }\n\n // Preserve the legacy pin behavior unless the host explicitly separates\n // click-away dismissal from the window's stacking level.\n const hideOnBlur =\n this._options.hideOnBlur ?? !this._browserWindow.isAlwaysOnTop();\n if (!hideOnBlur) {\n this.emit('focus-lost');\n return;\n }\n\n // Windows foreground-activation race: clicking the tray icon keeps the\n // shell (explorer.exe) as the foreground process, so `show()` cannot pull\n // focus to the popup and Windows immediately fires `blur`. Left unguarded,\n // the hide timer below fires before the first paint and the window never\n // visibly appears (gitify-app/gitify#3064). Ignore blur events that land\n // within the grace window right after a show; a genuine click-away\n // arrives well after it.\n if (\n process.platform === 'win32' &&\n Date.now() - this._lastShowTime < BLUR_HIDE_GRACE_MS\n ) {\n return;\n }\n\n this._blurTimeout = setTimeout(() => {\n this.hideWindow();\n }, 100);\n });\n\n if (this._options.showOnAllWorkspaces !== false) {\n // https://github.com/electron/electron/issues/37832#issuecomment-1497882944\n this._browserWindow.setVisibleOnAllWorkspaces(true, {\n // Maps to NSWindowCollectionBehaviorFullScreenAuxiliary, which\n // Electron clears when the flag is omitted. Without it the popup\n // cannot appear inside a fullscreen space, so macOS switches to\n // another space to show it.\n visibleOnFullScreen: true,\n skipTransformProcessType: true, // Avoid damaging the original visible state of app.dock\n });\n }\n\n if (this._options.hideOnClose) {\n this._browserWindow.on('close', (event) => {\n if (this._isDestroyed || this._isQuitting) {\n return;\n }\n event.preventDefault();\n // Defer the hide for Wayland: hiding synchronously from the `close`\n // handler can leave frameless surfaces in a half-closed state.\n setImmediate(() => this.hideWindow());\n });\n }\n\n if (this._options.escapeToHide) {\n this._browserWindow.webContents.on(\n 'before-input-event',\n (_event, input) => {\n if (input.type === 'keyDown' && input.key === 'Escape') {\n this.hideWindow();\n }\n },\n );\n }\n\n // Use `closed` (not `close`) so consumer `close` listeners can still read\n // `mb.window` and call `event.preventDefault()` without racing our cleanup.\n this._browserWindow.on('closed', this.windowClear.bind(this));\n\n // Re-anchor the window to the tray when its size changes (e.g. via\n // `mb.window.setSize(...)`), so the window doesn't end up clipped under\n // the taskbar. https://github.com/maxogden/menubar/issues/349\n this._browserWindow.on('resize', this.positionWindow);\n\n this.emit('before-load');\n\n // If the user explicity set options.index to false, we don't loadURL\n // https://github.com/maxogden/menubar/issues/255\n if (this._options.index !== false) {\n await this._browserWindow.loadURL(\n this._options.index,\n this._options.loadUrlOptions,\n );\n }\n this.emit('after-create-window');\n }\n\n private windowClear(): void {\n this._browserWindow = undefined;\n this.emit('after-close');\n }\n}\n","/**\n * Entry point of menubar\n * @example\n * ```typescript\n * import { menubar } from 'menubar';\n * ```\n */\n\n/** */\n\nimport { app } from 'electron';\n\nimport { Menubar } from './Menubar';\nimport type { Options } from './types';\n\nexport * from './util/getWindowPosition';\nexport { Menubar };\n\n/**\n * Factory function to create a menubar application\n *\n * @param options - Options for creating a menubar application, see\n * {@link Options}\n */\nexport function menubar(options?: Partial<Options>): Menubar {\n return new Menubar(app, options);\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,aAAb,MAAwB;CACtB;CAEA,YAAY,eAA8B;EACxC,KAAK,gBAAgB;CACvB;CAEA,UACE,UACA,YAC0B;EAC1B,IAAI,CAAC,UACH,MAAM,IAAI,UACR,0DACF;EAGF,MAAM,aAAa,aACf,OAAO,mBAAmB,UAAU,CAAC,CAAC,WACtC,OAAO,uBAAuB,OAAO,qBAAqB,CAAC,CAAC,CAAC;EACjE,MAAM,CAAC,aAAa,gBAAgB,KAAK,cAAc,QAAQ;EAC/D,MAAM,QAAQ,YAAY,KAAK;EAC/B,MAAM,YAAY,YAAY,SAAS;EAEvC,MAAM,YAA8D;GAClE,UAAU;IACR,GAAG,KAAK,MAAM,KAAK;IACnB,GAAG,WAAW;GAChB;GACA,gBAAgB;IACd,GAAG,KAAK,MAAM,KAAK;IACnB,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,WAAW;IACT,GAAG,KAAK,MAAM,QAAQ,cAAc,SAAS;IAC7C,GAAG,WAAW;GAChB;GACA,iBAAiB;IACf,GAAG,KAAK,MAAM,QAAQ,cAAc,SAAS;IAC7C,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,YAAY;IACV,GAAG,KAAK,MAAM,QAAQ,cAAc,IAAI,YAAY,CAAC;IACrD,GAAG,WAAW;GAChB;GACA,kBAAkB;IAChB,GAAG,KAAK,MAAM,QAAQ,cAAc,IAAI,YAAY,CAAC;IACrD,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,SAAS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B,KAAK,aAC5B;GAEF,MAAM,eAAe;GAGrB,mBAAmB,KAAK,WAAW,CAAC;EACtC,CAAC;EAGH,IAAI,KAAK,SAAS,cAChB,KAAK,eAAe,YAAY,GAC9B,uBACC,QAAQ,UAAU;GACjB,IAAI,MAAM,SAAS,aAAa,MAAM,QAAQ,UAC5C,KAAK,WAAW;EAEpB,CACF;EAKF,KAAK,eAAe,GAAG,UAAU,KAAK,YAAY,KAAK,IAAI,CAAC;EAK5D,KAAK,eAAe,GAAG,UAAU,KAAK,cAAc;EAEpD,KAAK,KAAK,aAAa;EAIvB,IAAI,KAAK,SAAS,UAAU,OAC1B,MAAM,KAAK,eAAe,QACxB,KAAK,SAAS,OACd,KAAK,SAAS,cAChB;EAEF,KAAK,KAAK,qBAAqB;CACjC;CAEA,cAA4B;EAC1B,KAAK,iBAAiB,KAAA;EACtB,KAAK,KAAK,aAAa;CACzB;AACF;;;;;;;;;;;;;;;;;ACprBA,SAAgB,QAAQ,SAAqC;CAC3D,OAAO,IAAI,QAAQ,KAAK,OAAO;AACjC"}
1
+ {"version":3,"file":"index.mjs","names":["electronScreen"],"sources":["../src/Positioner.ts","../src/util/cleanOptions.ts","../src/util/getWindowPosition.ts","../src/Menubar.ts","../src/index.ts"],"sourcesContent":["import { type BrowserWindow, type Rectangle, screen } from 'electron';\n\n/**\n * Named anchor points for placing the menubar window. The `tray*` values are\n * relative to the tray icon's bounds; the rest are relative to the work area\n * of the display containing the cursor (or the tray, when bounds are given).\n */\nexport type WindowPosition =\n | 'trayLeft'\n | 'trayBottomLeft'\n | 'trayRight'\n | 'trayBottomRight'\n | 'trayCenter'\n | 'trayBottomCenter'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'topCenter'\n | 'bottomCenter'\n | 'leftCenter'\n | 'rightCenter'\n | 'center';\n\n/**\n * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named\n * position, optionally relative to a tray icon's bounds. Ported from\n * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency.\n */\nexport class Positioner {\n private readonly browserWindow: BrowserWindow;\n\n constructor(browserWindow: BrowserWindow) {\n this.browserWindow = browserWindow;\n }\n\n calculate(\n position?: WindowPosition,\n trayBounds?: Rectangle,\n ): { x: number; y: number } {\n if (!position) {\n throw new TypeError(\n 'Positioner.calculate: a `position` argument is required.',\n );\n }\n\n const screenSize = trayBounds\n ? screen.getDisplayMatching(trayBounds).workArea\n : screen.getDisplayNearestPoint(screen.getCursorScreenPoint()).workArea;\n const [windowWidth, windowHeight] = this.browserWindow.getSize();\n const trayX = trayBounds?.x ?? Number.NaN;\n const trayWidth = trayBounds?.width ?? Number.NaN;\n\n const positions: Record<WindowPosition, { x: number; y: number }> = {\n trayLeft: {\n x: Math.floor(trayX),\n y: screenSize.y,\n },\n trayBottomLeft: {\n x: Math.floor(trayX),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: screenSize.y,\n },\n trayBottomRight: {\n x: Math.floor(trayX - windowWidth + trayWidth),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n trayCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: screenSize.y,\n },\n trayBottomCenter: {\n x: Math.floor(trayX - windowWidth / 2 + trayWidth / 2),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topLeft: {\n x: screenSize.x,\n y: screenSize.y,\n },\n topRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: screenSize.y,\n },\n bottomLeft: {\n x: screenSize.x,\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n bottomRight: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n topCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: screenSize.y,\n },\n bottomCenter: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(screenSize.height - (windowHeight - screenSize.y)),\n },\n leftCenter: {\n x: screenSize.x,\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n rightCenter: {\n x: Math.floor(screenSize.x + (screenSize.width - windowWidth)),\n y:\n screenSize.y +\n Math.floor(screenSize.height / 2) -\n Math.floor(windowHeight / 2),\n },\n center: {\n x: Math.floor(screenSize.x + (screenSize.width / 2 - windowWidth / 2)),\n y: Math.floor(\n (screenSize.height + screenSize.y) / 2 - windowHeight / 2,\n ),\n },\n };\n\n const coords = positions[position];\n\n // On Windows, a tray-relative position can push the window past the right\n // edge of the work area. Snap back to `topRight` x in that case so it stays\n // visible. See https://github.com/jenslind/electron-positioner.\n if (position.startsWith('tray')) {\n if (coords.x + windowWidth > screenSize.width + screenSize.x) {\n return { x: positions.topRight.x, y: coords.y };\n }\n }\n\n return coords;\n }\n}\n","/**\n * @ignore\n */\n\n/** */\n\nimport path from 'node:path';\nimport url from 'node:url';\n\nimport { app } from 'electron';\n\nimport type { Options } from '../types';\n\nconst DEFAULT_WINDOW_HEIGHT = 400;\nconst DEFAULT_WINDOW_WIDTH = 400;\n\n/**\n * Take as input some options, and return a sanitized version of it.\n *\n * @param opts - The options to clean.\n * @ignore\n */\nexport function cleanOptions(opts?: Partial<Options>): Options {\n const options: Partial<Options> = { ...opts };\n\n if (options.activateWithApp === undefined) {\n options.activateWithApp = true;\n }\n if (options.ignoreDoubleClickEvents === undefined) {\n options.ignoreDoubleClickEvents = true;\n }\n if (!options.dir) {\n options.dir = app.getAppPath();\n }\n if (!path.isAbsolute(options.dir)) {\n options.dir = path.resolve(options.dir);\n }\n // Note: options.index can be `false`\n if (options.index === undefined) {\n options.index = url.format({\n pathname: path.join(options.dir, 'index.html'),\n protocol: 'file:',\n slashes: true,\n });\n }\n options.loadUrlOptions = options.loadUrlOptions || {};\n\n options.tooltip = options.tooltip || '';\n\n // `icon`, `preloadWindow`, `showDockIcon`, `showOnAllWorkspaces`,\n // `showOnRightClick` don't need any special treatment\n\n // Now we take care of `browserWindow`\n if (!options.browserWindow) {\n options.browserWindow = {};\n }\n\n // Set width/height on options to be usable before the window is created\n options.browserWindow.width =\n // Note: not using `options.browserWindow.width || DEFAULT_WINDOW_WIDTH` so\n // that users can put a 0 width\n options.browserWindow.width !== undefined\n ? options.browserWindow.width\n : DEFAULT_WINDOW_WIDTH;\n options.browserWindow.height =\n options.browserWindow.height !== undefined\n ? options.browserWindow.height\n : DEFAULT_WINDOW_HEIGHT;\n\n return options as Options;\n}\n","/**\n * Utilities to get taskbar position and consequently menubar's position\n */\n\n/** */\n\nimport { screen as electronScreen, type Rectangle, type Tray } from 'electron';\n\nconst isLinux = process.platform === 'linux';\n\nconst trayToScreenRects = (trayBounds: Rectangle): [Rectangle, Rectangle] => {\n // There may be more than one screen, so we need to figure out on which screen our tray icon lives.\n const { workArea, bounds: screenBounds } =\n electronScreen.getDisplayMatching(trayBounds);\n\n return [\n screenBounds,\n {\n ...workArea,\n x: workArea.x - screenBounds.x,\n y: workArea.y - screenBounds.y,\n },\n ];\n};\n\ntype TaskbarLocation = 'top' | 'bottom' | 'left' | 'right';\n\n/**\n * Determine taskbard location: \"top\", \"bottom\", \"left\" or \"right\".\n *\n * Only tested on Windows for now, and only used in Windows.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function taskbarLocation(tray: Tray): TaskbarLocation {\n const trayBounds = tray.getBounds();\n const [screenBounds, workArea] = trayToScreenRects(trayBounds);\n\n if (\n process.platform === 'win32' &&\n trayBounds.width > 0 &&\n trayBounds.height > 0\n ) {\n // Other appbars also reserve work-area space. The tray's nearest display\n // edge identifies the taskbar without mistaking a PowerToys dock for it.\n const x = trayBounds.x + trayBounds.width / 2 - screenBounds.x;\n const y = trayBounds.y + trayBounds.height / 2 - screenBounds.y;\n const insets: Record<TaskbarLocation, number> = {\n top: workArea.y,\n bottom: screenBounds.height - workArea.y - workArea.height,\n left: workArea.x,\n right: screenBounds.width - workArea.x - workArea.width,\n };\n let nearest: [TaskbarLocation, number] = [\n 'bottom',\n Math.abs(screenBounds.height - y),\n ];\n const edges: [TaskbarLocation, number][] = [\n ['top', Math.abs(y)],\n ['left', Math.abs(x)],\n ['right', Math.abs(screenBounds.width - x)],\n ];\n for (const edge of edges) {\n // At a corner, prefer the edge that actually reserves work-area space.\n if (\n edge[1] < nearest[1] ||\n (edge[1] === nearest[1] && insets[edge[0]] > insets[nearest[0]])\n )\n nearest = edge;\n }\n return nearest[0];\n }\n\n // TASKBAR LEFT\n if (workArea.x > 0) {\n // Most likely Ubuntu hence assuming the window should be on top\n if (isLinux && workArea.y > 0) return 'top';\n // The workspace starts more on the right\n return 'left';\n }\n\n // TASKBAR TOP\n if (workArea.y > 0) {\n return 'top';\n }\n\n // TASKBAR RIGHT\n // Here both workArea.y and workArea.x are 0 so we can no longer leverage them.\n // We can use the workarea and display width though.\n // Determine taskbar location\n if (workArea.width < screenBounds.width) {\n // The taskbar is either on the left or right, but since the LEFT case was handled above,\n // we can be sure we're dealing with a right taskbar\n return 'right';\n }\n\n // TASKBAR BOTTOM\n // Since all the other cases were handled, we can be sure we're dealing with a bottom taskbar\n return 'bottom';\n}\n\ntype WindowPosition =\n | 'trayCenter'\n | 'topRight'\n | 'trayBottomCenter'\n | 'leftCenter'\n | 'bottomRight';\n\n/**\n * Depending on where the taskbar is, determine where the window should be\n * positioned.\n *\n * @param tray - The Electron Tray instance.\n */\nexport function getWindowPosition(tray: Tray): WindowPosition {\n switch (process.platform) {\n // macOS\n // Supports top taskbars\n case 'darwin':\n return 'trayCenter';\n // Linux\n // Windows\n // Supports top/bottom/left/right taskbar\n case 'linux':\n case 'win32': {\n const traySide = taskbarLocation(tray);\n\n // Assign position for menubar\n if (traySide === 'top') {\n return isLinux ? 'topRight' : 'trayCenter';\n }\n if (traySide === 'bottom') {\n return 'bottomRight';\n }\n if (traySide === 'left') {\n // Vertically centered against the left edge of the work area.\n // `bottomLeft` would put the window in the screen's bottom-left\n // corner — visually disconnected from the tray icon, which sits\n // somewhere on the left strip. Tray-anchored y isn't available\n // through `Positioner` for side taskbars, so center is the best\n // compromise that stays close to the tray.\n return 'leftCenter';\n }\n if (traySide === 'right') {\n return 'bottomRight';\n }\n }\n }\n\n // When we really don't know, we just show the menubar on the top-right\n return 'topRight';\n}\n","import { EventEmitter } from 'node:events';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n autoUpdater,\n BrowserWindow,\n globalShortcut,\n type Menu,\n Tray,\n} from 'electron';\n\nimport { Positioner } from './Positioner';\nimport type { Options } from './types';\nimport { cleanOptions } from './util/cleanOptions';\nimport { getWindowPosition } from './util/getWindowPosition';\n\n/**\n * Grace period after `showWindow()` during which a `blur` on the popup is\n * treated as the spurious Windows post-show blur and ignored instead of\n * triggering the auto-hide. See the `blur` handler in {@link Menubar.createWindow}.\n */\nconst BLUR_HIDE_GRACE_MS = 400;\n\n/**\n * Delay before re-asserting the hidden dock after startup. macOS can silently\n * drop an `app.dock.hide()` that races the app's launch activation\n * transition, leaving the dock icon stuck for the whole session. See the\n * re-check in {@link Menubar.appReady}.\n */\nconst DOCK_REHIDE_DELAY_MS = 2_000;\n\n/**\n * The main Menubar class.\n */\nexport class Menubar extends EventEmitter {\n private _app: Electron.App;\n private _browserWindow?: BrowserWindow;\n private _contextMenu?: Menu;\n private _blurTimeout: NodeJS.Timeout | null = null; // track blur events with timeout\n private _isDestroyed: boolean;\n private _isQuitting: boolean; // set when the app is shutting down, used by hideOnClose\n private _isVisible: boolean; // track visibility\n private _cachedBounds?: Electron.Rectangle; // _cachedBounds are needed for double-clicked event\n private _options: Options;\n private _positioner: Positioner | undefined;\n private _shortcut?: Electron.Accelerator;\n private _rightClickContextMenuBound = false;\n private _warnedNoPositioning = false; // guards the one-time Wayland warning\n private _lastShowTime = 0; // timestamp of last show(), debounces the post-show blur on Windows\n private _dockRehideTimeout?: NodeJS.Timeout; // pending post-startup dock re-hide check\n private _repositioning = false; // guards against re-entrant positionWindow calls\n private _showOnAllWorkspaces = false; // `showOnAllWorkspaces` as read when the window was created\n private _tray?: Tray;\n\n constructor(app: Electron.App, options?: Partial<Options>) {\n super();\n this._app = app;\n this._options = cleanOptions(options);\n this._isDestroyed = false;\n this._isQuitting = false;\n this._isVisible = false;\n\n app.on('before-quit', this.onBeforeQuit);\n autoUpdater.on('before-quit-for-update', this.onBeforeQuit);\n\n if (app.isReady()) {\n // See https://github.com/maxogden/menubar/pull/151\n process.nextTick(this.onAppReady);\n } else {\n app.on('ready', this.onAppReady);\n }\n }\n\n /**\n * The Electron [App](https://electronjs.org/docs/api/app)\n * instance.\n */\n get app(): Electron.App {\n return this._app;\n }\n\n /**\n * The {@link Positioner} instance used to compute where the menubar window\n * should appear on screen. Available after the `after-create-window` event.\n */\n get positioner(): Positioner {\n if (!this._positioner) {\n throw new Error(\n 'Please access `this.positioner` after the `after-create-window` event has fired.',\n );\n }\n\n return this._positioner;\n }\n\n /**\n * The Electron [Tray](https://electronjs.org/docs/api/tray) instance.\n */\n get tray(): Tray {\n if (!this._tray) {\n throw new Error(\n 'Please access `this.tray` after the `ready` event has fired.',\n );\n }\n\n return this._tray;\n }\n\n /**\n * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window)\n * instance, if it's present.\n */\n get window(): BrowserWindow | undefined {\n return this._browserWindow;\n }\n\n /**\n * Tear down the menubar instance: destroy the window, remove the tray, and\n * detach all listeners. Subsequent clicks on the tray will be no-ops until a\n * new {@link Menubar} instance is created.\n */\n destroy(): void {\n if (this.isDestroyed()) {\n return;\n }\n // Set first so `hideOnClose` lets the close go through instead of\n // intercepting it.\n this._isDestroyed = true;\n\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n\n if (this._dockRehideTimeout) {\n clearTimeout(this._dockRehideTimeout);\n this._dockRehideTimeout = undefined;\n }\n\n if (this._browserWindow) {\n this._browserWindow.destroy();\n this._browserWindow = undefined;\n }\n\n if (this._tray) {\n // Ensure all potential listeners are removed.\n for (const event of ['click', 'right-click', 'double-click']) {\n this._tray.removeListener(\n event as Parameters<Tray['on']>[0],\n this.clicked,\n );\n }\n this._tray.setToolTip('');\n this._tray = undefined;\n }\n\n this._app.removeListener('ready', this.onAppReady);\n this._app.removeListener('activate', this.onAppActivate);\n this._app.removeListener('before-quit', this.onBeforeQuit);\n autoUpdater.removeListener('before-quit-for-update', this.onBeforeQuit);\n }\n\n /**\n * Whether {@link destroy} has been called on this menubar instance.\n */\n isDestroyed(): boolean {\n return this._isDestroyed;\n }\n\n /**\n * Retrieve a menubar option.\n *\n * @param key - The option key to retrieve, see {@link Options}.\n */\n getOption<K extends keyof Options>(key: K): Options[K] {\n return this._options[key];\n }\n\n /**\n * Hide the menubar window.\n */\n hideWindow(): void {\n if (!this._browserWindow || !this._isVisible) {\n return;\n }\n this.emit('hide');\n this._browserWindow.hide();\n if (process.platform === 'darwin') {\n this.applyWorkspaceVisibility(false);\n }\n this.emit('after-hide');\n this._isVisible = false;\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n this._blurTimeout = null;\n }\n this.refreshContextMenu();\n }\n\n /**\n * Register a global keyboard accelerator that toggles the menubar window.\n * Replaces any previously registered shortcut owned by this Menubar.\n * Pass `undefined` to clear the current shortcut without registering a new\n * one. Returns whether the registration succeeded.\n *\n * @param accelerator - An Electron\n * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or\n * `undefined` to clear.\n */\n setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean {\n if (this._shortcut) {\n globalShortcut.unregister(this._shortcut);\n this._shortcut = undefined;\n }\n this._options.globalShortcut = accelerator;\n if (!accelerator) {\n return true;\n }\n const ok = globalShortcut.register(accelerator, () => this.toggleWindow());\n if (ok) {\n this._shortcut = accelerator;\n }\n return ok;\n }\n\n /**\n * Toggle the menubar window: hide it if visible, show it otherwise.\n * Resolves once the window finishes showing or hiding.\n */\n async toggleWindow(): Promise<void> {\n if (this._browserWindow && this._isVisible) {\n this.hideWindow();\n return;\n }\n await this.showWindow();\n }\n\n /**\n * Re-center the menubar window over the tray icon. Convenience wrapper for\n * `positioner.move('trayCenter', tray.getBounds())` that's safe to call\n * after the `after-create-window` event. No-op if the window doesn't\n * exist yet.\n */\n recenterOnTray(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n const bounds = this._tray.getBounds();\n const { x, y } = this.positioner.calculate('trayCenter', bounds);\n this._browserWindow.setPosition(Math.round(x), Math.round(y));\n }\n\n /**\n * Replace the tray context menu after construction. On Linux this also\n * re-publishes the menu to the SNI host, which is required after mutating\n * items in-place since libappindicator caches the previous serialization.\n * On macOS/Windows the right-click popup handler reads the current menu\n * reference, so swapping or clearing here takes effect immediately.\n *\n * @param menu - The new menu, or `null` to clear it.\n */\n setContextMenu(menu: Menu | null): void {\n this._contextMenu = menu ?? undefined;\n this._options.contextMenu = menu ?? undefined;\n if (!this._tray) {\n return;\n }\n if (process.platform === 'linux') {\n // `setContextMenu(null)` clears the menu on Linux.\n this._tray.setContextMenu(menu);\n return;\n }\n // macOS / Windows: bind the right-click popup once on first non-empty\n // assignment. The handler reads `this._contextMenu` at invoke time, so\n // later swaps and clears take effect without rebinding (and never leak\n // a stale closure reference).\n if (menu && !this._rightClickContextMenuBound) {\n this.bindRightClickContextMenu();\n }\n }\n\n /**\n * Re-publish the current context menu so in-place mutations of its items\n * (`visible`, `enabled`, `checked`, `label`) become visible to the user.\n *\n * Only Linux needs this: libappindicator / StatusNotifierItem serializes the\n * menu once and serves that copy until it is set again, so a mutated item\n * would otherwise keep rendering its old state until the next show or hide.\n * A no-op on macOS and Windows, where the menu is read at popup time — call\n * it unconditionally after mutating items.\n */\n refreshContextMenu(): void {\n if (\n process.platform === 'linux' &&\n this._contextMenu &&\n this._tray &&\n !this._tray.isDestroyed?.()\n ) {\n this._tray.setContextMenu(this._contextMenu);\n }\n }\n\n /**\n * Change an option after menubar is created.\n *\n * @param key - The option key to modify, see {@link Options}.\n * @param value - The value to set.\n */\n setOption<K extends keyof Options>(key: K, value: Options[K]): void {\n this._options[key] = value;\n if (key === 'hideOnBlur' || key === 'browserWindow') {\n this.applyWindowFocusBehavior();\n }\n }\n\n private shouldHideOnBlur(): boolean {\n const win = this._browserWindow;\n return (\n !!win &&\n !win.isDestroyed() &&\n this._options.hideOnBlur !== false &&\n !win.webContents.isDevToolsOpened()\n );\n }\n\n private applyWindowFocusBehavior(): void {\n const win = this._browserWindow;\n if (!win || win.isDestroyed()) {\n return;\n }\n\n const keepOpen = !this.shouldHideOnBlur();\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n this._blurTimeout = null;\n }\n\n if (process.platform === 'win32') {\n win.setAlwaysOnTop(true, 'pop-up-menu');\n } else {\n win.setAlwaysOnTop(\n keepOpen || this._options.browserWindow.alwaysOnTop === true,\n );\n }\n }\n\n /**\n * Show the menubar window.\n *\n * @param trayPos - The bounds to show the window in.\n */\n async showWindow(trayPos?: Electron.Rectangle): Promise<void> {\n if (!this.tray) {\n throw new Error('Tray should have been instantiated by now');\n }\n\n if (!this._browserWindow) {\n await this.createWindow();\n }\n\n // Use guard for TypeScript, to avoid ! everywhere\n if (!this._browserWindow) {\n throw new Error('Window has been initialized just above. qed.');\n }\n\n this.emit('show');\n\n // Cache fresh tray bounds (or fall back to existing cache / tray bounds)\n // so `positionWindow` can reposition without an event payload — for\n // example when the window resizes via `setSize`.\n if (trayPos && trayPos.x !== 0) {\n this._cachedBounds = trayPos;\n } else if (!this._cachedBounds && this.tray.getBounds) {\n this._cachedBounds = this.tray.getBounds();\n }\n\n if (process.platform === 'darwin') {\n this.applyWorkspaceVisibility(true);\n }\n this.positionWindow();\n // Record the show time before `show()` so the blur handler can recognise\n // and ignore the transient blur Windows fires right after (see below).\n this.applyWindowFocusBehavior();\n this._lastShowTime = Date.now();\n this._browserWindow.show();\n this._isVisible = true;\n this.emit('after-show');\n this.refreshContextMenu();\n }\n\n /**\n * Compute and apply the tray-anchored position of the browser window. Safe\n * to call any time after `createWindow` has run — invoked from\n * {@link showWindow} on every show, and from the window's `resize` event so\n * `setSize` calls reposition the window correctly.\n */\n private positionWindow = (): void => {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // `setPosition` below can make Windows emit `resize` synchronously, which\n // re-enters this method through the window's `resize` listener. Each pass\n // nudges the window again, so the recursion never unwinds: the main\n // process wedges with the event loop blocked and the window grows past\n // screen size (gitify-app/gitify#3064). Ignore re-entrant calls; the\n // outermost one already applies the final position.\n if (this._repositioning) {\n return;\n }\n this._repositioning = true;\n try {\n this.applyWindowPosition();\n } finally {\n this._repositioning = false;\n }\n };\n\n /**\n * Compute and apply the tray-anchored position. Always call through\n * {@link positionWindow}, which guards against re-entrancy.\n */\n private applyWindowPosition(): void {\n if (!this._browserWindow || !this._tray) {\n return;\n }\n\n // 'Windows' taskbar: sync window position each time before positioning.\n // https://github.com/maxogden/menubar/issues/232\n if (['win32', 'linux'].includes(process.platform)) {\n this._options.windowPosition = getWindowPosition(this._tray);\n }\n\n const trayPos = this._cachedBounds ?? this._tray.getBounds?.();\n\n // Default the window to the right if `trayPos` bounds are undefined or null.\n let noBoundsPosition: Options['windowPosition'];\n if (\n (trayPos === undefined || trayPos.x === 0) &&\n this._options.windowPosition?.startsWith('tray')\n ) {\n noBoundsPosition =\n process.platform === 'win32' ? 'bottomRight' : 'topRight';\n }\n\n const position = this.positioner.calculate(\n this._options.windowPosition || noBoundsPosition,\n trayPos,\n ) as { x: number; y: number };\n\n // Not using `||` because x and y can be zero.\n const x =\n this._options.browserWindow.x !== undefined\n ? this._options.browserWindow.x\n : position.x;\n const y =\n this._options.browserWindow.y !== undefined\n ? this._options.browserWindow.y\n : position.y;\n\n // `.setPosition` crashed on non-integers\n // https://github.com/maxogden/menubar/issues/233\n const targetX = Math.round(x);\n const targetY = Math.round(y);\n this._browserWindow.setPosition(targetX, targetY);\n\n // Native Wayland gives an application no way to position its own window:\n // `setPosition` is a no-op and `getPosition` reads back [0, 0]\n // (https://github.com/electron/electron/issues/40886). The compositor\n // decides where the window lands, usually centered, so the popover can't\n // be anchored to the tray. Detect that the move didn't take and warn once,\n // pointing at the X11 fallback. Gated on a Wayland session (`WAYLAND_DISPLAY`)\n // so pure X11 never trips it; the tolerance absorbs the few-pixel offsets\n // X11 window managers add for decorations, so XWayland (where positioning\n // works) doesn't trip it either.\n if (\n process.platform === 'linux' &&\n !!process.env.WAYLAND_DISPLAY &&\n !this._warnedNoPositioning\n ) {\n const [actualX, actualY] = this._browserWindow.getPosition();\n const ignored =\n Math.abs(actualX - targetX) > 24 || Math.abs(actualY - targetY) > 24;\n if (ignored) {\n this._warnedNoPositioning = true;\n console.warn(\n '[menubar] The window could not be positioned programmatically, ' +\n 'which is expected on native Wayland where the compositor controls ' +\n 'placement. The popover will not be anchored to the tray icon. Run ' +\n 'with --ozone-platform=x11 to restore tray-relative positioning.',\n );\n }\n }\n }\n\n private async appReady(): Promise<void> {\n if (this.app.dock && !this._options.showDockIcon) {\n this.app.dock.hide();\n\n // The hide above can be silently dropped when it races the launch\n // activation transition. Re-check once startup has settled; guarded on\n // visibility because `dock.hide()` also deactivates the app, so it must\n // not run when the dock is already hidden.\n this._dockRehideTimeout = setTimeout(() => {\n if (!this._isDestroyed && this.app.dock?.isVisible()) {\n this.app.dock.hide();\n }\n }, DOCK_REHIDE_DELAY_MS);\n }\n\n if (this._options.activateWithApp) {\n this.app.on('activate', this.onAppActivate);\n }\n\n let trayImage =\n this._options.icon || path.join(this._options.dir, 'IconTemplate.png');\n if (typeof trayImage === 'string' && !fs.existsSync(trayImage)) {\n trayImage = path.join(__dirname, '..', 'assets', 'IconTemplate.png'); // Default cat icon\n }\n\n const trigger =\n this._options.trigger ??\n (this._options.showOnRightClick ? 'right-click' : 'click');\n\n this._tray = this._options.tray || new Tray(trayImage);\n // Type guards for TS not to complain\n if (!this.tray) {\n throw new Error('Tray has been initialized above');\n }\n if (trigger !== 'none') {\n this.tray.on(trigger as Parameters<Tray['on']>[0], this.clicked);\n this.tray.on('double-click', this.clicked);\n }\n // macOS-only: ignore double-click so an accidental second click doesn't\n // race the blur handler and cause a tray-icon flicker.\n if (\n process.platform === 'darwin' &&\n this._options.ignoreDoubleClickEvents\n ) {\n this.tray.setIgnoreDoubleClickEvents(true);\n }\n this.tray.setToolTip(this._options.tooltip);\n\n if (this._options.contextMenu) {\n this.bindContextMenu(this._options.contextMenu);\n }\n\n if (this._options.globalShortcut) {\n this.setGlobalShortcut(this._options.globalShortcut);\n }\n\n if (!this._options.windowPosition) {\n this._options.windowPosition = getWindowPosition(this.tray);\n }\n\n if (this._options.preloadWindow) {\n await this.createWindow();\n }\n\n this.emit('ready');\n }\n\n /**\n * Callback on tray icon click or double-click.\n *\n * @param e\n * @param bounds\n */\n private clicked = async (\n event?: Electron.KeyboardEvent,\n bounds?: Electron.Rectangle,\n ): Promise<void> => {\n if (event && (event.shiftKey || event.ctrlKey || event.metaKey)) {\n return this.hideWindow();\n }\n\n // if blur was invoked clear timeout\n if (this._blurTimeout) {\n clearInterval(this._blurTimeout);\n }\n\n if (this._browserWindow && this._isVisible) {\n return this.hideWindow();\n }\n\n this._cachedBounds = bounds || this._cachedBounds;\n await this.showWindow(this._cachedBounds);\n };\n\n private onAppActivate = (\n _event: Electron.Event,\n hasVisibleWindows: boolean,\n ): void => {\n if (!hasVisibleWindows) {\n this.showWindow().catch(console.error);\n }\n };\n\n /**\n * Marks the app as shutting down so `hideOnClose` stops intercepting closes.\n *\n * Bound to both `app`'s `before-quit` and the auto updater's\n * `before-quit-for-update`. Installing an update never emits `before-quit`:\n * Electron closes every window first and only quits once the window list is\n * empty, so a `hideOnClose` veto there would leave the window open and the\n * install waiting forever.\n */\n private onBeforeQuit = (): void => {\n this._isQuitting = true;\n };\n\n private bindContextMenu(menu: Menu): void {\n this._contextMenu = menu;\n if (process.platform === 'linux') {\n // libappindicator / StatusNotifierItem requires the menu to live on the\n // tray itself; right-click is handled by the desktop environment.\n this.tray.setContextMenu(menu);\n return;\n }\n this.bindRightClickContextMenu();\n }\n\n private bindRightClickContextMenu(): void {\n // macOS / Windows: pop up the current menu on right-click so left-click\n // stays bound to toggling the menubar window. Read `this._contextMenu`\n // at invoke time so `setContextMenu()` swaps and clears take effect\n // without rebinding (and without leaking a stale closure reference).\n this.tray.on('right-click', (_event, bounds) => {\n const current = this._contextMenu;\n if (!current) {\n return;\n }\n this.tray.popUpContextMenu(current, { x: bounds.x, y: bounds.y });\n });\n this._rightClickContextMenuBound = true;\n }\n\n private onAppReady = (): void => {\n // Guard against `destroy()` being called between construction and the\n // scheduled `process.nextTick`/`'ready'` firing.\n if (this._isDestroyed) {\n return;\n }\n this.appReady().catch((err) => console.error('menubar: ', err));\n };\n\n private async createWindow(): Promise<void> {\n this.emit('create-window');\n\n // We add some default behavior for menubar's browserWindow, to make it\n // look like a menubar\n const defaults = {\n show: false, // Don't show it at first\n frame: false, // Remove window frame\n };\n\n this._browserWindow = new BrowserWindow({\n ...defaults,\n ...this._options.browserWindow,\n });\n\n this._positioner = new Positioner(this._browserWindow);\n\n this.applyWindowFocusBehavior();\n this._browserWindow.webContents.on('devtools-opened', () => {\n this.applyWindowFocusBehavior();\n });\n this._browserWindow.webContents.on('devtools-closed', () => {\n this.applyWindowFocusBehavior();\n });\n\n this._browserWindow.on('blur', () => {\n if (!this._browserWindow) {\n return;\n }\n\n if (!this.shouldHideOnBlur()) {\n this.emit('focus-lost');\n return;\n }\n\n // Windows foreground-activation race: clicking the tray icon keeps the\n // shell (explorer.exe) as the foreground process, so `show()` cannot pull\n // focus to the popup and Windows immediately fires `blur`. Left unguarded,\n // the hide timer below fires before the first paint and the window never\n // visibly appears (gitify-app/gitify#3064). Ignore blur events that land\n // within the grace window right after a show; a genuine click-away\n // arrives well after it.\n if (\n process.platform === 'win32' &&\n Date.now() - this._lastShowTime < BLUR_HIDE_GRACE_MS\n ) {\n return;\n }\n\n if (this._blurTimeout) {\n clearTimeout(this._blurTimeout);\n }\n this._blurTimeout = setTimeout(() => {\n this._blurTimeout = null;\n if (this.shouldHideOnBlur()) {\n this.hideWindow();\n }\n }, 100);\n });\n\n this._showOnAllWorkspaces = this._options.showOnAllWorkspaces !== false;\n this.applyWorkspaceVisibility(true);\n\n if (this._options.hideOnClose) {\n this._browserWindow.on('close', (event) => {\n if (this._isDestroyed || this._isQuitting) {\n return;\n }\n event.preventDefault();\n // Defer the hide for Wayland: hiding synchronously from the `close`\n // handler can leave frameless surfaces in a half-closed state.\n setImmediate(() => this.hideWindow());\n });\n }\n\n if (this._options.escapeToHide) {\n this._browserWindow.webContents.on(\n 'before-input-event',\n (_event, input) => {\n if (input.type === 'keyDown' && input.key === 'Escape') {\n this.hideWindow();\n }\n },\n );\n }\n\n // Use `closed` (not `close`) so consumer `close` listeners can still read\n // `mb.window` and call `event.preventDefault()` without racing our cleanup.\n this._browserWindow.on('closed', this.windowClear.bind(this));\n\n // Re-anchor the window to the tray when its size changes (e.g. via\n // `mb.window.setSize(...)`), so the window doesn't end up clipped under\n // the taskbar. https://github.com/maxogden/menubar/issues/349\n this._browserWindow.on('resize', this.positionWindow);\n\n this.emit('before-load');\n\n // If the user explicity set options.index to false, we don't loadURL\n // https://github.com/maxogden/menubar/issues/255\n if (this._options.index !== false) {\n await this._browserWindow.loadURL(\n this._options.index,\n this._options.loadUrlOptions,\n );\n }\n this.emit('after-create-window');\n }\n\n /**\n * Join or leave every workspace when `showOnAllWorkspaces` is enabled.\n *\n * On macOS the hidden popup leaves every Space in {@link hideWindow} and\n * rejoins them right before `show()` in {@link showWindow}. macOS can drop\n * a hidden window from all but one Space while `isVisibleOnAllWorkspaces()`\n * still reports `true`, e.g. when the fullscreen Space the popup was last\n * shown on closes. Showing it then switches to that one Space, and setting\n * the flag again to the value it already has does not re-add the window.\n * Clearing the flag while hidden makes the next show a real change, which\n * re-adds the window to every Space before it appears.\n */\n private applyWorkspaceVisibility(visible: boolean): void {\n if (\n !this._browserWindow ||\n this._browserWindow.isDestroyed() ||\n !this._showOnAllWorkspaces\n ) {\n return;\n }\n // https://github.com/electron/electron/issues/37832#issuecomment-1497882944\n this._browserWindow.setVisibleOnAllWorkspaces(visible, {\n // Maps to NSWindowCollectionBehaviorFullScreenAuxiliary, which\n // Electron clears when the flag is omitted. Without it the popup\n // cannot appear inside a fullscreen space, so macOS switches to\n // another space to show it.\n visibleOnFullScreen: visible,\n skipTransformProcessType: true, // Avoid damaging the original visible state of app.dock\n });\n }\n\n private windowClear(): void {\n this._browserWindow = undefined;\n this.emit('after-close');\n }\n}\n","/**\n * Entry point of menubar\n * @example\n * ```typescript\n * import { menubar } from 'menubar';\n * ```\n */\n\n/** */\n\nimport { app } from 'electron';\n\nimport { Menubar } from './Menubar';\nimport type { Options } from './types';\n\nexport * from './util/getWindowPosition';\nexport { Menubar };\n\n/**\n * Factory function to create a menubar application\n *\n * @param options - Options for creating a menubar application, see\n * {@link Options}\n */\nexport function menubar(options?: Partial<Options>): Menubar {\n return new Menubar(app, options);\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,aAAb,MAAwB;CACtB;CAEA,YAAY,eAA8B;EACxC,KAAK,gBAAgB;CACvB;CAEA,UACE,UACA,YAC0B;EAC1B,IAAI,CAAC,UACH,MAAM,IAAI,UACR,0DACF;EAGF,MAAM,aAAa,aACf,OAAO,mBAAmB,UAAU,CAAC,CAAC,WACtC,OAAO,uBAAuB,OAAO,qBAAqB,CAAC,CAAC,CAAC;EACjE,MAAM,CAAC,aAAa,gBAAgB,KAAK,cAAc,QAAQ;EAC/D,MAAM,QAAQ,YAAY,KAAK;EAC/B,MAAM,YAAY,YAAY,SAAS;EAEvC,MAAM,YAA8D;GAClE,UAAU;IACR,GAAG,KAAK,MAAM,KAAK;IACnB,GAAG,WAAW;GAChB;GACA,gBAAgB;IACd,GAAG,KAAK,MAAM,KAAK;IACnB,GAAG,KAAK,MAAM,WAAW,UAAU,eAAe,WAAW,EAAE;GACjE;GACA,WAAW;IACT,GAAG,KAAK,MAAM,QAAQ,cAAc,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aAC5B;GAEF,MAAM,eAAe;GAGrB,mBAAmB,KAAK,WAAW,CAAC;EACtC,CAAC;EAGH,IAAI,KAAK,SAAS,cAChB,KAAK,eAAe,YAAY,GAC9B,uBACC,QAAQ,UAAU;GACjB,IAAI,MAAM,SAAS,aAAa,MAAM,QAAQ,UAC5C,KAAK,WAAW;EAEpB,CACF;EAKF,KAAK,eAAe,GAAG,UAAU,KAAK,YAAY,KAAK,IAAI,CAAC;EAK5D,KAAK,eAAe,GAAG,UAAU,KAAK,cAAc;EAEpD,KAAK,KAAK,aAAa;EAIvB,IAAI,KAAK,SAAS,UAAU,OAC1B,MAAM,KAAK,eAAe,QACxB,KAAK,SAAS,OACd,KAAK,SAAS,cAChB;EAEF,KAAK,KAAK,qBAAqB;CACjC;;;;;;;;;;;;;CAcA,yBAAiC,SAAwB;EACvD,IACE,CAAC,KAAK,kBACN,KAAK,eAAe,YAAY,KAChC,CAAC,KAAK,sBAEN;EAGF,KAAK,eAAe,0BAA0B,SAAS;GAKrD,qBAAqB;GACrB,0BAA0B;EAC5B,CAAC;CACH;CAEA,cAA4B;EAC1B,KAAK,iBAAiB,KAAA;EACtB,KAAK,KAAK,aAAa;CACzB;AACF;;;;;;;;;;;;;;;;;AC9vBA,SAAgB,QAAQ,SAAqC;CAC3D,OAAO,IAAI,QAAQ,KAAK,OAAO;AACjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-menubar",
3
- "version": "10.3.0",
3
+ "version": "11.1.0",
4
4
  "description": "high level way to create menubar desktop applications with electron",
5
5
  "keywords": [
6
6
  "app",
@@ -64,17 +64,17 @@
64
64
  "devDependencies": {
65
65
  "@playwright/test": "1.62.1",
66
66
  "@types/pngjs": "6.0.5",
67
- "electron": "44.1.1",
67
+ "electron": "44.3.0",
68
68
  "oxfmt": "0.66.0",
69
69
  "oxlint": "1.81.0",
70
70
  "pngjs": "7.0.0",
71
- "rolldown": "1.2.7",
72
- "rolldown-plugin-dts": "0.28.4",
71
+ "rolldown": "1.2.11",
72
+ "rolldown-plugin-dts": "0.28.6",
73
73
  "typescript": "7.0.2",
74
- "vitest": "4.1.11"
74
+ "vitest": "5.0.2"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "electron": ">=35.0.0"
78
78
  },
79
- "packageManager": "pnpm@11.25.0"
79
+ "packageManager": "pnpm@12.3.2"
80
80
  }