import { BrowserWindow, BrowserWindowConstructorOptions, LoadURLOptions, Menu, Rectangle, Tray } from "electron"; import { EventEmitter } from "node:events"; //#region src/Positioner.d.ts /** * Named anchor points for placing the menubar window. The `tray*` values are * relative to the tray icon's bounds; the rest are relative to the work area * of the display containing the cursor (or the tray, when bounds are given). */ type WindowPosition$1 = 'trayLeft' | 'trayBottomLeft' | 'trayRight' | 'trayBottomRight' | 'trayCenter' | 'trayBottomCenter' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'topCenter' | 'bottomCenter' | 'leftCenter' | 'rightCenter' | 'center'; /** * Computes `{x, y}` coordinates for placing a {@link BrowserWindow} at a named * position, optionally relative to a tray icon's bounds. Ported from * `electron-positioner@4.1.0` to drop the unmaintained runtime dependency. */ declare class Positioner { private readonly browserWindow; constructor(browserWindow: BrowserWindow); calculate(position?: WindowPosition$1, trayBounds?: Rectangle): { x: number; y: number; }; } //#endregion //#region src/types.d.ts /** * Options for creating a menubar application */ interface Options { /** * Listen on `app.on('activate')` to open menubar when app is activated. * @default `true` */ activateWithApp?: boolean; /** * An Electron BrowserWindow instance, or an options object to be passed into * the BrowserWindow constructor. * @example * ```typescript * const options = { height: 640, width: 480 }; * * const mb = new Menubar({ * browserWindow: options * }); * ``` */ browserWindow: BrowserWindowConstructorOptions; /** * A native context menu to attach to the tray icon. * * On Linux this is bound via {@link Tray.setContextMenu} (required by * libappindicator / StatusNotifierItem) and re-published whenever the * menubar window shows or hides to defeat the indicator's menu cache. * * On macOS and Windows it is shown via {@link Tray.popUpContextMenu} on * right-click, so left-click continues to toggle the menubar window. * Setting this option therefore implies `trigger: 'click'` on those * platforms — pass `trigger: 'none'` to disable left-click toggling * entirely. */ contextMenu?: Menu; /** * The app source directory. */ dir: string; /** * Register this accelerator as a global shortcut that toggles the menubar * window. Calls * [`globalShortcut.register`](https://electronjs.org/docs/api/global-shortcut#globalshortcutregisteraccelerator-callback) * after `ready` and unregisters it on {@link Menubar.destroy}. The same * accelerator can be set or cleared later via * {@link Menubar.setGlobalShortcut}. */ globalShortcut?: Electron.Accelerator; /** * Hide the window on `close` instead of letting it be destroyed, so the * next tray click re-uses the same {@link BrowserWindow} instance. 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. * * Closes go through unimpeded once the app is shutting down, which the * library tracks via `app`'s `before-quit` and the auto updater's * `before-quit-for-update`. Has no effect when the close event was * triggered by {@link Menubar.destroy}. * @default `false` */ hideOnClose?: boolean; /** * Hide the menubar window when the user presses `Escape` while it has * focus. Wires up a `before-input-event` listener on the BrowserWindow. * @default `false` */ escapeToHide?: boolean; /** * 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. */ icon?: string | Electron.NativeImage; /** * 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. If false, then menubar won't call `loadURL` on * start. * @default `file:// + options.dir + index.html` * @see https://electronjs.org/docs/api/browser-window#winloadurlurl-options */ index: string | false; /** * 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 * @default `{}` * @see https://electronjs.org/docs/api/browser-window#winloadurlurl-options */ loadUrlOptions?: LoadURLOptions; /** * Ignore the tray's `double-click` event on macOS. Prevents a flicker * caused by the close-on-blur handler racing the second click of an * accidental double-click. No-op on Linux/Windows. Calls * [`tray.setIgnoreDoubleClickEvents`](https://electronjs.org/docs/api/tray#traysetignoredoubleclickeventsignore-macos). * @default `true` */ ignoreDoubleClickEvents?: boolean; /** * Create BrowserWindow instance before it is used -- increasing resource * usage, but making the click on the menubar load faster. */ preloadWindow?: boolean; /** * Configure the visibility of the application dock icon, macOS only. Calls * [`app.dock.hide`](https://electronjs.org/docs/api/app#appdockhide-macos). * * Hiding at runtime is a process transform that macOS can silently drop, so * packaged apps that never want a dock tile should also declare * `LSUIElement` in their `Info.plist` (with electron-builder: * `mac.extendInfo.LSUIElement: true`). This option then still covers * development runs, where the stock Electron binary's plist is not under * your control. */ showDockIcon?: boolean; /** * Makes the window available on all OS X workspaces. Calls * [`setVisibleOnAllWorkspaces`](https://electronjs.org/docs/api/browser-window#winsetvisibleonallworkspacesvisible-options) * with `visibleOnFullScreen`, so the popup also opens over a fullscreen * space instead of macOS switching away to another space to show it. */ showOnAllWorkspaces?: boolean; /** * Show the window on 'right-click' event instead of regular 'click'. * @deprecated Use {@link Options.trigger} instead. Will be removed in the * next major release. */ showOnRightClick?: boolean; /** * Tray event that toggles the menubar window. Set to `'none'` to disable * automatic toggling — the window can still be shown by calling * {@link Menubar.showWindow} directly. Useful when a single tray icon serves * multiple windows. * @default `'click'` (or `'right-click'` if the deprecated * {@link Options.showOnRightClick} is `true`) */ trigger?: 'click' | 'right-click' | 'none'; /** * Menubar tray icon tooltip text. Calls [`tray.setTooltip`](https://electronjs.org/docs/api/tray#traysettooltiptooltip). */ tooltip: string; /** * An electron Tray instance. If provided, `options.icon` will be ignored. */ tray?: Tray; /** * Sets the window position (x and y will still override this). See * {@link WindowPosition} for the list of valid values. */ windowPosition?: WindowPosition$1; } //#endregion //#region src/Menubar.d.ts /** * The main Menubar class. */ export declare class Menubar extends EventEmitter { private _app; private _browserWindow?; private _contextMenu?; private _blurTimeout; private _isDestroyed; private _isQuitting; private _isVisible; private _cachedBounds?; private _options; private _positioner; private _shortcut?; private _rightClickContextMenuBound; private _warnedNoPositioning; private _lastShowTime; private _dockRehideTimeout?; private _repositioning; private _tray?; constructor(app: Electron.App, options?: Partial); /** * The Electron [App](https://electronjs.org/docs/api/app) * instance. */ get app(): Electron.App; /** * The {@link Positioner} instance used to compute where the menubar window * should appear on screen. Available after the `after-create-window` event. */ get positioner(): Positioner; /** * The Electron [Tray](https://electronjs.org/docs/api/tray) instance. */ get tray(): Tray; /** * The Electron [BrowserWindow](https://electronjs.org/docs/api/browser-window) * instance, if it's present. */ get window(): BrowserWindow | undefined; /** * Tear down the menubar instance: destroy the window, remove the tray, and * detach all listeners. Subsequent clicks on the tray will be no-ops until a * new {@link Menubar} instance is created. */ destroy(): void; /** * Whether {@link destroy} has been called on this menubar instance. */ isDestroyed(): boolean; /** * Retrieve a menubar option. * * @param key - The option key to retrieve, see {@link Options}. */ getOption(key: K): Options[K]; /** * Hide the menubar window. */ hideWindow(): void; /** * Register a global keyboard accelerator that toggles the menubar window. * Replaces any previously registered shortcut owned by this Menubar. * Pass `undefined` to clear the current shortcut without registering a new * one. Returns whether the registration succeeded. * * @param accelerator - An Electron * [Accelerator](https://electronjs.org/docs/api/accelerator) string, or * `undefined` to clear. */ setGlobalShortcut(accelerator: Electron.Accelerator | undefined): boolean; /** * Toggle the menubar window: hide it if visible, show it otherwise. * Resolves once the window finishes showing or hiding. */ toggleWindow(): Promise; /** * Re-center the menubar window over the tray icon. Convenience wrapper for * `positioner.move('trayCenter', tray.getBounds())` that's safe to call * after the `after-create-window` event. No-op if the window doesn't * exist yet. */ recenterOnTray(): void; /** * Replace the tray context menu after construction. On Linux this also * re-publishes the menu to the SNI host, which is required after mutating * items in-place since libappindicator caches the previous serialization. * On macOS/Windows the right-click popup handler reads the current menu * reference, so swapping or clearing here takes effect immediately. * * @param menu - The new menu, or `null` to clear it. */ setContextMenu(menu: Menu | null): void; /** * Re-publish the current context menu so in-place mutations of its items * (`visible`, `enabled`, `checked`, `label`) become visible to the user. * * Only Linux needs this: libappindicator / StatusNotifierItem serializes the * menu once and serves that copy until it is set again, so a mutated item * would otherwise keep rendering its old state until the next show or hide. * A no-op on macOS and Windows, where the menu is read at popup time — call * it unconditionally after mutating items. */ refreshContextMenu(): void; /** * Change an option after menubar is created. * * @param key - The option key to modify, see {@link Options}. * @param value - The value to set. */ setOption(key: K, value: Options[K]): void; /** * Show the menubar window. * * @param trayPos - The bounds to show the window in. */ showWindow(trayPos?: Electron.Rectangle): Promise; /** * Compute and apply the tray-anchored position of the browser window. Safe * to call any time after `createWindow` has run — invoked from * {@link showWindow} on every show, and from the window's `resize` event so * `setSize` calls reposition the window correctly. */ private positionWindow; /** * Compute and apply the tray-anchored position. Always call through * {@link positionWindow}, which guards against re-entrancy. */ private applyWindowPosition; private appReady; /** * Callback on tray icon click or double-click. * * @param e * @param bounds */ private clicked; private onAppActivate; /** * Marks the app as shutting down so `hideOnClose` stops intercepting closes. * * Bound to both `app`'s `before-quit` and the auto updater's * `before-quit-for-update`. Installing an update never emits `before-quit`: * Electron closes every window first and only quits once the window list is * empty, so a `hideOnClose` veto there would leave the window open and the * install waiting forever. */ private onBeforeQuit; private bindContextMenu; private bindRightClickContextMenu; private onAppReady; private createWindow; private windowClear; } //#endregion //#region src/util/getWindowPosition.d.ts type TaskbarLocation = 'top' | 'bottom' | 'left' | 'right'; /** * Determine taskbard location: "top", "bottom", "left" or "right". * * Only tested on Windows for now, and only used in Windows. * * @param tray - The Electron Tray instance. */ export declare function taskbarLocation(tray: Tray): TaskbarLocation; type WindowPosition = 'trayCenter' | 'topRight' | 'trayBottomCenter' | 'leftCenter' | 'bottomRight'; /** * Depending on where the taskbar is, determine where the window should be * positioned. * * @param tray - The Electron Tray instance. */ export declare function getWindowPosition(tray: Tray): WindowPosition; //#endregion //#region src/index.d.ts /** * Factory function to create a menubar application * * @param options - Options for creating a menubar application, see * {@link Options} */ export declare function menubar(options?: Partial): Menubar; //#endregion //# sourceMappingURL=index.d.mts.map