mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 12:42:06 +00:00
Replace click callback by override in custom menu
This commit is contained in:
18
menu.js
18
menu.js
@ -20,12 +20,7 @@ const pluginEnabledMenu = (plugin, label = "") => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const mainMenuTemplate = (
|
const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
|
||||||
win,
|
|
||||||
withRoles = true,
|
|
||||||
isTray = false,
|
|
||||||
clickCb = () => {}
|
|
||||||
) => [
|
|
||||||
{
|
{
|
||||||
label: "Plugins",
|
label: "Plugins",
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -69,7 +64,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.autoUpdates"),
|
checked: config.get("options.autoUpdates"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.autoUpdates", item.checked);
|
config.set("options.autoUpdates", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -78,7 +72,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.disableHardwareAcceleration"),
|
checked: config.get("options.disableHardwareAcceleration"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.disableHardwareAcceleration", item.checked);
|
config.set("options.disableHardwareAcceleration", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -87,7 +80,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.restartOnConfigChanges"),
|
checked: config.get("options.restartOnConfigChanges"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.restartOnConfigChanges", item.checked);
|
config.set("options.restartOnConfigChanges", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -96,7 +88,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.autoResetAppCache"),
|
checked: config.get("options.autoResetAppCache"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.autoResetAppCache", item.checked);
|
config.set("options.autoResetAppCache", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -105,7 +96,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.resumeOnStart"),
|
checked: config.get("options.resumeOnStart"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.resumeOnStart", item.checked);
|
config.set("options.resumeOnStart", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...(is.windows() || is.linux()
|
...(is.windows() || is.linux()
|
||||||
@ -116,7 +106,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.hideMenu"),
|
checked: config.get("options.hideMenu"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.hideMenu", item.checked);
|
config.set("options.hideMenu", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -131,7 +120,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.startAtLogin"),
|
checked: config.get("options.startAtLogin"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.startAtLogin", item.checked);
|
config.set("options.startAtLogin", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -146,7 +134,6 @@ const mainMenuTemplate = (
|
|||||||
click: () => {
|
click: () => {
|
||||||
config.set("options.tray", false);
|
config.set("options.tray", false);
|
||||||
config.set("options.appVisible", true);
|
config.set("options.appVisible", true);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -157,7 +144,6 @@ const mainMenuTemplate = (
|
|||||||
click: () => {
|
click: () => {
|
||||||
config.set("options.tray", true);
|
config.set("options.tray", true);
|
||||||
config.set("options.appVisible", true);
|
config.set("options.appVisible", true);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -168,7 +154,6 @@ const mainMenuTemplate = (
|
|||||||
click: () => {
|
click: () => {
|
||||||
config.set("options.tray", true);
|
config.set("options.tray", true);
|
||||||
config.set("options.appVisible", false);
|
config.set("options.appVisible", false);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
@ -178,7 +163,6 @@ const mainMenuTemplate = (
|
|||||||
checked: config.get("options.trayClickPlayPause"),
|
checked: config.get("options.trayClickPlayPause"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
config.set("options.trayClickPlayPause", item.checked);
|
config.set("options.trayClickPlayPause", item.checked);
|
||||||
clickCb(item);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@ -20,9 +20,8 @@ module.exports = (win) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
let template = mainMenuTemplate(win, false, false, (item) => {
|
let template = mainMenuTemplate(win, false, false);
|
||||||
checkCheckbox(win, item);
|
updateCheckboxesAndRadioButtons(win, template);
|
||||||
});
|
|
||||||
let menu = Menu.buildFromTemplate(template);
|
let menu = Menu.buildFromTemplate(template);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
@ -48,3 +47,22 @@ function checkCheckbox(win, item) {
|
|||||||
//update menu (closes it)
|
//update menu (closes it)
|
||||||
win.webContents.send("updateMenu", true);
|
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);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user