From 2b3a20c5ffd438eeb6b144ed1ca8c55316b83d36 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sat, 3 Apr 2021 15:47:32 +0300 Subject: [PATCH] Minimalize tray menu -doesnt include main menu template anymore --- menu.js | 134 ++++++++++++++++++++++++++------------------------------ tray.js | 9 +++- 2 files changed, 69 insertions(+), 74 deletions(-) diff --git a/menu.js b/menu.js index f974c4e4..e41fd9e0 100644 --- a/menu.js +++ b/menu.js @@ -23,18 +23,16 @@ const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({ }, }); -const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ +const mainMenuTemplate = (win, withRoles = true) => [ { label: "Plugins", submenu: [ ...getAllPlugins().map((plugin) => { - const pluginPath = path.join(__dirname, "plugins", plugin, "menu.js"); - + const pluginPath = path.join(__dirname, "plugins", plugin, "menu.js") if (existsSync(pluginPath)) { if (!config.plugins.isEnabled(plugin)) { return pluginEnabledMenu(win, plugin, "", true); } - const getPluginMenu = require(pluginPath); return { label: plugin, @@ -46,7 +44,7 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ ], }; } - + return pluginEnabledMenu(win, plugin); }), { type: "separator" }, @@ -111,12 +109,12 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ config.set("options.hideMenu", item.checked); }, }, - ] + ] : []), ...(is.windows() || is.macOS() ? // Only works on Win/Mac - // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows - [ + // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows + [ { label: "Start at login", type: "checkbox", @@ -125,7 +123,7 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ config.set("options.startAtLogin", item.checked); }, }, - ] + ] : []), { label: "Tray", @@ -192,59 +190,55 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ], }, - ...(!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: "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,16 +265,12 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ app.quit(); }, }, - ...(!isTray - ? [ - { - label: "Quit App", - click: () => { - app.quit(); - }, - }, - ] - : []), + { + label: "Quit App", + click: () => { + app.quit(); + }, + }, ], }, ]; diff --git a/tray.js b/tray.js index e871f4bf..7d0331f7 100644 --- a/tray.js +++ b/tray.js @@ -3,7 +3,6 @@ const path = require("path"); const { Menu, nativeImage, Tray } = require("electron"); const config = require("./config"); -const { mainMenuTemplate } = require("./menu"); const getSongControls = require("./providers/song-controls"); // Prevent tray being garbage collected @@ -57,7 +56,13 @@ module.exports.setUpTray = (app, win) => { win.show(); }, }, - ...mainMenuTemplate(win, true, true), + { + label: "Restart App", + click: () => { + app.relaunch(); + app.quit(); + }, + }, { label: "Quit", click: () => {