mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Merge branch 'master' of github.com:th-ch/youtube-music into menu-options
# By Araxeus # Via GitHub (2) and Araxeus (1) * 'master' of github.com:th-ch/youtube-music: remove 'shortcuts'+'discord' from default plugins cleanup styled-bars code only refresh if plugin has a menu.js update styled-bars to support all changes permantly Refresh menu on plugin enable/disable
This commit is contained in:
@ -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
|
||||
},
|
||||
|
||||
17
menu.js
17
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" },
|
||||
{
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user