1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-24 11:55:50 +01:00

add menu for tray on linux

This commit is contained in:
Kyle Spearrin 2018-05-04 17:24:31 -04:00
parent 18feb238a7
commit 0e82da9bdc
2 changed files with 22 additions and 9 deletions

2
jslib

@ -1 +1 @@
Subproject commit 2032e14285ac3d4b2f3e9e310ad19ca1dd40c525
Subproject commit 36dfdf24f146062447d2b8884fbf84981ecff664

View File

@ -1,4 +1,5 @@
import {
Menu,
nativeImage,
Tray,
} from 'electron';
@ -10,6 +11,7 @@ import { DesktopConstants } from '../desktopConstants';
export class TrayMain {
private tray: Tray;
private menu: Menu;
private icon: string | Electron.NativeImage;
private pressedIcon: Electron.NativeImage;
@ -27,6 +29,13 @@ export class TrayMain {
}
init() {
if (process.platform === 'linux') {
this.menu = Menu.buildFromTemplate([{
label: this.appName,
click: () => this.open(),
}]);
}
this.windowMain.win.on('minimize', async (e: Event) => {
if (await this.minToTray()) {
e.preventDefault();
@ -52,15 +61,19 @@ export class TrayMain {
if (this.pressedIcon != null) {
this.tray.setPressedImage(this.pressedIcon);
}
if (this.menu != null) {
this.tray.setContextMenu(this.menu);
}
this.tray.on('click', () => {
if (this.windowMain.win.isVisible()) {
this.windowMain.win.hide();
} else {
this.windowMain.win.show();
}
});
this.tray.on('click', () => open());
this.windowMain.win.hide();
}
private open() {
if (this.windowMain.win.isVisible()) {
this.windowMain.win.hide();
} else {
this.windowMain.win.show();
}
}
}