mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-18 13:42:06 +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: {
|
navigation: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
shortcuts: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
adblocker: {
|
adblocker: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
cache: true,
|
cache: true,
|
||||||
additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt"
|
additionalBlockLists: [], // Additional list of filters, e.g "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt"
|
||||||
},
|
},
|
||||||
// Disabled plugins
|
// Disabled plugins
|
||||||
|
shortcuts: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
downloader: {
|
downloader: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s
|
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s
|
||||||
downloadFolder: undefined, // Custom download folder (absolute path)
|
downloadFolder: undefined, // Custom download folder (absolute path)
|
||||||
},
|
},
|
||||||
discord: {
|
discord: {
|
||||||
|
enabled: false,
|
||||||
activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below
|
activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below
|
||||||
activityTimoutTime: 10 * 60 * 1000 // 10 minutes
|
activityTimoutTime: 10 * 60 * 1000 // 10 minutes
|
||||||
},
|
},
|
||||||
|
|||||||
13
menu.js
13
menu.js
@ -7,7 +7,7 @@ const is = require("electron-is");
|
|||||||
const { getAllPlugins } = require("./plugins/utils");
|
const { getAllPlugins } = require("./plugins/utils");
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
|
|
||||||
const pluginEnabledMenu = (plugin, label = "") => ({
|
const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({
|
||||||
label: label || plugin,
|
label: label || plugin,
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: config.plugins.isEnabled(plugin),
|
checked: config.plugins.isEnabled(plugin),
|
||||||
@ -17,6 +17,9 @@ const pluginEnabledMenu = (plugin, label = "") => ({
|
|||||||
} else {
|
} else {
|
||||||
config.plugins.disable(plugin);
|
config.plugins.disable(plugin);
|
||||||
}
|
}
|
||||||
|
if (hasSubmenu) {
|
||||||
|
this.setApplicationMenu(win);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -27,16 +30,16 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
|
|||||||
...getAllPlugins().map((plugin) => {
|
...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)) {
|
if (!config.plugins.isEnabled(plugin)) {
|
||||||
return pluginEnabledMenu(plugin);
|
return pluginEnabledMenu(win, plugin, "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existsSync(pluginPath)) {
|
|
||||||
const getPluginMenu = require(pluginPath);
|
const getPluginMenu = require(pluginPath);
|
||||||
return {
|
return {
|
||||||
label: plugin,
|
label: plugin,
|
||||||
submenu: [
|
submenu: [
|
||||||
pluginEnabledMenu(plugin, "Enabled"),
|
pluginEnabledMenu(win, plugin, "Enabled", true),
|
||||||
...getPluginMenu(win, config.plugins.getOptions(plugin), () =>
|
...getPluginMenu(win, config.plugins.getOptions(plugin), () =>
|
||||||
module.exports.setApplicationMenu(win)
|
module.exports.setApplicationMenu(win)
|
||||||
),
|
),
|
||||||
@ -44,7 +47,7 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return pluginEnabledMenu(plugin);
|
return pluginEnabledMenu(win, plugin);
|
||||||
}),
|
}),
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,13 +4,27 @@ const { Menu } = require("electron");
|
|||||||
const electronLocalshortcut = require("electron-localshortcut");
|
const electronLocalshortcut = require("electron-localshortcut");
|
||||||
|
|
||||||
const config = require("../../config");
|
const config = require("../../config");
|
||||||
const { mainMenuTemplate } = require("../../menu");
|
const { setApplicationMenu } = require("../../menu");
|
||||||
const { injectCSS } = require("../utils");
|
const { injectCSS } = require("../utils");
|
||||||
|
|
||||||
//check that menu doesn't get created twice
|
//check that menu doesn't get created twice
|
||||||
let done = false;
|
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)
|
// css for custom scrollbar + disable drag area(was causing bugs)
|
||||||
injectCSS(win.webContents, path.join(__dirname, "style.css"));
|
injectCSS(win.webContents, path.join(__dirname, "style.css"));
|
||||||
|
|
||||||
@ -20,10 +34,8 @@ module.exports = (win) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
let template = mainMenuTemplate(win, false, false);
|
|
||||||
updateCheckboxesAndRadioButtons(win, template);
|
setApplicationMenu(win);
|
||||||
let menu = Menu.buildFromTemplate(template);
|
|
||||||
Menu.setApplicationMenu(menu);
|
|
||||||
|
|
||||||
//register keyboard shortcut && hide menu if hideMenu is enabled
|
//register keyboard shortcut && hide menu if hideMenu is enabled
|
||||||
if (config.get("options.hideMenu")) {
|
if (config.get("options.hideMenu")) {
|
||||||
@ -50,19 +62,15 @@ function checkCheckbox(win, item) {
|
|||||||
|
|
||||||
// Update checkboxes/radio buttons
|
// Update checkboxes/radio buttons
|
||||||
function updateCheckboxesAndRadioButtons(win, template) {
|
function updateCheckboxesAndRadioButtons(win, template) {
|
||||||
for (let index in template) {
|
for (let item of template) {
|
||||||
let item = template[index];
|
|
||||||
// Apply function on submenu
|
|
||||||
if (item.submenu != null) {
|
|
||||||
updateCheckboxesAndRadioButtons(win, item.submenu);
|
|
||||||
}
|
|
||||||
// Change onClick of checkbox+radio
|
// 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;
|
let originalOnclick = item.click;
|
||||||
item.click = (itemClicked) => {
|
item.click = (itemClicked) => {
|
||||||
originalOnclick(itemClicked);
|
originalOnclick(itemClicked);
|
||||||
checkCheckbox(win, itemClicked);
|
checkCheckbox(win, itemClicked);
|
||||||
};
|
};
|
||||||
|
item.fixed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user