From db0986e95f809aa1fd92d5ca15cb2283f8bbf244 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 4 May 2018 13:16:12 -0400 Subject: [PATCH] some fixes for tray icon --- jslib | 2 +- src/app/accounts/settings.component.html | 30 +++++++++---------- src/app/accounts/settings.component.ts | 13 ++++---- src/desktopConstants.ts | 3 ++ src/images/icon.ico | Bin 0 -> 20221 bytes src/locales/en/messages.json | 8 ++--- src/main.ts | 5 +++- src/main/tray.main.ts | 36 +++++++++++++---------- src/services/desktopconstants.service.ts | 5 ---- 9 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 src/desktopConstants.ts create mode 100644 src/images/icon.ico delete mode 100644 src/services/desktopconstants.service.ts diff --git a/jslib b/jslib index c29b53cdd6..c3dad8fd1a 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit c29b53cdd62369de59f6ae483b78b9bcc67d9238 +Subproject commit c3dad8fd1ae862476ccc417b4d33eecd3edd61a9 diff --git a/src/app/accounts/settings.component.html b/src/app/accounts/settings.component.html index f76e9f6f3b..6577a3d96c 100644 --- a/src/app/accounts/settings.component.html +++ b/src/app/accounts/settings.component.html @@ -22,16 +22,6 @@ {{'options' | i18n}}
-
-
- -
- {{'gaDesc' | i18n}} -
-
- {{'enableHideInTrayDesc' | i18n}} + {{'enableMinToTrayDesc' | i18n}} +
+
+
+ +
+ {{'gaDesc' | i18n}}
diff --git a/src/app/accounts/settings.component.ts b/src/app/accounts/settings.component.ts index 568cf00b5f..e4782c3662 100644 --- a/src/app/accounts/settings.component.ts +++ b/src/app/accounts/settings.component.ts @@ -14,7 +14,8 @@ import { StateService } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { ConstantsService } from 'jslib/services/constants.service'; -import { DesktopConstantsService } from '../../services/desktopconstants.service'; + +import { DesktopConstants } from '../../desktopConstants'; @Component({ selector: 'app-settings', @@ -24,7 +25,7 @@ export class SettingsComponent implements OnInit { lockOption: number = null; disableGa: boolean = false; disableFavicons: boolean = false; - enableHideInTray: boolean = false; + enableMinToTray: boolean = false; locale: string; lockOptions: any[]; localeOptions: any[]; @@ -57,7 +58,7 @@ export class SettingsComponent implements OnInit { async ngOnInit() { this.lockOption = await this.storageService.get(ConstantsService.lockOptionKey); this.disableFavicons = await this.storageService.get(ConstantsService.disableFaviconKey); - this.enableHideInTray = await this.storageService.get(DesktopConstantsService.enableHideInTrayKey); + this.enableMinToTray = await this.storageService.get(DesktopConstants.enableMinimizeToTrayKey); this.locale = await this.storageService.get(ConstantsService.localeKey); const disableGa = await this.storageService.get(ConstantsService.disableGaKey); @@ -86,9 +87,9 @@ export class SettingsComponent implements OnInit { this.callAnalytics('Favicons', !this.disableFavicons); } - async saveHideInTray() { - await this.storageService.save(DesktopConstantsService.enableHideInTrayKey, this.enableHideInTray); - this.callAnalytics('HideInTray', this.enableHideInTray); + async saveMinToTray() { + await this.storageService.save(DesktopConstants.enableMinimizeToTrayKey, this.enableMinToTray); + this.callAnalytics('MinimizeToTray', this.enableMinToTray); } async saveLocale() { diff --git a/src/desktopConstants.ts b/src/desktopConstants.ts new file mode 100644 index 0000000000..5ccf392147 --- /dev/null +++ b/src/desktopConstants.ts @@ -0,0 +1,3 @@ +export class DesktopConstants { + static readonly enableMinimizeToTrayKey: string = 'enableMinimizeToTray'; +} diff --git a/src/images/icon.ico b/src/images/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..1f5beb6ed2aae796a05f8c0558f3281058f31443 GIT binary patch literal 20221 zcmeHO2RxPS`+w{*LK0=BGAg1Wafl+yYgQClNmOQb)@dlRN716BlI)B)#<68&%R2TR z$H;N)=l?u<^;anU-g@8P`~P=;KDT?E=f1A*b=}v!F91LQ5Ci=D0F<%=VcP-VC;$NL z?0=SN000Zs(LgEuy8$r(+!KU8fC5|w=>T9(7y!7TGDHH<{<9uRz8i|~?0LYfpXwzPwh9c!#_@Z z?3>r`yJy|=w?D`Hvv!vcPIe8INXkmt~~PrgXIs*`?cAHe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21K^Q}|H_v2a%RvpC>x?)uK(P4H#Pg^rHHJQu2V$*B z9HWWvSzRn>wR?^9+PixOB&OwAlsd0*5uXl6QFH8el~F!<9oL?0ezzt`H-StXx=(rP z8y7+b*i6m%$uQ6!3+Iha-#O`HmXKms&I$lA*4V142lvQ^=rY+X@rOG&3GN+Dpl(do z#cHGran$MCiMeb(cr>R+kDR7Ahq!D>jErDF8H)*6zgusjHGYsGm_+=>Lxyc0 zYimcv{M+UTs+gHo6}^lDtzIXhX7$_Mf&q``2oXmIG&v=0fk<0s>l(=@8d`#lB)ppj z^50QUjFGokY}GvD@P<50^{(<(2!+K{V&4~rm%H*dHDxr}2|zb80CX90HM3rXcn=fD z)~7aAG?RA+0K$*L);nj4`<+GQXwB#@=Jdb5#S_a)!Y{>BEn$5~l0!Khsc?hf%v;?3 z2EnJTC-E*cW(20k!GmtP^_&)rMy`L{jtwNxe8t8HPbhj3kzX+eGN~?)cp)yM*`JV&5Le hIMDuB@X45^;;lejHG9sh1K$@OlaiN=I;?&De*ia { + return await this.storageService.get(DesktopConstants.enableMinimizeToTrayKey); + }); this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => { this.messagingMain.onMessage(message); diff --git a/src/main/tray.main.ts b/src/main/tray.main.ts index 5ed1a54542..976ea4bbec 100644 --- a/src/main/tray.main.ts +++ b/src/main/tray.main.ts @@ -1,34 +1,37 @@ import { Tray } from 'electron'; -import * as Path from 'path'; -import { Main } from '../main'; -import { DesktopConstantsService } from '../services/desktopconstants.service'; +import * as path from 'path'; + +import { WindowMain } from 'jslib/electron/window.main'; + +import { DesktopConstants } from '../desktopConstants'; export class TrayMain { private tray: Tray; private iconPath: string; - constructor(private main: Main) { + constructor(private windowMain: WindowMain, private appName: string, private minToTray: () => Promise) { if (process.platform === 'win32') { - this.iconPath = Path.join(__dirname, '../resources/icon.ico'); + this.iconPath = path.join(__dirname, '/images/icon.ico'); } else { - this.iconPath = Path.join(__dirname, '../resources/icon.png'); + this.iconPath = path.join(__dirname, '/images/icon.png'); } } init() { - this.main.windowMain.win.on('minimize', async (event: Event) => { - if (await this.main.storageService.get(DesktopConstantsService.enableHideInTrayKey)) { - event.preventDefault(); + this.windowMain.win.on('minimize', async (e: Event) => { + if (await this.minToTray()) { + e.preventDefault(); await this.handleHideEvent(); } }); - this.main.windowMain.win.on('show', async (event: Event) => { + + this.windowMain.win.on('show', async (e: Event) => { await this.handleShowEvent(); }); } private handleShowEvent() { - if (this.tray) { + if (this.tray != null) { this.tray.destroy(); this.tray = null; } @@ -36,13 +39,16 @@ export class TrayMain { private handleHideEvent() { this.tray = new Tray(this.iconPath); + this.tray.setToolTip(this.appName); + this.tray.on('click', () => { - if (this.main.windowMain.win.isVisible()) { - this.main.windowMain.win.hide(); + if (this.windowMain.win.isVisible()) { + this.windowMain.win.hide(); } else { - this.main.windowMain.win.show(); + this.windowMain.win.show(); } }); - this.main.windowMain.win.hide(); + + this.windowMain.win.hide(); } } diff --git a/src/services/desktopconstants.service.ts b/src/services/desktopconstants.service.ts deleted file mode 100644 index e29310f97f..0000000000 --- a/src/services/desktopconstants.service.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class DesktopConstantsService { - static readonly enableHideInTrayKey: string = 'enableHideInTray'; - - readonly enableHideInTrayKey: string = DesktopConstantsService.enableHideInTrayKey; -}