Refactor and improve menubar

- Style fixes
 - Remove some items from Edit menu
 - Add app menu on macOS
 - Make Help point to help page instead of FAQ
 - Simplify menubar logic
This commit is contained in:
Alex Liebowitz 2017-03-08 18:09:27 -05:00
parent b0d7e6497a
commit 9c13a03ca6

View file

@ -2,75 +2,106 @@ const {Menu} = require('electron');
const electron = require('electron'); const electron = require('electron');
const app = electron.app; const app = electron.app;
const template = [ const baseTemplate = [
{ {
label: 'Edit', label: 'Edit',
submenu: [ submenu: [
{ {
role: 'undo' role: 'undo',
}, },
{ {
role: 'redo' role: 'redo',
}, },
{ {
type: 'separator' type: 'separator',
}, },
{ {
role: 'cut' role: 'cut',
}, },
{ {
role: 'copy' role: 'copy',
}, },
{ {
role: 'paste' role: 'paste',
}, },
{
role: 'delete'
},
{
role: 'selectall'
}
] ]
}, },
{ {
label: 'Help', label: 'Help',
submenu: [ submenu: [
{ {
label: 'FAQ', label: 'Help',
click () { require('electron').shell.openExternal('https://lbry.io/faq') } click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.loadURL(`file://${__dirname}/../dist/index.html?help`);
}
}
} }
] ]
} }
]; ];
module.exports = { const macOSAppMenuTemplate = {
showNormalMenubar: () => { label: app.getName(),
const menu = Menu.buildFromTemplate(template); submenu: [
Menu.setApplicationMenu(menu); {
}, role: 'about',
showDeveloperMenubar: () => { },
const devTemplate = template.slice(); {
devTemplate.push({ type: 'separator',
label: 'Developer', },
submenu: [ {
{ role: 'hide',
label: 'Reload', },
accelerator: 'CmdOrCtrl+R', {
click (item, focusedWindow) { role: 'hideothers',
if (focusedWindow) focusedWindow.reload() },
} {
}, role: 'unhide',
{ },
label: 'Toggle Developer Tools', {
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', type: 'separator',
click (item, focusedWindow) { },
if (focusedWindow) focusedWindow.webContents.toggleDevTools() {
} role: 'quit',
}, },
] ]
}); };
const menu = Menu.buildFromTemplate(devTemplate); const developerMenuTemplate = {
Menu.setApplicationMenu(menu); label: 'Developer',
} submenu: [
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.reload();
}
}
},
{
label: 'Toggle Developer Tools',
accelerator: process.platform == 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.webContents.toggleDevTools();
}
}
},
]
};
module.exports = {
showMenubar(showDeveloperMenu) {
let template = baseTemplate.slice();
if (process.platform === 'darwin') {
template.unshift(macOSAppMenuTemplate);
}
if (showDeveloperMenu) {
template.push(developerMenuTemplate);
}
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
},
}; };