From 002dd2752b760320615a5d62b407e89f6686b12b Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 20 Nov 2020 14:05:50 +0100 Subject: [PATCH 1/9] Add setting for toggling hide dock --- src/app/accounts/settings.component.html | 10 ++++++++++ src/app/accounts/settings.component.ts | 8 ++++++++ src/locales/en/messages.json | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/src/app/accounts/settings.component.html b/src/app/accounts/settings.component.html index f54b90a2d7..9fef93a2ee 100644 --- a/src/app/accounts/settings.component.html +++ b/src/app/accounts/settings.component.html @@ -128,6 +128,16 @@ {{'startToTrayDesc' | i18n}} +
+
+ +
+ {{'hideDockDesc' | i18n}} +
- {{'hideDock' | i18n}} +
- {{'hideDockDesc' | i18n}} + {{'alwaysShowDockDesc' | i18n}}
diff --git a/src/app/accounts/settings.component.ts b/src/app/accounts/settings.component.ts index 3e5dcf3acc..7ceda1fd11 100644 --- a/src/app/accounts/settings.component.ts +++ b/src/app/accounts/settings.component.ts @@ -51,8 +51,8 @@ export class SettingsComponent implements OnInit { supportsBiometric: boolean; biometric: boolean; biometricText: string; - hideDock: boolean; - showHideDock: boolean = false; + alwaysShowDock: boolean; + showAlwaysShowDock: boolean = false; constructor(private analytics: Angulartics2, private toasterService: ToasterService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, @@ -133,8 +133,8 @@ export class SettingsComponent implements OnInit { this.supportsBiometric = await this.platformUtilsService.supportsBiometric(); this.biometric = await this.vaultTimeoutService.isBiometricLockSet(); this.biometricText = await this.storageService.get(ConstantsService.biometricText); - this.hideDock = await this.storageService.get(ElectronConstants.hideDock); - this.showHideDock = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop; + this.alwaysShowDock = await this.storageService.get(ElectronConstants.alwaysShowDock); + this.showAlwaysShowDock = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop; } async saveVaultTimeoutOptions() { @@ -281,8 +281,8 @@ export class SettingsComponent implements OnInit { }); } - async saveHideDock() { - await this.storageService.save(ElectronConstants.hideDock, this.hideDock); + async saveAlwaysShowDock() { + await this.storageService.save(ElectronConstants.alwaysShowDock, this.alwaysShowDock); } private callAnalytics(name: string, enabled: boolean) { diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 9d75ebcde4..27cd720c76 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -870,11 +870,11 @@ "startToTrayDesc": { "message": "When the application is first started, only show an icon in the system tray." }, - "hideDock": { - "message": "Hide dock icon" + "alwaysShowDock": { + "message": "Always show in the Dock" }, - "hideDockDesc": { - "message": "Hide Bitwarden from the Dock when minimized to the menu bar." + "alwaysShowDockDesc": { + "message": "Show the Bitwarden icon in the Dock even when minimized to the menu bar." }, "language": { "message": "Language" From 2cbe7f3d0a888fbf80455c28999ab339250d89e8 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 20 Nov 2020 17:20:51 +0100 Subject: [PATCH 4/9] Add support on mac for minimize to menu bar on close, minimize or start --- src/app/accounts/settings.component.html | 12 ++++----- src/app/accounts/settings.component.ts | 31 ++++++++++++++++++++---- src/locales/en/messages.json | 18 ++++++++++++++ 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/app/accounts/settings.component.html b/src/app/accounts/settings.component.html index 496cc085f5..bd790948e4 100644 --- a/src/app/accounts/settings.component.html +++ b/src/app/accounts/settings.component.html @@ -103,30 +103,30 @@
- {{'enableMinToTrayDesc' | i18n}} + {{enableMinToTrayDescText}}
- {{'enableCloseToTrayDesc' | i18n}} + {{enableCloseToTrayDescText}}
- {{'startToTrayDesc' | i18n}} + {{startToTrayDescText}}
diff --git a/src/app/accounts/settings.component.ts b/src/app/accounts/settings.component.ts index 7ceda1fd11..8563296e2e 100644 --- a/src/app/accounts/settings.component.ts +++ b/src/app/accounts/settings.component.ts @@ -46,23 +46,44 @@ export class SettingsComponent implements OnInit { themeOptions: any[]; clearClipboard: number; clearClipboardOptions: any[]; - enableTrayText: string; - enableTrayDescText: string; supportsBiometric: boolean; biometric: boolean; biometricText: string; alwaysShowDock: boolean; showAlwaysShowDock: boolean = false; + enableTrayText: string; + enableTrayDescText: string; + enableMinToTrayText: string; + enableMinToTrayDescText: string; + enableCloseToTrayText: string; + enableCloseToTrayDescText: string; + startToTrayText: string; + startToTrayDescText: string; + constructor(private analytics: Angulartics2, private toasterService: ToasterService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private storageService: StorageService, private vaultTimeoutService: VaultTimeoutService, private stateService: StateService, private messagingService: MessagingService, private userService: UserService, private cryptoService: CryptoService) { - const trayKey = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop ? - 'enableMenuBar' : 'enableTray'; + const isMac = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop; + + const trayKey = isMac ? 'enableMenuBar' : 'enableTray'; this.enableTrayText = this.i18nService.t(trayKey); this.enableTrayDescText = this.i18nService.t(trayKey + 'Desc'); + + const minToTrayKey = isMac ? 'enableMinToMenuBar' : 'enableMinToTray'; + this.enableMinToTrayText = this.i18nService.t(minToTrayKey) + this.enableMinToTrayDescText = this.i18nService.t(minToTrayKey + 'Desc'); + + const closeToTrayKey = isMac ? 'enableCloseToMenuBar' : 'enableCloseToTray'; + this.enableCloseToTrayText = this.i18nService.t(closeToTrayKey) + this.enableCloseToTrayDescText = this.i18nService.t(closeToTrayKey + 'Desc'); + + const startToTrayKey = isMac ? 'startToMenuBar' : 'startToTray'; + this.startToTrayText = this.i18nService.t(startToTrayKey) + this.startToTrayDescText = this.i18nService.t(startToTrayKey + 'Desc'); + this.vaultTimeouts = [ // { name: i18nService.t('immediately'), value: 0 }, { name: i18nService.t('oneMinute'), value: 1 }, @@ -115,7 +136,7 @@ export class SettingsComponent implements OnInit { } async ngOnInit() { - this.showMinToTray = this.platformUtilsService.getDevice() === DeviceType.WindowsDesktop; + this.showMinToTray = this.platformUtilsService.getDevice() !== DeviceType.LinuxDesktop; this.vaultTimeout = await this.storageService.get(ConstantsService.vaultTimeoutKey); this.vaultTimeoutAction = await this.storageService.get(ConstantsService.vaultTimeoutActionKey); const pinSet = await this.vaultTimeoutService.isPinLockSet(); diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 27cd720c76..dab599731e 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -852,12 +852,24 @@ "enableMinToTrayDesc": { "message": "When minimizing the window, show an icon in the system tray instead." }, + "enableMinToMenuBar": { + "message": "Minimize to menu bar" + }, + "enableMinToMenuBarDesc": { + "message": "When minimizing the window, show an icon in the menu bar instead." + }, "enableCloseToTray": { "message": "Close to Tray Icon" }, "enableCloseToTrayDesc": { "message": "When closing the window, show an icon in the system tray instead." }, + "enableCloseToMenuBar": { + "message": "Close to menu bar" + }, + "enableCloseToMenuBarDesc": { + "message": "When closing the window, show an icon in the menu bar instead." + }, "enableTray": { "message": "Enable Tray Icon" }, @@ -870,6 +882,12 @@ "startToTrayDesc": { "message": "When the application is first started, only show an icon in the system tray." }, + "startToMenuBar": { + "message": "Start to menu bar" + }, + "startToMenuBarDesc": { + "message": "When the application is first started, only show an icon in the menu bar." + }, "alwaysShowDock": { "message": "Always show in the Dock" }, From f926f80d8c595bd9bc3ad684f0797e8ed1a3d3b0 Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 23 Nov 2020 15:04:35 +0100 Subject: [PATCH 5/9] Wip start on login --- src/app/accounts/settings.component.html | 10 ++++++++++ src/app/accounts/settings.component.ts | 5 +++++ src/locales/en/messages.json | 6 ++++++ src/main/messaging.main.ts | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/src/app/accounts/settings.component.html b/src/app/accounts/settings.component.html index bd790948e4..af7aa285ec 100644 --- a/src/app/accounts/settings.component.html +++ b/src/app/accounts/settings.component.html @@ -128,6 +128,16 @@
{{startToTrayDescText}}
+
+
+ +
+ {{'startOnLoginDesc' | i18n}} +
-
- {{'startOnLoginDesc' | i18n}} + {{'openAtLoginDesc' | i18n}}
diff --git a/src/app/accounts/settings.component.ts b/src/app/accounts/settings.component.ts index 6f670f0485..111993fc8e 100644 --- a/src/app/accounts/settings.component.ts +++ b/src/app/accounts/settings.component.ts @@ -51,7 +51,7 @@ export class SettingsComponent implements OnInit { biometricText: string; alwaysShowDock: boolean; showAlwaysShowDock: boolean = false; - startOnLogin: boolean; + openAtLogin: boolean; enableTrayText: string; enableTrayDescText: string; @@ -157,6 +157,7 @@ export class SettingsComponent implements OnInit { this.biometricText = await this.storageService.get(ConstantsService.biometricText); this.alwaysShowDock = await this.storageService.get(ElectronConstants.alwaysShowDock); this.showAlwaysShowDock = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop; + this.openAtLogin = await this.storageService.get(ElectronConstants.openAtLogin); } async saveVaultTimeoutOptions() { @@ -307,8 +308,9 @@ export class SettingsComponent implements OnInit { await this.storageService.save(ElectronConstants.alwaysShowDock, this.alwaysShowDock); } - async saveStartOnLogin() { - this.messagingService.send(this.startOnLogin ? 'addOpenAtLogin' : 'removeOpenAtLogin'); + async saveOpenAtLogin() { + this.storageService.save(ElectronConstants.openAtLogin, this.openAtLogin); + this.messagingService.send(this.openAtLogin ? 'addOpenAtLogin' : 'removeOpenAtLogin'); } private callAnalytics(name: string, enabled: boolean) { diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 519794e745..2ec24da91c 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -888,10 +888,10 @@ "startToMenuBarDesc": { "message": "When the application is first started, only show an icon in the menu bar." }, - "startOnLogin": { + "openAtLogin": { "message": "Start automatically on login" }, - "startOnLoginDesc": { + "openAtLoginDesc": { "message": "Start the Bitwarden Desktop application automatically on login." }, "alwaysShowDock": { diff --git a/src/main/messaging.main.ts b/src/main/messaging.main.ts index 208a23ff4f..338244fe24 100644 --- a/src/main/messaging.main.ts +++ b/src/main/messaging.main.ts @@ -1,4 +1,4 @@ -import { ipcMain } from 'electron'; +import { app, ipcMain } from 'electron'; import { Main } from '../main'; @@ -15,6 +15,10 @@ export class MessagingMain { init() { this.scheduleNextSync(); + if (process.platform !== 'linux') { + const loginSettings = app.getLoginItemSettings(); + this.storageService.save(ElectronConstants.openAtLogin, loginSettings.openAtLogin); + } ipcMain.on('messagingService', async (event: any, message: any) => this.onMessage(message)); } @@ -44,9 +48,15 @@ export class MessagingMain { case 'hideToTray': this.main.trayMain.hideToTray(); break; - case 'addStartOnLogin': + case 'addOpenAtLogin': + if (process.platform !== 'linux') { + app.setLoginItemSettings({openAtLogin: true}); + } break; - case 'removeStartOnLogin': + case 'removeOpenAtLogin': + if (process.platform !== 'linux') { + app.setLoginItemSettings({openAtLogin: false}); + } break; default: break; From 75d26de5815b6d4f40ddee98b45ddac2fb0a63d3 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 27 Nov 2020 10:58:47 +0100 Subject: [PATCH 7/9] Add support for linux autostart --- src/main/messaging.main.ts | 42 ++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main/messaging.main.ts b/src/main/messaging.main.ts index 338244fe24..41925bb1dd 100644 --- a/src/main/messaging.main.ts +++ b/src/main/messaging.main.ts @@ -1,4 +1,6 @@ import { app, ipcMain } from 'electron'; +import * as fs from 'fs'; +import * as path from 'path'; import { Main } from '../main'; @@ -49,14 +51,10 @@ export class MessagingMain { this.main.trayMain.hideToTray(); break; case 'addOpenAtLogin': - if (process.platform !== 'linux') { - app.setLoginItemSettings({openAtLogin: true}); - } + this.addOpenAtLogin(); break; case 'removeOpenAtLogin': - if (process.platform !== 'linux') { - app.setLoginItemSettings({openAtLogin: false}); - } + this.removeOpenAtLogin(); break; default: break; @@ -88,4 +86,36 @@ export class MessagingMain { lockNowTrayMenuItem.enabled = isAuthenticated && !isLocked; } } + + private addOpenAtLogin() { + if (process.platform === 'linux') { + const data = `[Desktop Entry] + Type=Application + Version=${app.getVersion()} + Name=Bitwarden + Comment=Bitwarden startup script + Exec=${app.getPath('exe')} + StartupNotify=false + Terminal=false`; + + fs.writeFileSync(this.linuxStartupFile(), data); + } else { + app.setLoginItemSettings({openAtLogin: true}); + } + } + + private removeOpenAtLogin() { + if (process.platform === 'linux') { + const file = this.linuxStartupFile(); + if (fs.existsSync(file)) { + fs.unlinkSync(file); + } + } else { + app.setLoginItemSettings({openAtLogin: false}); + } + } + + private linuxStartupFile(): string { + return path.join(app.getPath('home'), '.config', 'autostart', 'bitwarden.desktop'); + } } From 0cd196f56c51b3fc5c8498b7c6813092856c8437 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 27 Nov 2020 11:34:09 +0100 Subject: [PATCH 8/9] Fix linux not creating the autostart dir if not exist --- src/main/messaging.main.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/messaging.main.ts b/src/main/messaging.main.ts index 41925bb1dd..720e6fe999 100644 --- a/src/main/messaging.main.ts +++ b/src/main/messaging.main.ts @@ -17,7 +17,9 @@ export class MessagingMain { init() { this.scheduleNextSync(); - if (process.platform !== 'linux') { + if (process.platform === 'linux') { + this.storageService.save(ElectronConstants.openAtLogin, fs.existsSync(this.linuxStartupFile())); + } else { const loginSettings = app.getLoginItemSettings(); this.storageService.save(ElectronConstants.openAtLogin, loginSettings.openAtLogin); } @@ -98,6 +100,10 @@ export class MessagingMain { StartupNotify=false Terminal=false`; + const dir = path.dirname(this.linuxStartupFile()); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } fs.writeFileSync(this.linuxStartupFile(), data); } else { app.setLoginItemSettings({openAtLogin: true}); @@ -106,9 +112,8 @@ export class MessagingMain { private removeOpenAtLogin() { if (process.platform === 'linux') { - const file = this.linuxStartupFile(); - if (fs.existsSync(file)) { - fs.unlinkSync(file); + if (fs.existsSync(this.linuxStartupFile())) { + fs.unlinkSync(this.linuxStartupFile()); } } else { app.setLoginItemSettings({openAtLogin: false}); From 91b186ae5d2fc8f6359940afb8d9d8116568e4ad Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 27 Nov 2020 16:33:16 +0100 Subject: [PATCH 9/9] Enable closeToTray and startToTray on linux --- src/app/accounts/settings.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/accounts/settings.component.html b/src/app/accounts/settings.component.html index f76566c601..6f11bd8074 100644 --- a/src/app/accounts/settings.component.html +++ b/src/app/accounts/settings.component.html @@ -108,7 +108,7 @@
{{enableMinToTrayDescText}}
-
+
-
+