mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
add menu for tray on linux
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 2032e14285...36dfdf24f1
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user