Newer
Older
Luke Schoen
committed
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import electron from 'electron';
const { app, shell } = electron;
// Create the Application's main menu
// https://github.com/electron/electron/blob/master/docs/api/menu.md#examples
Luke Schoen
committed
export const getTemplate = fetherApp => {
// File menu
const fileTab =
process.platform === 'darwin'
? {
label: app.getName(),
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services', submenu: [] },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}
: {
label: app.getName(),
submenu: [{ role: 'quit' }]
};
const editTab = {
Luke Schoen
committed
label: 'Edit',
submenu: [
Luke Schoen
committed
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
Luke Schoen
committed
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
Luke Schoen
committed
{ type: 'separator' },
Luke Schoen
committed
{ role: 'delete' },
{ role: 'selectall' }
]
Luke Schoen
committed
};
Luke Schoen
committed
const editTabWindowsOS = {
label: 'Edit',
submenu: [
{ label: 'Undo', click: () => fetherApp.win.webContents.undo() },
{ label: 'Redo', click: () => fetherApp.win.webContents.redo() },
{ type: 'separator' },
{ label: 'Cut', click: () => fetherApp.win.webContents.cut() },
{ label: 'Copy', click: () => fetherApp.win.webContents.copy() },
{ label: 'Paste', click: () => fetherApp.win.webContents.paste() },
{ type: 'separator' },
{ label: 'Delete', click: () => fetherApp.win.webContents.delete() },
{
label: 'Select All',
click: () => fetherApp.win.webContents.selectAll()
}
]
};
Luke Schoen
committed
const viewTab = {
Luke Schoen
committed
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
Luke Schoen
committed
};
Luke Schoen
committed
const viewTabWindowsOS = {
label: 'View',
submenu: [
{ label: 'Reload', click: () => fetherApp.win.webContents.reload() },
{
label: 'Toggle Developer Tools',
click: () => fetherApp.win.webContents.toggleDevTools()
}
]
};
Luke Schoen
committed
const windowTab = {
Luke Schoen
committed
role: 'window',
submenu: [{ role: 'minimize' }, { role: 'close' }]
Luke Schoen
committed
};
const helpTab = {
Luke Schoen
committed
role: 'help',
submenu: [
{
label: 'Learn More',
click () {
shell.openExternal('https://parity.io');
}
}
]
Luke Schoen
committed
};
Luke Schoen
committed
Luke Schoen
committed
let template = [
fileTab,
process.platform === 'win32' ? editTabWindowsOS : editTab,
process.platform === 'win32' ? viewTabWindowsOS : viewTab,
windowTab,
helpTab
];
Luke Schoen
committed
if (process.platform === 'darwin') {
// Edit menu
template[1].submenu.push(
Luke Schoen
committed
{ type: 'separator' },
Luke Schoen
committed
{
label: 'Speech',
submenu: [{ role: 'startspeaking' }, { role: 'stopspeaking' }]
}
);
}
Luke Schoen
committed
Luke Schoen
committed
if (process.platform === 'darwin') {
// Window menu
template[3].submenu = [
{ role: 'close' },
{ role: 'minimize' },
{ role: 'zoom' },
{ type: 'separator' },
{ role: 'front' }
];
}
Luke Schoen
committed
Luke Schoen
committed
if (fetherApp.options.withTaskbar) {
Luke Schoen
committed
if (process.platform === 'darwin') {
// Remove 'close' and 'minimize' options when running as taskbar app
template[3].submenu.splice(0, 2);
} else {
// Remove Window menu tab on non-macOS when running as taskbar app
template.splice(3, 1);
}
Luke Schoen
committed
}
Luke Schoen
committed
return template;
};