diff --git a/jslib b/jslib index c29b53cd..c3dad8fd 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 f76e9f6f..6577a3d9 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 568cf00b..e4782c36 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 00000000..5ccf3921 --- /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 00000000..1f5beb6e Binary files /dev/null and b/src/images/icon.ico differ diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index e1da8713..4cb0c304 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -770,11 +770,11 @@ "disableFaviconDesc": { "message": "Website Icons provide a recognizable image next to each login item in your vault." }, - "enableHideInTray": { - "message": "Hide Bitwarden in tray" + "enableMinToTray": { + "message": "Minimize to Tray" }, - "enableHideInTrayDesc": { - "message": "Bitwarden will stay in your system tray when minimizing the window." + "enableMinToTrayDesc": { + "message": "When minimizing the window, run Bitwarden as a system tray icon." }, "language": { "message": "Language" diff --git a/src/main.ts b/src/main.ts index 285e43de..ecaa7f08 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,6 +16,7 @@ import { ElectronLogService } from 'jslib/electron/services/electronLog.service' import { ElectronMainMessagingService } from 'jslib/electron/services/electronMainMessaging.service'; import { ElectronStorageService } from 'jslib/electron/services/electronStorage.service'; import { WindowMain } from 'jslib/electron/window.main'; +import { DesktopConstants } from './desktopConstants'; export class Main { logService: ElectronLogService; @@ -68,7 +69,9 @@ export class Main { this.updaterMain = new UpdaterMain(this); this.menuMain = new MenuMain(this); this.powerMonitorMain = new PowerMonitorMain(this); - this.trayMain = new TrayMain(this); + this.trayMain = new TrayMain(this.windowMain, 'Bitwarden', async () => { + 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 5ed1a545..976ea4bb 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 e29310f9..00000000 --- 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; -}