bitwarden-estensione-browser/src/main/menu.main.ts

381 lines
16 KiB
TypeScript
Raw Normal View History

2018-02-08 21:58:47 +01:00
import {
app,
BrowserWindow,
2018-02-12 22:07:14 +01:00
clipboard,
2018-02-09 19:21:23 +01:00
dialog,
2018-02-10 21:30:42 +01:00
ipcMain,
2018-02-08 21:58:47 +01:00
Menu,
2018-02-13 21:00:38 +01:00
MenuItem,
2018-02-08 21:58:47 +01:00
MenuItemConstructorOptions,
2018-02-09 18:36:37 +01:00
shell,
2018-02-08 21:58:47 +01:00
} from 'electron';
2018-02-12 22:07:14 +01:00
import { UpdaterMain } from './updater.main';
2018-02-08 21:58:47 +01:00
import { WindowMain } from './window.main';
2018-02-08 19:10:13 +01:00
2018-02-11 05:24:22 +01:00
import { I18nService } from 'jslib/abstractions/i18n.service';
2018-02-11 06:09:47 +01:00
import { MessagingService } from 'jslib/abstractions/messaging.service';
2018-02-09 06:21:00 +01:00
2018-02-08 19:10:13 +01:00
export class MenuMain {
2018-02-12 22:07:14 +01:00
constructor(private windowMain: WindowMain, private updaterMain: UpdaterMain,
private i18nService: I18nService, private messagingService: MessagingService) { }
2018-02-08 19:10:13 +01:00
init() {
const template: MenuItemConstructorOptions[] = [
2018-02-08 21:58:47 +01:00
{
2018-02-09 18:12:41 +01:00
label: this.i18nService.t('file'),
2018-02-08 21:58:47 +01:00
submenu: [
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('addNewLogin'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('newLogin'),
2018-02-10 21:30:42 +01:00
accelerator: 'CmdOrCtrl+N',
2018-02-09 06:21:00 +01:00
},
{
label: this.i18nService.t('addNewItem'),
2018-02-08 21:58:47 +01:00
submenu: [
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('typeLogin'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('newLogin'),
2018-02-10 21:30:42 +01:00
accelerator: 'Alt+L',
2018-02-08 21:58:47 +01:00
},
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('typeCard'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('newCard'),
2018-02-10 21:30:42 +01:00
accelerator: 'Alt+C',
2018-02-08 21:58:47 +01:00
},
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('typeIdentity'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('newIdentity'),
2018-02-10 21:30:42 +01:00
accelerator: 'Alt+I',
2018-02-08 21:58:47 +01:00
},
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('typeSecureNote'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('newSecureNote'),
2018-02-10 21:30:42 +01:00
accelerator: 'Alt+S',
},
],
2018-02-08 21:58:47 +01:00
},
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('addNewFolder'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('newFolder'),
2018-02-08 21:58:47 +01:00
},
2018-02-09 06:21:00 +01:00
{ type: 'separator' },
2018-02-09 19:21:23 +01:00
{
label: this.i18nService.t('syncVault'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('syncVault'),
2018-02-09 19:21:23 +01:00
},
2018-02-10 21:30:42 +01:00
],
2018-02-08 21:58:47 +01:00
},
2018-02-08 19:10:13 +01:00
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('edit'),
2018-02-08 19:10:13 +01:00
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
2018-02-09 06:21:00 +01:00
{ role: 'selectall' },
2018-02-08 19:10:13 +01:00
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
2018-02-10 21:30:42 +01:00
],
2018-02-08 19:10:13 +01:00
},
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('view'),
2018-02-08 19:10:13 +01:00
submenu: [
2018-02-09 06:21:00 +01:00
{
2018-02-09 18:12:41 +01:00
label: this.i18nService.t('passwordGenerator'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('openPasswordGenerator'),
2018-02-10 21:30:42 +01:00
accelerator: 'CmdOrCtrl+G',
2018-02-09 18:12:41 +01:00
},
2018-02-09 06:21:00 +01:00
{
2018-02-09 18:12:41 +01:00
label: this.i18nService.t('searchVault'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('focusSearch'),
2018-02-10 21:30:42 +01:00
accelerator: 'CmdOrCtrl+F',
2018-02-09 06:21:00 +01:00
},
2018-02-08 19:10:13 +01:00
{ type: 'separator' },
2018-02-09 18:12:41 +01:00
{ role: 'zoomin', accelerator: 'CmdOrCtrl+=' },
{ role: 'zoomout', accelerator: 'CmdOrCtrl+-' },
2018-02-09 18:36:37 +01:00
{ role: 'resetzoom', accelerator: 'CmdOrCtrl+0' },
2018-02-09 18:12:41 +01:00
{ type: 'separator' },
{ role: 'togglefullscreen' },
{ type: 'separator' },
{ role: 'reload', accelerator: 'Alt+Shift+R' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
2018-02-10 21:30:42 +01:00
],
2018-02-08 19:10:13 +01:00
},
2018-02-08 21:58:47 +01:00
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('account'),
2018-02-08 21:58:47 +01:00
submenu: [
2018-02-09 19:21:23 +01:00
{
label: this.i18nService.t('premiumMembership'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('premiumMembership'),
2018-02-09 19:21:23 +01:00
},
{
label: this.i18nService.t('changeMasterPass'),
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-11 05:24:22 +01:00
const result = dialog.showMessageBox(this.windowMain.win, {
title: this.i18nService.t('changeMasterPass'),
message: this.i18nService.t('changeMasterPasswordConfirmation'),
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
2018-02-09 19:21:23 +01:00
cancelId: 1,
defaultId: 0,
noLink: true,
});
if (result === 0) {
shell.openExternal('https://vault.bitwarden.com');
}
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
{
label: this.i18nService.t('changeEmail'),
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-11 05:24:22 +01:00
const result = dialog.showMessageBox(this.windowMain.win, {
title: this.i18nService.t('changeEmail'),
message: this.i18nService.t('changeEmailConfirmation'),
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
2018-02-09 19:21:23 +01:00
cancelId: 1,
defaultId: 0,
noLink: true,
});
if (result === 0) {
shell.openExternal('https://vault.bitwarden.com');
}
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
2018-02-10 22:06:39 +01:00
{
label: this.i18nService.t('twoStepLogin'),
click: () => {
2018-02-11 05:24:22 +01:00
const result = dialog.showMessageBox(this.windowMain.win, {
title: this.i18nService.t('twoStepLogin'),
message: this.i18nService.t('twoStepLoginConfirmation'),
buttons: [this.i18nService.t('yes'), this.i18nService.t('no')],
2018-02-10 22:06:39 +01:00
cancelId: 1,
defaultId: 0,
noLink: true,
});
if (result === 0) {
shell.openExternal('https://vault.bitwarden.com');
}
},
},
2018-02-09 19:21:23 +01:00
{ type: 'separator' },
2018-02-08 21:58:47 +01:00
{
2018-02-09 06:21:00 +01:00
label: this.i18nService.t('logOut'),
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-11 05:24:22 +01:00
const result = dialog.showMessageBox(this.windowMain.win, {
title: this.i18nService.t('logOut'),
message: this.i18nService.t('logOutConfirmation'),
buttons: [this.i18nService.t('logOut'), this.i18nService.t('cancel')],
2018-02-09 19:21:23 +01:00
cancelId: 1,
defaultId: 0,
noLink: true,
});
if (result === 0) {
2018-02-11 05:24:22 +01:00
this.messagingService.send('logout');
2018-02-09 19:21:23 +01:00
}
2018-02-10 21:30:42 +01:00
},
2018-02-08 21:58:47 +01:00
},
2018-02-10 21:30:42 +01:00
],
2018-02-08 21:58:47 +01:00
},
2018-02-08 19:10:13 +01:00
{
role: 'window',
submenu: [
{ role: 'minimize' },
2018-02-10 21:30:42 +01:00
{ role: 'close' },
],
2018-02-08 19:10:13 +01:00
},
{
role: 'help',
submenu: [
{
2018-02-09 18:36:37 +01:00
label: this.i18nService.t('emailUs'),
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('mailTo:hello@bitwarden.com'),
2018-02-09 18:36:37 +01:00
},
{
label: this.i18nService.t('visitOurWebsite'),
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://bitwarden.com/contact'),
2018-02-09 18:36:37 +01:00
},
{
label: this.i18nService.t('fileBugReport'),
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://github.com/bitwarden/desktop'),
2018-02-09 18:36:37 +01:00
},
{ type: 'separator' },
{
2018-02-09 19:21:23 +01:00
label: this.i18nService.t('followUs'),
submenu: [
{
label: this.i18nService.t('blog'),
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://blog.bitwarden.com'),
2018-02-09 19:21:23 +01:00
},
{
label: 'Twitter',
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://twitter.com/bitwarden_app'),
2018-02-09 19:21:23 +01:00
},
{
label: 'Facebook',
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://www.facebook.com/bitwarden/'),
2018-02-09 19:21:23 +01:00
},
{
label: 'Google+',
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://plus.google.com/114869903467947368993'),
2018-02-09 19:21:23 +01:00
},
{
label: 'GitHub',
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://github.com/bitwarden'),
2018-02-10 21:30:42 +01:00
},
],
2018-02-09 18:36:37 +01:00
},
2018-02-09 19:21:23 +01:00
{ type: 'separator' },
2018-02-09 18:36:37 +01:00
{
2018-02-09 19:47:59 +01:00
label: this.i18nService.t('goToWebVault'),
2018-02-10 22:06:39 +01:00
click: () => shell.openExternal('https://vault.bitwarden.com'),
2018-02-09 18:36:37 +01:00
},
{
2018-02-09 19:21:23 +01:00
label: this.i18nService.t('getMobileApp'),
submenu: [
{
label: 'iOS',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://itunes.apple.com/app/' +
'bitwarden-free-password-manager/id1137397744?mt=8');
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
{
label: 'Android',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://play.google.com/store/apps/' +
'details?id=com.x8bit.bitwarden');
2018-02-10 21:30:42 +01:00
},
},
],
2018-02-09 18:36:37 +01:00
},
{
2018-02-09 19:21:23 +01:00
label: this.i18nService.t('getBrowserExtension'),
submenu: [
{
label: 'Chrome',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://chrome.google.com/webstore/detail/' +
+'bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb');
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
{
label: 'Firefox',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://addons.mozilla.org/firefox/addon/' +
'bitwarden-password-manager/');
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
{
label: 'Opera',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://addons.opera.com/extensions/details/' +
'bitwarden-free-password-manager/');
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
{
label: 'Edge',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://www.microsoft.com/store/p/' +
'bitwarden-free-password-manager/9p6kxl0svnnl');
2018-02-10 21:30:42 +01:00
},
2018-02-09 19:21:23 +01:00
},
{
label: 'Safari',
2018-02-10 21:30:42 +01:00
click: () => {
2018-02-09 19:21:23 +01:00
shell.openExternal('https://safari-extensions.apple.com/details/' +
'?id=com.bitwarden.safari-LTZ2PFU5D6');
2018-02-10 21:30:42 +01:00
},
},
],
},
],
},
2018-02-08 19:10:13 +01:00
];
2018-02-10 23:07:46 +01:00
const firstMenuOptions: MenuItemConstructorOptions[] = [
{ type: 'separator' },
{
label: this.i18nService.t('settings'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('openSettings'),
2018-02-10 23:07:46 +01:00
},
{
label: this.i18nService.t('lockNow'),
2018-02-11 05:24:22 +01:00
click: () => this.messagingService.send('lockVault'),
2018-02-10 23:07:46 +01:00
accelerator: 'CmdOrCtrl+L',
},
];
2018-02-14 04:33:01 +01:00
const updateMenuItem = {
label: this.i18nService.t('checkForUpdates'),
click: () => this.updaterMain.checkForUpdate(true),
id: 'checkForUpdates',
};
2018-02-08 19:10:13 +01:00
if (process.platform === 'darwin') {
2018-02-10 23:07:46 +01:00
const firstMenuPart: MenuItemConstructorOptions[] = [
2018-02-08 21:58:47 +01:00
{ role: 'about' },
2018-02-14 04:33:01 +01:00
updateMenuItem,
2018-02-10 23:07:46 +01:00
];
template.unshift({
label: 'Bitwarden',
submenu: firstMenuPart.concat(firstMenuOptions, [
{ type: 'separator' },
{ role: 'services', submenu: [] },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
]),
});
2018-02-08 19:10:13 +01:00
// Window menu
2018-02-10 23:07:46 +01:00
template[template.length - 2].submenu = [
2018-02-08 19:10:13 +01:00
{ role: 'close' },
{ role: 'minimize' },
{ role: 'zoom' },
{ type: 'separator' },
2018-02-10 21:30:42 +01:00
{ role: 'front' },
];
2018-02-10 23:07:46 +01:00
} else {
2018-02-12 22:07:14 +01:00
// File menu
2018-02-10 23:07:46 +01:00
template[0].submenu = (template[0].submenu as MenuItemConstructorOptions[]).concat(
firstMenuOptions);
2018-02-12 22:07:14 +01:00
// About menu
template[template.length - 1].submenu =
(template[template.length - 1].submenu as MenuItemConstructorOptions[]).concat([
{ type: 'separator' },
2018-02-14 04:33:01 +01:00
updateMenuItem,
2018-02-12 22:07:14 +01:00
{
label: this.i18nService.t('about'),
click: () => {
const aboutInformation = this.i18nService.t('version', app.getVersion()) +
2018-02-12 22:12:18 +01:00
'\nShell ' + process.versions.electron +
'\nRenderer ' + process.versions.chrome +
'\nNode ' + process.versions.node +
2018-02-12 22:07:14 +01:00
'\nArchitecture ' + process.arch;
const result = dialog.showMessageBox(this.windowMain.win, {
title: 'Bitwarden',
message: 'Bitwarden',
detail: aboutInformation,
type: 'info',
noLink: true,
buttons: [this.i18nService.t('ok'), this.i18nService.t('copy')],
});
if (result === 1) {
clipboard.writeText(aboutInformation);
}
},
2018-02-12 22:12:18 +01:00
},
2018-02-12 22:07:14 +01:00
]);
2018-02-08 21:58:47 +01:00
}
2018-02-08 19:10:13 +01:00
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
}