1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-03 17:13:47 +00: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

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();
}
}