From be651ebb4b6bc23fe46b8fc522e6590b6da57074 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 22:35:01 +0200 Subject: [PATCH] Parameter in menu builder for tray --- menu.js | 121 ++++++++++++++++++++---------------- plugins/styled-bars/back.js | 2 +- tray.js | 14 +---- 3 files changed, 71 insertions(+), 66 deletions(-) diff --git a/menu.js b/menu.js index dc3b1b8e..563aa612 100644 --- a/menu.js +++ b/menu.js @@ -20,7 +20,12 @@ const pluginEnabledMenu = (plugin, label = "") => ({ }, }); -const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [ +const mainMenuTemplate = ( + win, + withRoles = true, + isTray = false, + clickCb = () => {} +) => [ { label: "Plugins", submenu: [ @@ -200,51 +205,59 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [ }, ], }, - { - label: "View", - submenu: withRoles - ? [ - { role: "reload" }, - { role: "forceReload" }, - { type: "separator" }, - { role: "zoomIn" }, - { role: "zoomOut" }, - { role: "resetZoom" }, - ] - : [ - { - label: "Reload", - click: () => { - win.webContents.reload(); - }, - }, - { - label: "Force Reload", - click: () => { - win.webContents.reloadIgnoringCache(); - }, - }, - { type: "separator" }, - { - label: "Zoom In", - click: () => { - win.webContents.setZoomLevel(win.webContents.getZoomLevel() + 1); - }, - }, - { - label: "Zoom Out", - click: () => { - win.webContents.setZoomLevel(win.webContents.getZoomLevel() - 1); - }, - }, - { - label: "Reset Zoom", - click: () => { - win.webContents.setZoomLevel(0); - }, - }, - ], - }, + ...(!isTray + ? [ + { + label: "View", + submenu: withRoles + ? [ + { role: "reload" }, + { role: "forceReload" }, + { type: "separator" }, + { role: "zoomIn" }, + { role: "zoomOut" }, + { role: "resetZoom" }, + ] + : [ + { + label: "Reload", + click: () => { + win.webContents.reload(); + }, + }, + { + label: "Force Reload", + click: () => { + win.webContents.reloadIgnoringCache(); + }, + }, + { type: "separator" }, + { + label: "Zoom In", + click: () => { + win.webContents.setZoomLevel( + win.webContents.getZoomLevel() + 1 + ); + }, + }, + { + label: "Zoom Out", + click: () => { + win.webContents.setZoomLevel( + win.webContents.getZoomLevel() - 1 + ); + }, + }, + { + label: "Reset Zoom", + click: () => { + win.webContents.setZoomLevel(0); + }, + }, + ], + }, + ] + : []), { label: "Navigation", submenu: [ @@ -271,12 +284,16 @@ const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [ app.quit(); }, }, - { - label: "Quit App", - click: () => { - app.quit(); - }, - }, + ...(!isTray + ? [ + { + label: "Quit App", + click: () => { + app.quit(); + }, + }, + ] + : []), ], }, ]; diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index 3a760de7..c9ca2675 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -20,7 +20,7 @@ module.exports = (win) => { return; } done = true; - let template = mainMenuTemplate(win, false, (item) => { + let template = mainMenuTemplate(win, false, false, (item) => { checkCheckbox(win, item); }); let menu = Menu.buildFromTemplate(template); diff --git a/tray.js b/tray.js index e8eb22d3..e871f4bf 100644 --- a/tray.js +++ b/tray.js @@ -57,7 +57,7 @@ module.exports.setUpTray = (app, win) => { win.show(); }, }, - ...mainMenuTemplate(win), + ...mainMenuTemplate(win, true, true), { label: "Quit", click: () => { @@ -66,18 +66,6 @@ module.exports.setUpTray = (app, win) => { }, ]; - // delete quit button from navigation submenu - let navigation = getIndex(template,'Navigation'); - let quit = getIndex(template[navigation].submenu,'Quit App'); - delete template[navigation].submenu[quit]; - - // delete View submenu (all buttons are useless in tray) - delete template[getIndex(template, 'View')]; - const trayMenu = Menu.buildFromTemplate(template); tray.setContextMenu(trayMenu); }; - -function getIndex(arr,label) { - return arr.findIndex(item => item.label === label) -}