From 58481e3133dfe5b256633bc61125c3f816a6ce85 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 18:10:08 +0300 Subject: [PATCH 1/5] Refresh menu on plugin enable/disable --- menu.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/menu.js b/menu.js index 3f5744b4..bb0424b5 100644 --- a/menu.js +++ b/menu.js @@ -7,7 +7,7 @@ const is = require("electron-is"); const { getAllPlugins } = require("./plugins/utils"); const config = require("./config"); -const pluginEnabledMenu = (plugin, label = "") => ({ +const pluginEnabledMenu = (win, plugin, label = "") => ({ label: label || plugin, type: "checkbox", checked: config.plugins.isEnabled(plugin), @@ -17,6 +17,7 @@ const pluginEnabledMenu = (plugin, label = "") => ({ } else { config.plugins.disable(plugin); } + this.setApplicationMenu(win); }, }); @@ -28,7 +29,7 @@ const mainMenuTemplate = (win) => [ const pluginPath = path.join(__dirname, "plugins", plugin, "menu.js"); if (!config.plugins.isEnabled(plugin)) { - return pluginEnabledMenu(plugin); + return pluginEnabledMenu(win, plugin); } if (existsSync(pluginPath)) { @@ -36,7 +37,7 @@ const mainMenuTemplate = (win) => [ return { label: plugin, submenu: [ - pluginEnabledMenu(plugin, "Enabled"), + pluginEnabledMenu(win, plugin, "Enabled"), ...getPluginMenu(win, config.plugins.getOptions(plugin), () => module.exports.setApplicationMenu(win) ), @@ -44,7 +45,7 @@ const mainMenuTemplate = (win) => [ }; } - return pluginEnabledMenu(plugin); + return pluginEnabledMenu(win, plugin); }), { type: "separator" }, { From adc0d145c320e745f7dc05baf59085741318fae3 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 19:02:39 +0300 Subject: [PATCH 2/5] update styled-bars to support all changes permantly --- plugins/styled-bars/back.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index 37fd6c8b..433a56d8 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -5,23 +5,24 @@ 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); +//override Menu.buildFromTemplate to also fix menu +const originBuildMenu = Menu.buildFromTemplate; +//this function natively gets called on all submenu so no more reason to use recursion +Menu.buildFromTemplate = function (template) { //fix checkbox and roles fixMenu(template); //return as normal - return template; + return originBuildMenu(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 => { + //override menu template for custom menu win = winImport; // css for custom scrollbar + disable drag area(was causing bugs) injectCSS(win.webContents, path.join(__dirname, 'style.css')); @@ -55,12 +56,9 @@ function switchMenuVisibility() { 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') { + //change onClick of checkbox+radio if not fixed + if ((item.type === 'checkbox' || item.type === 'radio') && !item.fixed) { + item.fixed = true; let ogOnclick = item.click; item.click = (itemClicked) => { ogOnclick(itemClicked); From 02d45bed7489dd497d80aa6aad29b1422b2b1b9d Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 19:21:21 +0300 Subject: [PATCH 3/5] only refresh if plugin has a menu.js --- menu.js | 15 ++++++++------- plugins/styled-bars/back.js | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/menu.js b/menu.js index bb0424b5..68c96e77 100644 --- a/menu.js +++ b/menu.js @@ -7,7 +7,7 @@ const is = require("electron-is"); const { getAllPlugins } = require("./plugins/utils"); const config = require("./config"); -const pluginEnabledMenu = (win, plugin, label = "") => ({ +const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu=false) => ({ label: label || plugin, type: "checkbox", checked: config.plugins.isEnabled(plugin), @@ -17,7 +17,9 @@ const pluginEnabledMenu = (win, plugin, label = "") => ({ } else { config.plugins.disable(plugin); } - this.setApplicationMenu(win); + if(hasSubmenu) { + this.setApplicationMenu(win); + } }, }); @@ -28,16 +30,15 @@ const mainMenuTemplate = (win) => [ ...getAllPlugins().map((plugin) => { const pluginPath = path.join(__dirname, "plugins", plugin, "menu.js"); - if (!config.plugins.isEnabled(plugin)) { - return pluginEnabledMenu(win, plugin); - } - if (existsSync(pluginPath)) { + if (!config.plugins.isEnabled(plugin)) { + return pluginEnabledMenu(win, plugin, "", true); + } const getPluginMenu = require(pluginPath); return { label: plugin, submenu: [ - pluginEnabledMenu(win, plugin, "Enabled"), + pluginEnabledMenu(win, plugin, "Enabled", true), ...getPluginMenu(win, config.plugins.getOptions(plugin), () => module.exports.setApplicationMenu(win) ), diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index 433a56d8..8c9a9185 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -22,7 +22,6 @@ let win; let done = false; module.exports = winImport => { - //override menu template for custom menu win = winImport; // css for custom scrollbar + disable drag area(was causing bugs) injectCSS(win.webContents, path.join(__dirname, 'style.css')); From 5670a6d1b4c042c05bb35000e32290b309fb0413 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 21:09:31 +0300 Subject: [PATCH 4/5] cleanup styled-bars code --- plugins/styled-bars/back.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/styled-bars/back.js b/plugins/styled-bars/back.js index 8c9a9185..65b55fc1 100644 --- a/plugins/styled-bars/back.js +++ b/plugins/styled-bars/back.js @@ -3,9 +3,9 @@ const { Menu } = require('electron'); const path = require('path'); const electronLocalshortcut = require("electron-localshortcut"); const config = require('../../config'); -var { mainMenuTemplate } = require("../../menu"); +const { setApplicationMenu } = require("../../menu"); -//override Menu.buildFromTemplate to also fix menu +//override Menu.buildFromTemplate, making it also fix the template const originBuildMenu = Menu.buildFromTemplate; //this function natively gets called on all submenu so no more reason to use recursion Menu.buildFromTemplate = function (template) { @@ -21,7 +21,7 @@ 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')); @@ -31,9 +31,9 @@ module.exports = winImport => { return } done = true; - let template = mainMenuTemplate(win); - let menu = Menu.buildFromTemplate(template); - Menu.setApplicationMenu(menu); + + //refresh menu to fix it + setApplicationMenu(win); //register keyboard shortcut && hide menu if hideMenu is enabled if (config.get('options.hideMenu')) { @@ -53,18 +53,17 @@ function switchMenuVisibility() { //go over each item in menu function fixMenu(template) { - for (let index in template) { - let item = template[index]; + for (let item of template) { //change onClick of checkbox+radio if not fixed if ((item.type === 'checkbox' || item.type === 'radio') && !item.fixed) { - item.fixed = true; let ogOnclick = item.click; item.click = (itemClicked) => { ogOnclick(itemClicked); checkCheckbox(itemClicked); }; + item.fixed = true; } - //customize roles + //customize roles (will be deleted soon) else if (item.role != null) { fixRoles(item) } From e66db051a975f86510f392dd88954d5a69fe9fd1 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 1 Apr 2021 21:24:11 +0300 Subject: [PATCH 5/5] remove 'shortcuts'+'discord' from default plugins --- config/defaults.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index 25f8141f..946a2ba5 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -21,21 +21,22 @@ const defaultConfig = { navigation: { enabled: true, }, - shortcuts: { - enabled: true, - }, adblocker: { enabled: true, cache: true, additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt" }, // Disabled plugins + shortcuts: { + enabled: false, + }, downloader: { enabled: false, ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s downloadFolder: undefined, // Custom download folder (absolute path) }, discord: { + enabled: false, activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below activityTimoutTime: 10 * 60 * 1000 // 10 minutes },