mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
Desktop fit & finish (#212)
* Add context menu on right click to mac * Add hide dock setting * Change "hide dock" to "always show dock" * Add support on mac for minimize to menu bar on close, minimize or start * Add "openAtLogin" to ElectronConstants * Add "restoreFromTray" to TrayMainService
This commit is contained in:
@@ -7,4 +7,6 @@ export class ElectronConstants {
|
|||||||
static readonly minimizeOnCopyToClipboardKey: string = 'minimizeOnCopyToClipboardKey';
|
static readonly minimizeOnCopyToClipboardKey: string = 'minimizeOnCopyToClipboardKey';
|
||||||
static readonly enableBiometric: string = 'enabledBiometric';
|
static readonly enableBiometric: string = 'enabledBiometric';
|
||||||
static readonly enableBrowserIntegration: string = 'enableBrowserIntegration';
|
static readonly enableBrowserIntegration: string = 'enableBrowserIntegration';
|
||||||
|
static readonly alwaysShowDock: string = 'alwaysShowDock';
|
||||||
|
static readonly openAtLogin: string = 'openAtLogin';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
app,
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
MenuItemConstructorOptions,
|
MenuItemConstructorOptions,
|
||||||
@@ -44,7 +45,7 @@ export class TrayMain {
|
|||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: process.platform === 'darwin' ? this.i18nService.t('close') : this.i18nService.t('exit'),
|
label: this.i18nService.t('exit'),
|
||||||
click: () => this.closeWindow(),
|
click: () => this.closeWindow(),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -52,14 +53,11 @@ export class TrayMain {
|
|||||||
menuItemOptions.splice(1, 0, ...additionalMenuItems);
|
menuItemOptions.splice(1, 0, ...additionalMenuItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform !== 'darwin') {
|
|
||||||
this.contextMenu = Menu.buildFromTemplate(menuItemOptions);
|
this.contextMenu = Menu.buildFromTemplate(menuItemOptions);
|
||||||
}
|
|
||||||
if (await this.storageService.get<boolean>(ElectronConstants.enableTrayKey)) {
|
if (await this.storageService.get<boolean>(ElectronConstants.enableTrayKey)) {
|
||||||
this.showTray();
|
this.showTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
this.windowMain.win.on('minimize', async (e: Event) => {
|
this.windowMain.win.on('minimize', async (e: Event) => {
|
||||||
if (await this.storageService.get<boolean>(ElectronConstants.enableMinimizeToTrayKey)) {
|
if (await this.storageService.get<boolean>(ElectronConstants.enableMinimizeToTrayKey)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -75,7 +73,6 @@ export class TrayMain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.windowMain.win.on('show', async (e: Event) => {
|
this.windowMain.win.on('show', async (e: Event) => {
|
||||||
const enableTray = await this.storageService.get<boolean>(ElectronConstants.enableTrayKey);
|
const enableTray = await this.storageService.get<boolean>(ElectronConstants.enableTrayKey);
|
||||||
@@ -96,11 +93,20 @@ export class TrayMain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hideToTray() {
|
async hideToTray() {
|
||||||
this.showTray();
|
this.showTray();
|
||||||
if (this.windowMain.win != null) {
|
if (this.windowMain.win != null) {
|
||||||
this.windowMain.win.hide();
|
this.windowMain.win.hide();
|
||||||
}
|
}
|
||||||
|
if (this.isDarwin() && !await this.storageService.get<boolean>(ElectronConstants.alwaysShowDock)) {
|
||||||
|
this.hideDock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreFromTray() {
|
||||||
|
if (this.windowMain.win == null || !this.windowMain.win.isVisible()) {
|
||||||
|
this.toggleWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showTray() {
|
showTray() {
|
||||||
@@ -111,29 +117,49 @@ export class TrayMain {
|
|||||||
this.tray = new Tray(this.icon);
|
this.tray = new Tray(this.icon);
|
||||||
this.tray.setToolTip(this.appName);
|
this.tray.setToolTip(this.appName);
|
||||||
this.tray.on('click', () => this.toggleWindow());
|
this.tray.on('click', () => this.toggleWindow());
|
||||||
|
this.tray.on('right-click', () => this.tray.popUpContextMenu(this.contextMenu));
|
||||||
|
|
||||||
if (this.pressedIcon != null) {
|
if (this.pressedIcon != null) {
|
||||||
this.tray.setPressedImage(this.pressedIcon);
|
this.tray.setPressedImage(this.pressedIcon);
|
||||||
}
|
}
|
||||||
if (this.contextMenu != null) {
|
if (this.contextMenu != null && !this.isDarwin()) {
|
||||||
this.tray.setContextMenu(this.contextMenu);
|
this.tray.setContextMenu(this.contextMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private toggleWindow() {
|
private hideDock() {
|
||||||
|
app.dock.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
private showDock() {
|
||||||
|
app.dock.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private isDarwin() {
|
||||||
|
return process.platform === 'darwin';
|
||||||
|
}
|
||||||
|
|
||||||
|
private async toggleWindow() {
|
||||||
if (this.windowMain.win == null) {
|
if (this.windowMain.win == null) {
|
||||||
if (process.platform === 'darwin') {
|
if (this.isDarwin()) {
|
||||||
// On MacOS, closing the window via the red button destroys the BrowserWindow instance.
|
// On MacOS, closing the window via the red button destroys the BrowserWindow instance.
|
||||||
this.windowMain.createWindow().then(() => {
|
this.windowMain.createWindow().then(() => {
|
||||||
this.windowMain.win.show();
|
this.windowMain.win.show();
|
||||||
|
this.showDock();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.windowMain.win.isVisible()) {
|
if (this.windowMain.win.isVisible()) {
|
||||||
this.windowMain.win.hide();
|
this.windowMain.win.hide();
|
||||||
|
if (this.isDarwin() && !await this.storageService.get<boolean>(ElectronConstants.alwaysShowDock)) {
|
||||||
|
this.hideDock();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.windowMain.win.show();
|
this.windowMain.win.show();
|
||||||
|
if (this.isDarwin()) {
|
||||||
|
this.showDock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class WindowMain {
|
|||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
// On OS X it is common for applications and their menu bar
|
// On OS X it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== 'darwin' || isMacAppStore()) {
|
if (process.platform !== 'darwin' || this.isQuitting || isMacAppStore()) {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user