From 9c13a03ca6bffb8f800117e61f0c18e0a81bc9a2 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 8 Mar 2017 18:09:27 -0500 Subject: [PATCH] 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 --- app/menu/main-menu.js | 121 ++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 45 deletions(-) diff --git a/app/menu/main-menu.js b/app/menu/main-menu.js index f388ffd7b..585435730 100644 --- a/app/menu/main-menu.js +++ b/app/menu/main-menu.js @@ -2,75 +2,106 @@ const {Menu} = require('electron'); const electron = require('electron'); const app = electron.app; -const template = [ +const baseTemplate = [ { label: 'Edit', 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', submenu: [ { - label: 'FAQ', - click () { require('electron').shell.openExternal('https://lbry.io/faq') } + label: 'Help', + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.loadURL(`file://${__dirname}/../dist/index.html?help`); + } + } } ] } ]; -module.exports = { - showNormalMenubar: () => { - const menu = Menu.buildFromTemplate(template); - Menu.setApplicationMenu(menu); - }, - showDeveloperMenubar: () => { - const devTemplate = template.slice(); - devTemplate.push({ - 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() - } - }, - ] - }); - - const menu = Menu.buildFromTemplate(devTemplate); - Menu.setApplicationMenu(menu); - } +const macOSAppMenuTemplate = { + label: app.getName(), + submenu: [ + { + role: 'about', + }, + { + type: 'separator', + }, + { + role: 'hide', + }, + { + role: 'hideothers', + }, + { + role: 'unhide', + }, + { + type: 'separator', + }, + { + role: 'quit', + }, + ] +}; + +const developerMenuTemplate = { + 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)); + }, };