From 7a340d69dc558a8b43a05a52530dc465627be95e Mon Sep 17 00:00:00 2001 From: Hayden Donald Date: Sun, 13 Oct 2024 12:10:37 +1100 Subject: [PATCH] Add disable click option Added disableClick which will disable the opening of the window when the user clicks the tray icon. You can still use showWindow to open the window --- src/Menubar.ts | 16 +++++++++------- src/types.ts | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Menubar.ts b/src/Menubar.ts index a2e3d38..d381059 100644 --- a/src/Menubar.ts +++ b/src/Menubar.ts @@ -222,11 +222,13 @@ export class Menubar extends EventEmitter { if (!this.tray) { throw new Error('Tray has been initialized above'); } - this.tray.on( - defaultClickEvent as Parameters[0], - this.clicked.bind(this), - ); - this.tray.on('double-click', this.clicked.bind(this)); + if (this._options.disableClick != true) { + this.tray.on( + defaultClickEvent as Parameters[0], + this.clicked.bind(this), + ); + this.tray.on('double-click', this.clicked.bind(this)); + } this.tray.setToolTip(this._options.tooltip); if (!this._options.windowPosition) { @@ -293,8 +295,8 @@ export class Menubar extends EventEmitter { this._browserWindow.isAlwaysOnTop() ? this.emit('focus-lost') : (this._blurTimeout = setTimeout(() => { - this.hideWindow(); - }, 100)); + this.hideWindow(); + }, 100)); }); if (this._options.showOnAllWorkspaces !== false) { diff --git a/src/types.ts b/src/types.ts index cf37f65..7cd967b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -73,6 +73,10 @@ export interface Options { * Show the window on 'right-click' event instead of regular 'click'. */ showOnRightClick?: boolean; + /** + * Don't show the window at all if clicked + */ + disableClick?: boolean; /** * Menubar tray icon tooltip text. Calls [`tray.setTooltip`](https://electronjs.org/docs/api/tray#traysettooltiptooltip). */