Merge pull request #601 from Hinton/feature/fit-finish

Desktop fit & finish
This commit is contained in:
Chad Scharf 2020-12-04 12:41:03 -05:00 committed by GitHub
commit fcbd43a9f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 148 additions and 14 deletions

View File

@ -113,30 +113,50 @@
<label for="enableMinToTray">
<input id="enableMinToTray" type="checkbox" name="EnableMinToTray"
[(ngModel)]="enableMinToTray" (change)="saveMinToTray()">
{{'enableMinToTray' | i18n}}
{{enableMinToTrayText}}
</label>
</div>
<small class="help-block">{{'enableMinToTrayDesc' | i18n}}</small>
<small class="help-block">{{enableMinToTrayDescText}}</small>
</div>
<div class="form-group" *ngIf="showMinToTray">
<div class="form-group">
<div class="checkbox">
<label for="enableCloseToTray">
<input id="enableCloseToTray" type="checkbox" name="EnableCloseToTray"
[(ngModel)]="enableCloseToTray" (change)="saveCloseToTray()">
{{'enableCloseToTray' | i18n}}
{{enableCloseToTrayText}}
</label>
</div>
<small class="help-block">{{'enableCloseToTrayDesc' | i18n}}</small>
<small class="help-block">{{enableCloseToTrayDescText}}</small>
</div>
<div class="form-group" *ngIf="showMinToTray">
<div class="form-group">
<div class="checkbox">
<label for="startToTray">
<input id="startToTray" type="checkbox" name="StartToTray" [(ngModel)]="startToTray"
(change)="saveStartToTray()">
{{'startToTray' | i18n}}
{{startToTrayText}}
</label>
</div>
<small class="help-block">{{'startToTrayDesc' | i18n}}</small>
<small class="help-block">{{startToTrayDescText}}</small>
</div>
<div class="form-group">
<div class="checkbox">
<label for="openAtLogin">
<input id="openAtLogin" type="checkbox" name="OpenAtLogin" [(ngModel)]="openAtLogin"
(change)="saveOpenAtLogin()">
{{'openAtLogin' | i18n}}
</label>
</div>
<small class="help-block">{{'openAtLoginDesc' | i18n}}</small>
</div>
<div class="form-group" *ngIf="showAlwaysShowDock">
<div class="checkbox">
<label for="alwaysShowDock">
<input id="alwaysShowDock" type="checkbox" name="AlwaysShowDock" [(ngModel)]="alwaysShowDock"
(change)="saveAlwaysShowDock()">
{{'alwaysShowDock' | i18n}}
</label>
</div>
<small class="help-block">{{'alwaysShowDockDesc' | i18n}}</small>
</div>
<div class="form-group">
<label for="theme">{{'theme' | i18n}}</label>

View File

@ -47,21 +47,45 @@ 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;
openAtLogin: boolean;
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 },
@ -114,7 +138,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<number>(ConstantsService.vaultTimeoutKey);
this.vaultTimeoutAction = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
const pinSet = await this.vaultTimeoutService.isPinLockSet();
@ -133,6 +157,9 @@ export class SettingsComponent implements OnInit {
this.supportsBiometric = await this.platformUtilsService.supportsBiometric();
this.biometric = await this.vaultTimeoutService.isBiometricLockSet();
this.biometricText = await this.storageService.get<string>(ConstantsService.biometricText);
this.alwaysShowDock = await this.storageService.get<boolean>(ElectronConstants.alwaysShowDock);
this.showAlwaysShowDock = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop;
this.openAtLogin = await this.storageService.get<boolean>(ElectronConstants.openAtLogin);
}
async saveVaultTimeoutOptions() {
@ -279,6 +306,15 @@ export class SettingsComponent implements OnInit {
});
}
async saveAlwaysShowDock() {
await this.storageService.save(ElectronConstants.alwaysShowDock, this.alwaysShowDock);
}
async saveOpenAtLogin() {
this.storageService.save(ElectronConstants.openAtLogin, this.openAtLogin);
this.messagingService.send(this.openAtLogin ? 'addOpenAtLogin' : 'removeOpenAtLogin');
}
async saveBrowserIntegration() {
await this.storageService.save(ElectronConstants.enableBrowserIntegration, this.enableBrowserIntegration);
this.messagingService.send(this.enableBrowserIntegration ? 'enableBrowserIntegration' : 'disableBrowserIntegration');

View File

@ -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,24 @@
"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."
},
"openAtLogin": {
"message": "Start automatically on login"
},
"openAtLoginDesc": {
"message": "Start the Bitwarden Desktop application automatically on login."
},
"alwaysShowDock": {
"message": "Always show in the Dock"
},
"alwaysShowDockDesc": {
"message": "Show the Bitwarden icon in the Dock even when minimized to the menu bar."
},
"language": {
"message": "Language"
},

View File

@ -1,4 +1,6 @@
import { ipcMain } from 'electron';
import { app, ipcMain } from 'electron';
import * as fs from 'fs';
import * as path from 'path';
import { Main } from '../main';
@ -15,6 +17,12 @@ export class MessagingMain {
init() {
this.scheduleNextSync();
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);
}
ipcMain.on('messagingService', async (event: any, message: any) => this.onMessage(message));
}
@ -44,6 +52,11 @@ export class MessagingMain {
case 'hideToTray':
this.main.trayMain.hideToTray();
break;
case 'addOpenAtLogin':
this.addOpenAtLogin();
break;
case 'removeOpenAtLogin':
this.removeOpenAtLogin();
case 'setFocus':
this.setFocus();
break;
@ -86,6 +99,41 @@ export class MessagingMain {
}
}
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`;
const dir = path.dirname(this.linuxStartupFile());
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFileSync(this.linuxStartupFile(), data);
} else {
app.setLoginItemSettings({openAtLogin: true});
}
}
private removeOpenAtLogin() {
if (process.platform === 'linux') {
if (fs.existsSync(this.linuxStartupFile())) {
fs.unlinkSync(this.linuxStartupFile());
}
} else {
app.setLoginItemSettings({openAtLogin: false});
}
}
private linuxStartupFile(): string {
return path.join(app.getPath('home'), '.config', 'autostart', 'bitwarden.desktop');
}
private setFocus() {
this.main.trayMain.restoreFromTray();
this.main.windowMain.win.focusOnWebView();