mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
Close to tray (#21)
* Close to Tray implemented * Enable Tray Icon on Linux * Remove unnecessary function * Revert 26a3a98e384cc62a94f2b213af3a6543874b3d95
This commit is contained in:
parent
5609fecbce
commit
d5308a3bf5
@ -93,7 +93,7 @@ export class BaseMenu {
|
||||
},
|
||||
{
|
||||
label: this.i18nService.t('close'),
|
||||
role: 'close',
|
||||
role: 'quit',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
export class ElectronConstants {
|
||||
static readonly enableMinimizeToTrayKey: string = 'enableMinimizeToTray';
|
||||
static readonly enableCloseToTrayKey: string = 'enableCloseToTray';
|
||||
static readonly enableTrayKey: string = 'enableTray';
|
||||
}
|
||||
|
@ -68,6 +68,17 @@ export class TrayMain {
|
||||
});
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
this.windowMain.win.on('close', async (e: Event) => {
|
||||
if (await this.storageService.get<boolean>(ElectronConstants.enableCloseToTrayKey)) {
|
||||
if(!this.windowMain.isQuitting){
|
||||
e.preventDefault();
|
||||
this.hideToTray();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.windowMain.win.on('show', async (e: Event) => {
|
||||
const enableTray = await this.storageService.get<boolean>(ElectronConstants.enableTrayKey);
|
||||
if (!enableTray) {
|
||||
@ -124,6 +135,7 @@ export class TrayMain {
|
||||
}
|
||||
|
||||
private closeWindow() {
|
||||
this.windowMain.isQuitting = true;
|
||||
if (this.windowMain.win != null) {
|
||||
this.windowMain.win.close();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ const Keys = {
|
||||
|
||||
export class WindowMain {
|
||||
win: BrowserWindow;
|
||||
isQuitting: boolean = false;
|
||||
|
||||
private windowStateChangeTimer: NodeJS.Timer;
|
||||
private windowStates: { [key: string]: any; } = {};
|
||||
@ -39,6 +40,12 @@ export class WindowMain {
|
||||
}
|
||||
}
|
||||
|
||||
// This method will be called when Electron is shutting
|
||||
// down the application.
|
||||
app.on('before-quit', () => {
|
||||
this.isQuitting = true;
|
||||
});
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
|
Loading…
Reference in New Issue
Block a user