1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-06-25 10:26:00 +02:00
bitwarden-desktop/src/main/menu.main.ts

192 lines
6.5 KiB
TypeScript
Raw Normal View History

2018-02-08 21:58:47 +01:00
import {
app,
BrowserWindow,
Menu,
MenuItemConstructorOptions,
ipcMain,
} 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: 'resetzoom', accelerator: 'CmdOrCtrl+0' },
{ role: 'zoomin', accelerator: 'CmdOrCtrl+=' },
{ role: 'zoomout', accelerator: 'CmdOrCtrl+-' },
{ 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: [
{
label: 'Learn More',
click() { require('electron').shell.openExternal('https://electronjs.org') }
}
]
}
];
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
}