mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-28 12:35:40 +01:00
add menu for tray on linux
This commit is contained in:
parent
18feb238a7
commit
0e82da9bdc
2
jslib
2
jslib
@ -1 +1 @@
|
|||||||
Subproject commit 2032e14285ac3d4b2f3e9e310ad19ca1dd40c525
|
Subproject commit 36dfdf24f146062447d2b8884fbf84981ecff664
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Menu,
|
||||||
nativeImage,
|
nativeImage,
|
||||||
Tray,
|
Tray,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
@ -10,6 +11,7 @@ import { DesktopConstants } from '../desktopConstants';
|
|||||||
|
|
||||||
export class TrayMain {
|
export class TrayMain {
|
||||||
private tray: Tray;
|
private tray: Tray;
|
||||||
|
private menu: Menu;
|
||||||
private icon: string | Electron.NativeImage;
|
private icon: string | Electron.NativeImage;
|
||||||
private pressedIcon: Electron.NativeImage;
|
private pressedIcon: Electron.NativeImage;
|
||||||
|
|
||||||
@ -27,6 +29,13 @@ export class TrayMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
this.menu = Menu.buildFromTemplate([{
|
||||||
|
label: this.appName,
|
||||||
|
click: () => this.open(),
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
|
||||||
this.windowMain.win.on('minimize', async (e: Event) => {
|
this.windowMain.win.on('minimize', async (e: Event) => {
|
||||||
if (await this.minToTray()) {
|
if (await this.minToTray()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -52,15 +61,19 @@ export class TrayMain {
|
|||||||
if (this.pressedIcon != null) {
|
if (this.pressedIcon != null) {
|
||||||
this.tray.setPressedImage(this.pressedIcon);
|
this.tray.setPressedImage(this.pressedIcon);
|
||||||
}
|
}
|
||||||
|
if (this.menu != null) {
|
||||||
|
this.tray.setContextMenu(this.menu);
|
||||||
|
}
|
||||||
|
|
||||||
this.tray.on('click', () => {
|
this.tray.on('click', () => open());
|
||||||
if (this.windowMain.win.isVisible()) {
|
|
||||||
this.windowMain.win.hide();
|
|
||||||
} else {
|
|
||||||
this.windowMain.win.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.windowMain.win.hide();
|
this.windowMain.win.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private open() {
|
||||||
|
if (this.windowMain.win.isVisible()) {
|
||||||
|
this.windowMain.win.hide();
|
||||||
|
} else {
|
||||||
|
this.windowMain.win.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user