2018-02-08 21:58:47 +01:00
|
|
|
import {
|
|
|
|
app,
|
|
|
|
BrowserWindow,
|
|
|
|
Menu,
|
|
|
|
MenuItemConstructorOptions,
|
|
|
|
ipcMain,
|
2018-02-09 18:36:37 +01:00
|
|
|
shell,
|
2018-02-08 21:58:47 +01:00
|
|
|
} from 'electron';
|
|
|
|
|
|
|
|
import { WindowMain } from './window.main';
|
2018-02-08 19:10:13 +01:00
|
|
|
|
2018-02-09 06:21:00 +01:00
|
|
|
import { I18nService } from '../services/i18n.service';
|
|
|
|
|
2018-02-08 19:10:13 +01:00
|
|
|
export class MenuMain {
|
2018-02-09 06:21:00 +01:00
|
|
|
constructor(private windowMain: WindowMain, private i18nService: I18nService) { }
|
2018-02-08 19:10:13 +01:00
|
|
|
|
|
|
|
init() {
|
2018-02-08 21:58:47 +01:00
|
|
|
const self = this;
|
|
|
|
|
2018-02-08 19:10:13 +01:00
|
|
|
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'),
|
|
|
|
click() {
|
|
|
|
self.send('newLogin');
|
|
|
|
},
|
|
|
|
accelerator: 'CmdOrCtrl+N'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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-08 21:58:47 +01:00
|
|
|
click() {
|
|
|
|
self.send('newLogin');
|
2018-02-09 18:12:41 +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-08 21:58:47 +01:00
|
|
|
click() {
|
|
|
|
self.send('newCard');
|
2018-02-09 18:12:41 +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-08 21:58:47 +01:00
|
|
|
click() {
|
|
|
|
self.send('newIdentity');
|
2018-02-09 18:12:41 +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-08 21:58:47 +01:00
|
|
|
click() {
|
|
|
|
self.send('newSecureNote');
|
2018-02-09 18:12:41 +01:00
|
|
|
},
|
|
|
|
accelerator: 'Alt+S'
|
2018-02-08 21:58:47 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-02-09 06:21:00 +01:00
|
|
|
{ type: 'separator' },
|
2018-02-08 21:58:47 +01:00
|
|
|
{
|
2018-02-09 06:21:00 +01:00
|
|
|
label: this.i18nService.t('addNewFolder'),
|
2018-02-08 21:58:47 +01:00
|
|
|
click() {
|
2018-02-09 06:21:00 +01:00
|
|
|
self.send('newFolder');
|
2018-02-08 21:58:47 +01:00
|
|
|
}
|
|
|
|
},
|
2018-02-09 06:21:00 +01:00
|
|
|
{ type: 'separator' },
|
2018-02-08 21:58:47 +01:00
|
|
|
{
|
2018-02-09 06:21:00 +01:00
|
|
|
label: this.i18nService.t('settings'),
|
2018-02-08 21:58:47 +01:00
|
|
|
click() {
|
2018-02-09 06:21:00 +01:00
|
|
|
self.send('openSettings');
|
2018-02-08 21:58:47 +01:00
|
|
|
}
|
2018-02-09 06:21:00 +01:00
|
|
|
},
|
|
|
|
{
|
2018-02-09 18:12:41 +01:00
|
|
|
label: this.i18nService.t('lock'),
|
2018-02-09 06:21:00 +01:00
|
|
|
click() {
|
|
|
|
self.send('lockApp');
|
|
|
|
},
|
|
|
|
accelerator: 'CmdOrCtrl+L'
|
|
|
|
},
|
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-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'),
|
|
|
|
click() {
|
|
|
|
self.send('openPasswordGenerator');
|
|
|
|
},
|
|
|
|
accelerator: 'CmdOrCtrl+G'
|
|
|
|
},
|
2018-02-09 06:21:00 +01:00
|
|
|
{
|
2018-02-09 18:12:41 +01:00
|
|
|
label: this.i18nService.t('searchVault'),
|
|
|
|
click() {
|
|
|
|
self.send('focusSearch');
|
|
|
|
},
|
|
|
|
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-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 06:21:00 +01:00
|
|
|
label: this.i18nService.t('logOut'),
|
2018-02-08 21:58:47 +01:00
|
|
|
click() {
|
|
|
|
self.send('confirmLogout');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
2018-02-08 19:10:13 +01:00
|
|
|
{
|
|
|
|
role: 'window',
|
|
|
|
submenu: [
|
|
|
|
{ role: 'minimize' },
|
|
|
|
{ role: 'close' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
2018-02-09 18:36:37 +01:00
|
|
|
label: this.i18nService.t('emailUs'),
|
|
|
|
click() {
|
|
|
|
shell.openExternal('mailTo:hello@bitwarden.com')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.i18nService.t('visitOurWebsite'),
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://bitwarden.com/contact')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.i18nService.t('fileBugReport'),
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://github.com/bitwarden/desktop')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ type: 'separator' },
|
|
|
|
{
|
|
|
|
label: this.i18nService.t('blog'),
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://blog.bitwarden.com')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Twitter',
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://twitter.com/bitwarden_app')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Facebook',
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://www.facebook.com/bitwarden/')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Google+',
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://plus.google.com/114869903467947368993')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'GitHub',
|
|
|
|
click() {
|
|
|
|
shell.openExternal('https://github.com/bitwarden')
|
|
|
|
}
|
2018-02-08 19:10:13 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
2018-02-09 06:21:00 +01:00
|
|
|
template[0].label = app.getName();
|
|
|
|
(template[0].submenu as MenuItemConstructorOptions[]).concat([
|
2018-02-08 21:58:47 +01:00
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'about' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'services', submenu: [] },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'hide' },
|
|
|
|
{ role: 'hideothers' },
|
|
|
|
{ role: 'unhide' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'quit' }
|
2018-02-09 06:21:00 +01:00
|
|
|
]);
|
2018-02-08 19:10:13 +01:00
|
|
|
|
|
|
|
// Window menu
|
2018-02-08 21:58:47 +01:00
|
|
|
template[4].submenu = [
|
2018-02-08 19:10:13 +01:00
|
|
|
{ role: 'close' },
|
|
|
|
{ role: 'minimize' },
|
|
|
|
{ role: 'zoom' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'front' }
|
|
|
|
]
|
2018-02-08 21:58:47 +01:00
|
|
|
}
|
2018-02-08 19:10:13 +01:00
|
|
|
|
|
|
|
const menu = Menu.buildFromTemplate(template);
|
|
|
|
Menu.setApplicationMenu(menu);
|
|
|
|
}
|
2018-02-08 21:58:47 +01:00
|
|
|
|
|
|
|
send(command: string, message?: any) {
|
|
|
|
this.windowMain.win.webContents.send('messagingService', {
|
|
|
|
command: command,
|
|
|
|
message: message,
|
|
|
|
});
|
|
|
|
}
|
2018-02-08 19:10:13 +01:00
|
|
|
}
|