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 }, diff --git a/menu.js b/menu.js index f641d184..f974c4e4 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 = "", hasSubmenu = false) => ({ label: label || plugin, type: "checkbox", checked: config.plugins.isEnabled(plugin), @@ -17,6 +17,9 @@ const pluginEnabledMenu = (plugin, label = "") => ({ } else { config.plugins.disable(plugin); } + if (hasSubmenu) { + this.setApplicationMenu(win); + } }, }); @@ -27,16 +30,16 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ ...getAllPlugins().map((plugin) => { const pluginPath = path.join(__dirname, "plugins", plugin, "menu.js"); - if (!config.plugins.isEnabled(plugin)) { - return pluginEnabledMenu(plugin); - } - if (existsSync(pluginPath)) { + if (!config.plugins.isEnabled(plugin)) { + return pluginEnabledMenu(win, plugin, "", true); + } + const getPluginMenu = require(pluginPath); return { label: plugin, submenu: [ - pluginEnabledMenu(plugin, "Enabled"), + pluginEnabledMenu(win, plugin, "Enabled", true), ...getPluginMenu(win, config.plugins.getOptions(plugin), () => module.exports.setApplicationMenu(win) ), @@ -44,7 +47,7 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }; } - return pluginEnabledMenu(plugin); + return pluginEnabledMenu(win, plugin); }), { type: "separator" }, { diff --git a/plugins/in-app-menu/back.js b/plugins/in-app-menu/back.js index 7f9d6644..3c77c377 100644 --- a/plugins/in-app-menu/back.js +++ b/plugins/in-app-menu/back.js @@ -4,13 +4,27 @@ const { Menu } = require("electron"); const electronLocalshortcut = require("electron-localshortcut"); const config = require("../../config"); -const { mainMenuTemplate } = require("../../menu"); +const { setApplicationMenu } = require("../../menu"); const { injectCSS } = require("../utils"); //check that menu doesn't get created twice let done = false; +// win hook for fixing menu +let win; + +const originalBuildMenu = Menu.buildFromTemplate; +// This function natively gets called on all submenu so no more reason to use recursion +Menu.buildFromTemplate = (template) => { + // Fix checkboxes and radio buttons + updateCheckboxesAndRadioButtons(win, template); + + // return as normal + return originalBuildMenu(template); +}; + +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")); @@ -20,10 +34,8 @@ module.exports = (win) => { return; } done = true; - let template = mainMenuTemplate(win, false, false); - updateCheckboxesAndRadioButtons(win, template); - let menu = Menu.buildFromTemplate(template); - Menu.setApplicationMenu(menu); + + setApplicationMenu(win); //register keyboard shortcut && hide menu if hideMenu is enabled if (config.get("options.hideMenu")) { @@ -50,19 +62,15 @@ function checkCheckbox(win, item) { // 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); - } + for (let item of template) { // Change onClick of checkbox+radio - else if (item.type === "checkbox" || item.type === "radio") { + if ((item.type === "checkbox" || item.type === "radio") && !item.fixed) { let originalOnclick = item.click; item.click = (itemClicked) => { originalOnclick(itemClicked); checkCheckbox(win, itemClicked); }; + item.fixed = true; } } }