1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-05 18:13:26 +00:00

update menu items on event messages

This commit is contained in:
Kyle Spearrin
2018-02-14 00:26:32 -05:00
parent 216c77fa25
commit 3bffbbbeb3
4 changed files with 89 additions and 11 deletions

View File

@@ -13,11 +13,57 @@ import {
import { Main } from '../main';
export class MenuMain {
menu: Menu;
updateMenuItem: MenuItem;
addNewLogin: MenuItem;
addNewItem: MenuItem;
addNewFolder: MenuItem;
syncVault: MenuItem;
settings: MenuItem;
lockNow: MenuItem;
logOut: MenuItem;
twoStepLogin: MenuItem;
changeEmail: MenuItem;
changeMasterPass: MenuItem;
premiumMembership: MenuItem;
passwordGenerator: MenuItem;
searchVault: MenuItem;
unlockedRequiredMenuItems: MenuItem[] = [];
constructor(private main: Main) { }
init() {
this.initContextMenu();
this.initApplicationMenu();
this.updateMenuItem = this.menu.getMenuItemById('checkForUpdates');
this.addNewLogin = this.menu.getMenuItemById('addNewLogin');
this.addNewItem = this.menu.getMenuItemById('addNewItem');
this.addNewFolder = this.menu.getMenuItemById('addNewFolder');
this.syncVault = this.menu.getMenuItemById('syncVault');
this.settings = this.menu.getMenuItemById('settings');
this.lockNow = this.menu.getMenuItemById('lockNow');
this.logOut = this.menu.getMenuItemById('logOut');
this.twoStepLogin = this.menu.getMenuItemById('twoStepLogin');
this.changeEmail = this.menu.getMenuItemById('changeEmail');
this.changeMasterPass = this.menu.getMenuItemById('changeMasterPass');
this.premiumMembership = this.menu.getMenuItemById('premiumMembership');
this.passwordGenerator = this.menu.getMenuItemById('passwordGenerator');
this.searchVault = this.menu.getMenuItemById('searchVault');
this.unlockedRequiredMenuItems = [
this.addNewLogin, this.addNewItem, this.addNewFolder,
this.syncVault, this.settings, this.lockNow, this.twoStepLogin, this.changeEmail,
this.changeMasterPass, this.premiumMembership, this.passwordGenerator, this.searchVault];
this.updateApplicationMenuState(false, true);
}
updateApplicationMenuState(isAuthenticated: boolean, isLocked: boolean) {
this.unlockedRequiredMenuItems.forEach((mi: MenuItem) => {
mi.enabled = isAuthenticated && !isLocked;
});
this.logOut.enabled = isAuthenticated;
}
private initContextMenu() {
@@ -67,9 +113,11 @@ export class MenuMain {
label: this.main.i18nService.t('addNewLogin'),
click: () => this.main.messagingService.send('newLogin'),
accelerator: 'CmdOrCtrl+N',
id: 'addNewLogin',
},
{
label: this.main.i18nService.t('addNewItem'),
id: 'addNewItem',
submenu: [
{
label: this.main.i18nService.t('typeLogin'),
@@ -95,11 +143,13 @@ export class MenuMain {
},
{
label: this.main.i18nService.t('addNewFolder'),
id: 'addNewFolder',
click: () => this.main.messagingService.send('newFolder'),
},
{ type: 'separator' },
{
label: this.main.i18nService.t('syncVault'),
id: 'syncVault',
click: () => this.main.messagingService.send('syncVault'),
},
],
@@ -122,11 +172,13 @@ export class MenuMain {
submenu: [
{
label: this.main.i18nService.t('passwordGenerator'),
id: 'passwordGenerator',
click: () => this.main.messagingService.send('openPasswordGenerator'),
accelerator: 'CmdOrCtrl+G',
},
{
label: this.main.i18nService.t('searchVault'),
id: 'searchVault',
click: () => this.main.messagingService.send('focusSearch'),
accelerator: 'CmdOrCtrl+F',
},
@@ -148,9 +200,11 @@ export class MenuMain {
{
label: this.main.i18nService.t('premiumMembership'),
click: () => this.main.messagingService.send('premiumMembership'),
id: 'premiumMembership',
},
{
label: this.main.i18nService.t('changeMasterPass'),
id: 'changeMasterPass',
click: () => {
const result = dialog.showMessageBox(this.main.windowMain.win, {
title: this.main.i18nService.t('changeMasterPass'),
@@ -167,6 +221,7 @@ export class MenuMain {
},
{
label: this.main.i18nService.t('changeEmail'),
id: 'changeEmail',
click: () => {
const result = dialog.showMessageBox(this.main.windowMain.win, {
title: this.main.i18nService.t('changeEmail'),
@@ -183,6 +238,7 @@ export class MenuMain {
},
{
label: this.main.i18nService.t('twoStepLogin'),
id: 'twoStepLogin',
click: () => {
const result = dialog.showMessageBox(this.main.windowMain.win, {
title: this.main.i18nService.t('twoStepLogin'),
@@ -200,6 +256,7 @@ export class MenuMain {
{ type: 'separator' },
{
label: this.main.i18nService.t('logOut'),
id: 'logOut',
click: () => {
const result = dialog.showMessageBox(this.main.windowMain.win, {
title: this.main.i18nService.t('logOut'),
@@ -336,10 +393,12 @@ export class MenuMain {
{ type: 'separator' },
{
label: this.main.i18nService.t('settings'),
id: 'settings',
click: () => this.main.messagingService.send('openSettings'),
},
{
label: this.main.i18nService.t('lockNow'),
id: 'lockNow',
click: () => this.main.messagingService.send('lockVault'),
accelerator: 'CmdOrCtrl+L',
},
@@ -413,7 +472,7 @@ export class MenuMain {
]);
}
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
this.menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(this.menu);
}
}

View File

@@ -54,6 +54,9 @@ export class MessagingMain {
case 'scheduleNextSync':
this.scheduleNextSync();
break;
case 'updateAppMenu':
this.main.menuMain.updateApplicationMenuState(message.isAuthenticated, message.isLocked);
break;
default:
break;
}

View File

@@ -14,17 +14,15 @@ const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours
export class UpdaterMain {
private doingUpdateCheck = false;
private doingUpdateCheckWithFeedback = false;
private updateMenuItem: MenuItem;
constructor(private main: Main) { }
async init() {
global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay);
global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval);
this.updateMenuItem = Menu.getApplicationMenu().getMenuItemById('checkForUpdates');
autoUpdater.on('checking-for-update', () => {
this.updateMenuItem.enabled = false;
this.main.menuMain.updateMenuItem.enabled = false;
this.doingUpdateCheck = true;
});
@@ -60,7 +58,7 @@ export class UpdaterMain {
});
autoUpdater.on('update-downloaded', (info) => {
this.updateMenuItem.label = this.main.i18nService.t('restartToUpdate');
this.main.menuMain.updateMenuItem.label = this.main.i18nService.t('restartToUpdate');
const result = dialog.showMessageBox(this.main.windowMain.win, {
type: 'info',
@@ -103,7 +101,7 @@ export class UpdaterMain {
private reset() {
autoUpdater.autoDownload = true;
this.updateMenuItem.enabled = true;
this.main.menuMain.updateMenuItem.enabled = true;
this.doingUpdateCheck = false;
}
}