From 5671b99b7ec24dd4148c3cf04462af61b617813a Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 20:15:55 +0200 Subject: [PATCH 01/11] Format new menu items --- menu.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/menu.js b/menu.js index 3f5744b4..24895c61 100644 --- a/menu.js +++ b/menu.js @@ -220,13 +220,18 @@ const mainMenuTemplate = (win) => [ }, }, { - label: 'Restart App', - click: () => {app.relaunch(); app.quit();} - } , + label: "Restart App", + click: () => { + app.relaunch(); + app.quit(); + }, + }, { - label: 'Quit App', - click: () => {app.quit();} - } + label: "Quit App", + click: () => { + app.quit(); + }, + }, ], }, ]; From 36864b4c2f87de3fa6db883ecca01bc947ccf95c Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 20:17:12 +0200 Subject: [PATCH 02/11] Format custom menu plugin --- plugins/styled-bars/back.js | 34 +++++++++++++------------- plugins/styled-bars/front.js | 16 ++++++------ plugins/styled-bars/style.css | 46 ++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index 37fd6c8b..cd8afbf2 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -1,8 +1,8 @@ -const { injectCSS } = require('../utils'); -const { Menu } = require('electron'); -const path = require('path'); +const { injectCSS } = require("../utils"); +const { Menu } = require("electron"); +const path = require("path"); const electronLocalshortcut = require("electron-localshortcut"); -const config = require('../../config'); +const config = require("../../config"); var { mainMenuTemplate } = require("../../menu"); //override menu template for custom menu @@ -14,31 +14,31 @@ mainMenuTemplate = function (winHook) { fixMenu(template); //return as normal return template; -} +}; //win hook for fixing menu let win; //check that menu doesn't get created twice let done = false; -module.exports = winImport => { +module.exports = (winImport) => { win = winImport; // css for custom scrollbar + disable drag area(was causing bugs) - injectCSS(win.webContents, path.join(__dirname, 'style.css')); - win.on('ready-to-show', () => { - // (apparently ready-to-show is called twice) + injectCSS(win.webContents, path.join(__dirname, "style.css")); + win.on("ready-to-show", () => { + // (apparently ready-to-show is called twice) if (done) { - return + return; } done = true; let template = mainMenuTemplate(win); let menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); - + //register keyboard shortcut && hide menu if hideMenu is enabled - if (config.get('options.hideMenu')) { + if (config.get("options.hideMenu")) { switchMenuVisibility(); - electronLocalshortcut.register(win, 'Esc', () => { + electronLocalshortcut.register(win, "Esc", () => { switchMenuVisibility(); }); } @@ -47,8 +47,8 @@ module.exports = winImport => { let visible = true; function switchMenuVisibility() { - visible=!visible; - win.webContents.send('updateMenu',visible) + visible = !visible; + win.webContents.send("updateMenu", visible); } //go over each item in menu @@ -60,7 +60,7 @@ function fixMenu(template) { fixMenu(item.submenu); } //change onClick of checkbox+radio - else if (item.type === 'checkbox' || item.type === 'radio') { + else if (item.type === "checkbox" || item.type === "radio") { let ogOnclick = item.click; item.click = (itemClicked) => { ogOnclick(itemClicked); @@ -107,5 +107,5 @@ function checkCheckbox(item) { //check item item.checked = !item.checked; //update menu (closes it) - win.webContents.send('updateMenu', true); + win.webContents.send("updateMenu", true); } diff --git a/plugins/styled-bars/front.js b/plugins/styled-bars/front.js index d5274364..ad0fb064 100644 --- a/plugins/styled-bars/front.js +++ b/plugins/styled-bars/front.js @@ -1,15 +1,15 @@ -const customTitlebar = require('custom-electron-titlebar'); -const {remote, ipcRenderer} = require('electron'); +const customTitlebar = require("custom-electron-titlebar"); +const { remote, ipcRenderer } = require("electron"); module.exports = () => { const myBar = new customTitlebar.Titlebar({ - backgroundColor: customTitlebar.Color.fromHex('#050505'), - itemBackgroundColor: customTitlebar.Color.fromHex('#121212') + backgroundColor: customTitlebar.Color.fromHex("#050505"), + itemBackgroundColor: customTitlebar.Color.fromHex("#121212"), }); - myBar.updateTitle(' '); - document.title = 'Youtube Music'; + myBar.updateTitle(" "); + document.title = "Youtube Music"; - ipcRenderer.on('updateMenu', function (event, menu) { + ipcRenderer.on("updateMenu", function (event, menu) { if (menu) { myBar.updateMenu(remote.Menu.getApplicationMenu()); } else { @@ -20,4 +20,4 @@ module.exports = () => { } } }); -}; \ No newline at end of file +}; diff --git a/plugins/styled-bars/style.css b/plugins/styled-bars/style.css index f0d0c88b..641b94cd 100644 --- a/plugins/styled-bars/style.css +++ b/plugins/styled-bars/style.css @@ -1,21 +1,22 @@ /* increase font size for menu and menuItems */ -.titlebar, .menubar-menu-container .action-label{ - font-size: 14px !important; +.titlebar, +.menubar-menu-container .action-label { + font-size: 14px !important; } /* allow submenu's to show correctly */ -.menubar-menu-container{ - overflow-y: visible !important; +.menubar-menu-container { + overflow-y: visible !important; } /* fixes scrollbar positioning relative to nav bar */ #nav-bar-background.ytmusic-app-layout { - right: 15px !important; + right: 15px !important; } /* remove window dragging for nav bar (conflict with titlebar drag) */ -ytmusic-nav-bar, +ytmusic-nav-bar, .tab-titleiron-icon, ytmusic-pivot-bar-item-renderer { - -webkit-app-region : unset; + -webkit-app-region: unset; } /* Move navBar downwards and make it opaque */ @@ -28,34 +29,35 @@ ytmusic-search-box.ytmusic-nav-bar { } .center-content.ytmusic-nav-bar { - background: #030303; + background: #030303; } -yt-page-navigation-progress, +yt-page-navigation-progress, #progress.yt-page-navigation-progress, -ytmusic-item-section-renderer[has-item-section-tabbed-header-renderer_] #header.ytmusic-item-section-renderer, +ytmusic-item-section-renderer[has-item-section-tabbed-header-renderer_] + #header.ytmusic-item-section-renderer, ytmusic-header-renderer.ytmusic-search-page { - top: 90px !important; + top: 90px !important; } /* Custom scrollbar */ ::-webkit-scrollbar { - width: 12px; - background-color: #030303; - -webkit-border-radius: 100px; + width: 12px; + background-color: #030303; + -webkit-border-radius: 100px; } /* hover effect for both scrollbar area, and scrollbar 'thumb' */ ::-webkit-scrollbar:hover { - background-color: rgba(15, 15, 15, 0.699); + background-color: rgba(15, 15, 15, 0.699); } /* The scrollbar 'thumb' ...that marque oval shape in a scrollbar */ ::-webkit-scrollbar-thumb:vertical { - background-clip: padding-box; - border: 2px solid rgba(0, 0, 0, 0); + background-clip: padding-box; + border: 2px solid rgba(0, 0, 0, 0); - background: rgb(49, 0, 0); - -webkit-border-radius: 100px; + background: rgb(49, 0, 0); + -webkit-border-radius: 100px; } ::-webkit-scrollbar-thumb:vertical:active { - background: rgb(56, 0, 0); /* Some darker color when you click it */ - -webkit-border-radius: 100px; -} \ No newline at end of file + background: rgb(56, 0, 0); /* Some darker color when you click it */ + -webkit-border-radius: 100px; +} From 400a2a9bab1b05bcabe0ff6609370cdac225a5e4 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 20:18:20 +0200 Subject: [PATCH 03/11] Add option to menu to render without roles --- menu.js | 52 ++++++++++++++++++++++++++++++------- plugins/styled-bars/back.js | 35 +------------------------ 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/menu.js b/menu.js index 24895c61..33ac027f 100644 --- a/menu.js +++ b/menu.js @@ -20,7 +20,7 @@ const pluginEnabledMenu = (plugin, label = "") => ({ }, }); -const mainMenuTemplate = (win) => [ +const mainMenuTemplate = (win, withRoles = true) => [ { label: "Plugins", submenu: [ @@ -191,14 +191,48 @@ const mainMenuTemplate = (win) => [ }, { label: "View", - submenu: [ - { role: "reload" }, - { role: "forceReload" }, - { type: "separator" }, - { role: "zoomIn" }, - { role: "zoomOut" }, - { role: "resetZoom" }, - ], + 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", diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index cd8afbf2..ec70c7b2 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -9,7 +9,7 @@ var { mainMenuTemplate } = require("../../menu"); const originTemplate = mainMenuTemplate; mainMenuTemplate = function (winHook) { //get template - let template = originTemplate(winHook); + let template = originTemplate(winHook, false); //fix checkbox and roles fixMenu(template); //return as normal @@ -67,42 +67,9 @@ function fixMenu(template) { checkCheckbox(itemClicked); }; } - //customize roles - else if (item.role != null) { - fixRoles(item) - } } } -//custom menu doesn't support roles, so they get injected manually -function fixRoles(MenuItem) { - switch (MenuItem.role) { - case 'reload': - MenuItem.label = 'Reload'; - MenuItem.click = () => { win.webContents.reload(); } - break; - case 'forceReload': - MenuItem.label = 'Force Reload'; - MenuItem.click = () => { win.webContents.reloadIgnoringCache(); } - break; - case 'zoomIn': - MenuItem.label = 'Zoom In'; - MenuItem.click = () => { win.webContents.setZoomLevel(win.webContents.getZoomLevel() + 1); } - break; - case 'zoomOut': - MenuItem.label = 'Zoom Out'; - MenuItem.click = () => { win.webContents.setZoomLevel(win.webContents.getZoomLevel() - 1); } - break; - case 'resetZoom': - MenuItem.label = 'Reset Zoom'; - MenuItem.click = () => { win.webContents.setZoomLevel(0); } - break; - default: - console.log(`Error fixing MenuRoles: "${MenuItem.role}" was not expected`); - } - delete MenuItem.role; -} - function checkCheckbox(item) { //check item item.checked = !item.checked; From f9f3482bf11813c56516332fc11a1cfc6e9d0c17 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 20:23:10 +0200 Subject: [PATCH 04/11] Pass callback in menu builder --- menu.js | 13 ++++++++++++- plugins/styled-bars/back.js | 25 +++---------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/menu.js b/menu.js index 33ac027f..dc3b1b8e 100644 --- a/menu.js +++ b/menu.js @@ -20,7 +20,7 @@ const pluginEnabledMenu = (plugin, label = "") => ({ }, }); -const mainMenuTemplate = (win, withRoles = true) => [ +const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [ { label: "Plugins", submenu: [ @@ -64,6 +64,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.autoUpdates"), click: (item) => { config.set("options.autoUpdates", item.checked); + clickCb(item); }, }, { @@ -72,6 +73,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.disableHardwareAcceleration"), click: (item) => { config.set("options.disableHardwareAcceleration", item.checked); + clickCb(item); }, }, { @@ -80,6 +82,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.restartOnConfigChanges"), click: (item) => { config.set("options.restartOnConfigChanges", item.checked); + clickCb(item); }, }, { @@ -88,6 +91,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.autoResetAppCache"), click: (item) => { config.set("options.autoResetAppCache", item.checked); + clickCb(item); }, }, { @@ -96,6 +100,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.resumeOnStart"), click: (item) => { config.set("options.resumeOnStart", item.checked); + clickCb(item); }, }, ...(is.windows() || is.linux() @@ -106,6 +111,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.hideMenu"), click: (item) => { config.set("options.hideMenu", item.checked); + clickCb(item); }, }, ] @@ -120,6 +126,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.startAtLogin"), click: (item) => { config.set("options.startAtLogin", item.checked); + clickCb(item); }, }, ] @@ -134,6 +141,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ click: () => { config.set("options.tray", false); config.set("options.appVisible", true); + clickCb(item); }, }, { @@ -144,6 +152,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ click: () => { config.set("options.tray", true); config.set("options.appVisible", true); + clickCb(item); }, }, { @@ -154,6 +163,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ click: () => { config.set("options.tray", true); config.set("options.appVisible", false); + clickCb(item); }, }, { type: "separator" }, @@ -163,6 +173,7 @@ const mainMenuTemplate = (win, withRoles = true) => [ checked: config.get("options.trayClickPlayPause"), click: (item) => { config.set("options.trayClickPlayPause", item.checked); + clickCb(item); }, }, ], diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index ec70c7b2..cfc92108 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -9,9 +9,9 @@ var { mainMenuTemplate } = require("../../menu"); const originTemplate = mainMenuTemplate; mainMenuTemplate = function (winHook) { //get template - let template = originTemplate(winHook, false); - //fix checkbox and roles - fixMenu(template); + let template = originTemplate(winHook, false, (item) => { + checkCheckbox(item); + }); //return as normal return template; }; @@ -51,25 +51,6 @@ function switchMenuVisibility() { win.webContents.send("updateMenu", visible); } -//go over each item in menu -function fixMenu(template) { - for (let index in template) { - let item = template[index]; - //apply function on submenu - if (item.submenu != null) { - fixMenu(item.submenu); - } - //change onClick of checkbox+radio - else if (item.type === "checkbox" || item.type === "radio") { - let ogOnclick = item.click; - item.click = (itemClicked) => { - ogOnclick(itemClicked); - checkCheckbox(itemClicked); - }; - } - } -} - function checkCheckbox(item) { //check item item.checked = !item.checked; From 0d2b61472c1e9bc3f6511eb35ec742c8f5571be1 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 20:25:27 +0200 Subject: [PATCH 05/11] Use template builder in custom menu plugin --- plugins/styled-bars/back.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index cfc92108..6c8fcc6e 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -5,24 +5,10 @@ const electronLocalshortcut = require("electron-localshortcut"); const config = require("../../config"); var { mainMenuTemplate } = require("../../menu"); -//override menu template for custom menu -const originTemplate = mainMenuTemplate; -mainMenuTemplate = function (winHook) { - //get template - let template = originTemplate(winHook, false, (item) => { - checkCheckbox(item); - }); - //return as normal - return template; -}; -//win hook for fixing menu -let win; - //check that menu doesn't get created twice let done = false; -module.exports = (winImport) => { - win = winImport; +module.exports = (win) => { // css for custom scrollbar + disable drag area(was causing bugs) injectCSS(win.webContents, path.join(__dirname, "style.css")); win.on("ready-to-show", () => { @@ -31,27 +17,29 @@ module.exports = (winImport) => { return; } done = true; - let template = mainMenuTemplate(win); + let template = mainMenuTemplate(win, false, (item) => { + checkCheckbox(win, item); + }); let menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); //register keyboard shortcut && hide menu if hideMenu is enabled if (config.get("options.hideMenu")) { - switchMenuVisibility(); + switchMenuVisibility(win); electronLocalshortcut.register(win, "Esc", () => { - switchMenuVisibility(); + switchMenuVisibility(win); }); } }); }; let visible = true; -function switchMenuVisibility() { +function switchMenuVisibility(win) { visible = !visible; win.webContents.send("updateMenu", visible); } -function checkCheckbox(item) { +function checkCheckbox(win, item) { //check item item.checked = !item.checked; //update menu (closes it) From ff9e39e2ee3025acebe3ea03a0bef4ba09562cc1 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 20:27:15 +0200 Subject: [PATCH 06/11] Re-order dependencies --- plugins/styled-bars/back.js | 9 ++++++--- plugins/styled-bars/front.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index 6c8fcc6e..3a760de7 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -1,9 +1,11 @@ -const { injectCSS } = require("../utils"); -const { Menu } = require("electron"); const path = require("path"); + +const { Menu } = require("electron"); const electronLocalshortcut = require("electron-localshortcut"); + const config = require("../../config"); -var { mainMenuTemplate } = require("../../menu"); +const { mainMenuTemplate } = require("../../menu"); +const { injectCSS } = require("../utils"); //check that menu doesn't get created twice let done = false; @@ -11,6 +13,7 @@ let done = false; module.exports = (win) => { // css for custom scrollbar + disable drag area(was causing bugs) injectCSS(win.webContents, path.join(__dirname, "style.css")); + win.on("ready-to-show", () => { // (apparently ready-to-show is called twice) if (done) { diff --git a/plugins/styled-bars/front.js b/plugins/styled-bars/front.js index ad0fb064..13f0bac0 100644 --- a/plugins/styled-bars/front.js +++ b/plugins/styled-bars/front.js @@ -1,6 +1,7 @@ -const customTitlebar = require("custom-electron-titlebar"); const { remote, ipcRenderer } = require("electron"); +const customTitlebar = require("custom-electron-titlebar"); + module.exports = () => { const myBar = new customTitlebar.Titlebar({ backgroundColor: customTitlebar.Color.fromHex("#050505"), From a8cfe399b3a5b1b9ecee5304792925e7203f2ccc Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 21:15:52 +0200 Subject: [PATCH 07/11] Rename bar var --- plugins/styled-bars/front.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/styled-bars/front.js b/plugins/styled-bars/front.js index 13f0bac0..3287dc5d 100644 --- a/plugins/styled-bars/front.js +++ b/plugins/styled-bars/front.js @@ -3,19 +3,19 @@ const { remote, ipcRenderer } = require("electron"); const customTitlebar = require("custom-electron-titlebar"); module.exports = () => { - const myBar = new customTitlebar.Titlebar({ + const bar = new customTitlebar.Titlebar({ backgroundColor: customTitlebar.Color.fromHex("#050505"), itemBackgroundColor: customTitlebar.Color.fromHex("#121212"), }); - myBar.updateTitle(" "); + bar.updateTitle(" "); document.title = "Youtube Music"; ipcRenderer.on("updateMenu", function (event, menu) { if (menu) { - myBar.updateMenu(remote.Menu.getApplicationMenu()); + bar.updateMenu(remote.Menu.getApplicationMenu()); } else { try { - myBar.updateMenu(null); + bar.updateMenu(null); } catch (e) { //will always throw type error - null isn't menu, but it works } From 3fe793cd4da55135fc3fba73f3eacf03ba8611c6 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 21:18:31 +0200 Subject: [PATCH 08/11] CSS: border radius compatibility --- plugins/styled-bars/style.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/styled-bars/style.css b/plugins/styled-bars/style.css index 641b94cd..25ae7c4a 100644 --- a/plugins/styled-bars/style.css +++ b/plugins/styled-bars/style.css @@ -42,6 +42,8 @@ ytmusic-header-renderer.ytmusic-search-page { ::-webkit-scrollbar { width: 12px; background-color: #030303; + border-radius: 100px; + -moz-border-radius: 100px; -webkit-border-radius: 100px; } /* hover effect for both scrollbar area, and scrollbar 'thumb' */ @@ -55,9 +57,13 @@ ytmusic-header-renderer.ytmusic-search-page { border: 2px solid rgba(0, 0, 0, 0); background: rgb(49, 0, 0); + border-radius: 100px; + -moz-border-radius: 100px; -webkit-border-radius: 100px; } ::-webkit-scrollbar-thumb:vertical:active { background: rgb(56, 0, 0); /* Some darker color when you click it */ + border-radius: 100px; + -moz-border-radius: 100px; -webkit-border-radius: 100px; } From be651ebb4b6bc23fe46b8fc522e6590b6da57074 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 22:35:01 +0200 Subject: [PATCH 09/11] 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) -} From c09de4315402fe0604def6bba41164a43d5884a4 Mon Sep 17 00:00:00 2001 From: TC Date: Wed, 31 Mar 2021 22:37:12 +0200 Subject: [PATCH 10/11] Rename plugin to `in-app-menu` + hidden titleBarStyle --- index.js | 9 +++++++-- plugins/{styled-bars => in-app-menu}/back.js | 0 plugins/{styled-bars => in-app-menu}/front.js | 0 plugins/{styled-bars => in-app-menu}/style.css | 0 4 files changed, 7 insertions(+), 2 deletions(-) rename plugins/{styled-bars => in-app-menu}/back.js (100%) rename plugins/{styled-bars => in-app-menu}/front.js (100%) rename plugins/{styled-bars => in-app-menu}/style.css (100%) diff --git a/index.js b/index.js index fabf3312..7c79a1b6 100644 --- a/index.js +++ b/index.js @@ -75,6 +75,7 @@ function createMainWindow() { const windowSize = config.get("window-size"); const windowMaximized = config.get("window-maximized"); const windowPosition = config.get("window-position"); + const useInlineMenu = config.plugins.isEnabled("in-app-menu"); const win = new electron.BrowserWindow({ icon: icon, @@ -99,8 +100,12 @@ function createMainWindow() { } : undefined), }, - frame: !is.macOS() && !config.plugins.isEnabled("styled-bars"), - titleBarStyle: is.macOS() ? "hiddenInset" : "default", + frame: !is.macOS() && !useInlineMenu, + titleBarStyle: useInlineMenu + ? "hidden" + : is.macOS() + ? "hiddenInset" + : "default", autoHideMenuBar: config.get("options.hideMenu"), }); if (windowPosition) { diff --git a/plugins/styled-bars/back.js b/plugins/in-app-menu/back.js similarity index 100% rename from plugins/styled-bars/back.js rename to plugins/in-app-menu/back.js diff --git a/plugins/styled-bars/front.js b/plugins/in-app-menu/front.js similarity index 100% rename from plugins/styled-bars/front.js rename to plugins/in-app-menu/front.js diff --git a/plugins/styled-bars/style.css b/plugins/in-app-menu/style.css similarity index 100% rename from plugins/styled-bars/style.css rename to plugins/in-app-menu/style.css From 77393c5324a67fb43dd73506dc0e636cfdd37119 Mon Sep 17 00:00:00 2001 From: TC Date: Fri, 2 Apr 2021 21:20:50 +0200 Subject: [PATCH 11/11] Replace click callback by override in custom menu --- menu.js | 18 +----------------- plugins/in-app-menu/back.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/menu.js b/menu.js index 563aa612..f641d184 100644 --- a/menu.js +++ b/menu.js @@ -20,12 +20,7 @@ const pluginEnabledMenu = (plugin, label = "") => ({ }, }); -const mainMenuTemplate = ( - win, - withRoles = true, - isTray = false, - clickCb = () => {} -) => [ +const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ { label: "Plugins", submenu: [ @@ -69,7 +64,6 @@ const mainMenuTemplate = ( checked: config.get("options.autoUpdates"), click: (item) => { config.set("options.autoUpdates", item.checked); - clickCb(item); }, }, { @@ -78,7 +72,6 @@ const mainMenuTemplate = ( checked: config.get("options.disableHardwareAcceleration"), click: (item) => { config.set("options.disableHardwareAcceleration", item.checked); - clickCb(item); }, }, { @@ -87,7 +80,6 @@ const mainMenuTemplate = ( checked: config.get("options.restartOnConfigChanges"), click: (item) => { config.set("options.restartOnConfigChanges", item.checked); - clickCb(item); }, }, { @@ -96,7 +88,6 @@ const mainMenuTemplate = ( checked: config.get("options.autoResetAppCache"), click: (item) => { config.set("options.autoResetAppCache", item.checked); - clickCb(item); }, }, { @@ -105,7 +96,6 @@ const mainMenuTemplate = ( checked: config.get("options.resumeOnStart"), click: (item) => { config.set("options.resumeOnStart", item.checked); - clickCb(item); }, }, ...(is.windows() || is.linux() @@ -116,7 +106,6 @@ const mainMenuTemplate = ( checked: config.get("options.hideMenu"), click: (item) => { config.set("options.hideMenu", item.checked); - clickCb(item); }, }, ] @@ -131,7 +120,6 @@ const mainMenuTemplate = ( checked: config.get("options.startAtLogin"), click: (item) => { config.set("options.startAtLogin", item.checked); - clickCb(item); }, }, ] @@ -146,7 +134,6 @@ const mainMenuTemplate = ( click: () => { config.set("options.tray", false); config.set("options.appVisible", true); - clickCb(item); }, }, { @@ -157,7 +144,6 @@ const mainMenuTemplate = ( click: () => { config.set("options.tray", true); config.set("options.appVisible", true); - clickCb(item); }, }, { @@ -168,7 +154,6 @@ const mainMenuTemplate = ( click: () => { config.set("options.tray", true); config.set("options.appVisible", false); - clickCb(item); }, }, { type: "separator" }, @@ -178,7 +163,6 @@ const mainMenuTemplate = ( checked: config.get("options.trayClickPlayPause"), click: (item) => { config.set("options.trayClickPlayPause", item.checked); - clickCb(item); }, }, ], diff --git a/plugins/in-app-menu/back.js b/plugins/in-app-menu/back.js index c9ca2675..7f9d6644 100644 --- a/plugins/in-app-menu/back.js +++ b/plugins/in-app-menu/back.js @@ -20,9 +20,8 @@ module.exports = (win) => { return; } done = true; - let template = mainMenuTemplate(win, false, false, (item) => { - checkCheckbox(win, item); - }); + let template = mainMenuTemplate(win, false, false); + updateCheckboxesAndRadioButtons(win, template); let menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); @@ -48,3 +47,22 @@ function checkCheckbox(win, item) { //update menu (closes it) win.webContents.send("updateMenu", true); } + +// Update checkboxes/radio buttons +function updateCheckboxesAndRadioButtons(win, template) { + for (let index in template) { + let item = template[index]; + // Apply function on submenu + if (item.submenu != null) { + updateCheckboxesAndRadioButtons(win, item.submenu); + } + // Change onClick of checkbox+radio + else if (item.type === "checkbox" || item.type === "radio") { + let originalOnclick = item.click; + item.click = (itemClicked) => { + originalOnclick(itemClicked); + checkCheckbox(win, itemClicked); + }; + } + } +}