From a1f5e31bfce97b4bbe492e24bf7d57ec2803c31a Mon Sep 17 00:00:00 2001 From: Muhamed Date: Mon, 7 Nov 2022 01:11:48 +0530 Subject: refactor: remove toggle component's duplicate --- src/lib/Tray.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/lib/Tray.ts') diff --git a/src/lib/Tray.ts b/src/lib/Tray.ts index 8e489edde..dafbb68aa 100644 --- a/src/lib/Tray.ts +++ b/src/lib/Tray.ts @@ -20,7 +20,7 @@ const INDICATOR_TRAY_INDIRECT = 'tray-indirect'; // TODO: Need to support i18n for a lot of the hard-coded strings in this file export default class TrayIcon { - trayIcon: Tray | null = null; + tray: Tray | null = null; indicator: string | number = 0; @@ -97,7 +97,9 @@ export default class TrayIcon { } _updateTrayMenu(appSettings): void { - if (!this.trayIcon) return; + if (!this.tray) { + return; + } if (appSettings && appSettings.type === 'app') { this.isAppMuted = appSettings.data.isAppMuted; // save current state after a change @@ -105,7 +107,7 @@ export default class TrayIcon { this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate(this)); if (isLinux) { - this.trayIcon.setContextMenu(this.trayMenu); + this.tray.setContextMenu(this.trayMenu); } } @@ -115,26 +117,26 @@ export default class TrayIcon { } _show(): void { - if (this.trayIcon) { + if (this.tray) { return; } - this.trayIcon = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); - this.trayIcon.setToolTip('Ferdium'); + this.tray = new Tray(this._getAsset('tray', INDICATOR_TRAY_PLAIN)); + this.tray.setToolTip('Ferdium'); this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate(this)); if (isLinux) { - this.trayIcon.setContextMenu(this.trayMenu); + this.tray.setContextMenu(this.trayMenu); } - this.trayIcon.on('click', () => { + this.tray.on('click', () => { this._toggleWindow(); }); if (isMac || isWindows) { - this.trayIcon.on('right-click', () => { - if (this.trayIcon && this.trayMenu) { - this.trayIcon.popUpContextMenu(this.trayMenu); + this.tray.on('right-click', () => { + if (this.tray && this.trayMenu) { + this.tray.popUpContextMenu(this.trayMenu); } }); } @@ -177,10 +179,10 @@ export default class TrayIcon { } _hide(): void { - if (!this.trayIcon) return; + if (!this.tray) return; - this.trayIcon.destroy(); - this.trayIcon = null; + this.tray.destroy(); + this.tray = null; if (isMac && this.themeChangeSubscriberId) { systemPreferences.unsubscribeNotification(this.themeChangeSubscriberId); @@ -216,16 +218,16 @@ export default class TrayIcon { } _refreshIcon(): void { - if (!this.trayIcon) { + if (!this.tray) { return; } - this.trayIcon.setImage( + this.tray.setImage( this._getAsset('tray', this._getAssetFromIndicator(this.indicator)), ); if (isMac && !macosVersion.isGreaterThanOrEqualTo('11')) { - this.trayIcon.setPressedImage( + this.tray.setPressedImage( this._getAsset( 'tray', `${this._getAssetFromIndicator(this.indicator)}-active`, -- cgit v1.2.3-70-g09d2