1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

Tray icon (#84)

* Implemented configurable tray icon

* Fixed calls to callAnalytics using wrong indicators
This commit is contained in:
tstumm 2018-05-04 18:45:42 +02:00 committed by Kyle Spearrin
parent c612f3487b
commit 0f2d1e73b4
7 changed files with 83 additions and 2 deletions

2
jslib

@ -1 +1 @@
Subproject commit c3dad8fd1ae862476ccc417b4d33eecd3edd61a9
Subproject commit c29b53cdd62369de59f6ae483b78b9bcc67d9238

View File

@ -42,6 +42,16 @@
</div>
<small class="help-block">{{'disableFaviconDesc' | i18n}}</small>
</div>
<div class="form-group">
<div class="checkbox">
<label for="enableHideInTray">
<input id="enableHideInTray" type="checkbox" name="EnableHideInTray"
[(ngModel)]="enableHideInTray" (change)="saveHideInTray()">
{{'enableHideInTray' | i18n}}
</label>
</div>
<small class="help-block">{{'enableHideInTrayDesc' | i18n}}</small>
</div>
<div class="form-group">
<label for="locale">{{'language' | i18n}}</label>
<select id="locale" name="Locale" [(ngModel)]="locale" (change)="saveLocale()">

View File

@ -14,6 +14,7 @@ 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';
@Component({
selector: 'app-settings',
@ -23,6 +24,7 @@ export class SettingsComponent implements OnInit {
lockOption: number = null;
disableGa: boolean = false;
disableFavicons: boolean = false;
enableHideInTray: boolean = false;
locale: string;
lockOptions: any[];
localeOptions: any[];
@ -55,6 +57,7 @@ export class SettingsComponent implements OnInit {
async ngOnInit() {
this.lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
this.enableHideInTray = await this.storageService.get<boolean>(DesktopConstantsService.enableHideInTrayKey);
this.locale = await this.storageService.get<string>(ConstantsService.localeKey);
const disableGa = await this.storageService.get<boolean>(ConstantsService.disableGaKey);
@ -80,7 +83,12 @@ export class SettingsComponent implements OnInit {
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicons);
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicons);
this.messagingService.send('refreshCiphers');
this.callAnalytics('Favicons', !this.disableGa);
this.callAnalytics('Favicons', !this.disableFavicons);
}
async saveHideInTray() {
await this.storageService.save(DesktopConstantsService.enableHideInTrayKey, this.enableHideInTray);
this.callAnalytics('HideInTray', this.enableHideInTray);
}
async saveLocale() {

View File

@ -770,6 +770,12 @@
"disableFaviconDesc": {
"message": "Website Icons provide a recognizable image next to each login item in your vault."
},
"enableHideInTray": {
"message": "Hide Bitwarden in tray"
},
"enableHideInTrayDesc": {
"message": "Bitwarden will stay in your system tray when minimizing the window."
},
"language": {
"message": "Language"
},

View File

@ -6,6 +6,7 @@ import { I18nService } from './services/i18n.service';
import { MenuMain } from './main/menu.main';
import { MessagingMain } from './main/messaging.main';
import { PowerMonitorMain } from './main/powerMonitor.main';
import { TrayMain } from './main/tray.main';
import { UpdaterMain } from './main/updater.main';
import { ConstantsService } from 'jslib/services/constants.service';
@ -28,6 +29,7 @@ export class Main {
updaterMain: UpdaterMain;
menuMain: MenuMain;
powerMonitorMain: PowerMonitorMain;
trayMain: TrayMain;
constructor() {
// Set paths for portable builds
@ -66,6 +68,7 @@ export class Main {
this.updaterMain = new UpdaterMain(this);
this.menuMain = new MenuMain(this);
this.powerMonitorMain = new PowerMonitorMain(this);
this.trayMain = new TrayMain(this);
this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => {
this.messagingMain.onMessage(message);
@ -82,6 +85,7 @@ export class Main {
this.messagingMain.init();
this.menuMain.init();
this.powerMonitorMain.init();
this.trayMain.init();
await this.updaterMain.init();
}, (e: any) => {
// tslint:disable-next-line

48
src/main/tray.main.ts Normal file
View File

@ -0,0 +1,48 @@
import { Tray } from 'electron';
import * as Path from 'path';
import { Main } from '../main';
import { DesktopConstantsService } from '../services/desktopconstants.service';
export class TrayMain {
private tray: Tray;
private iconPath: string;
constructor(private main: Main) {
if (process.platform === 'win32') {
this.iconPath = Path.join(__dirname, '../resources/icon.ico');
} else {
this.iconPath = Path.join(__dirname, '../resources/icon.png');
}
}
init() {
this.main.windowMain.win.on('minimize', async (event: Event) => {
if (await this.main.storageService.get<boolean>(DesktopConstantsService.enableHideInTrayKey)) {
event.preventDefault();
await this.handleHideEvent();
}
});
this.main.windowMain.win.on('show', async (event: Event) => {
await this.handleShowEvent();
});
}
private handleShowEvent() {
if (this.tray) {
this.tray.destroy();
this.tray = null;
}
}
private handleHideEvent() {
this.tray = new Tray(this.iconPath);
this.tray.on('click', () => {
if (this.main.windowMain.win.isVisible()) {
this.main.windowMain.win.hide();
} else {
this.main.windowMain.win.show();
}
});
this.main.windowMain.win.hide();
}
}

View File

@ -0,0 +1,5 @@
export class DesktopConstantsService {
static readonly enableHideInTrayKey: string = 'enableHideInTray';
readonly enableHideInTrayKey: string = DesktopConstantsService.enableHideInTrayKey;
}