mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
Pass callback in menu builder
This commit is contained in:
13
menu.js
13
menu.js
@ -20,7 +20,7 @@ const pluginEnabledMenu = (plugin, label = "") => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const mainMenuTemplate = (win, withRoles = true) => [
|
const mainMenuTemplate = (win, withRoles = true, clickCb = () => {}) => [
|
||||||
{
|
{
|
||||||
label: "Plugins",
|
label: "Plugins",
|
||||||
submenu: [
|
submenu: [
|
||||||
@ -64,6 +64,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -72,6 +73,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -80,6 +82,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -88,6 +91,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -96,6 +100,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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()
|
||||||
@ -106,6 +111,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -120,6 +126,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -134,6 +141,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
click: () => {
|
click: () => {
|
||||||
config.set("options.tray", false);
|
config.set("options.tray", false);
|
||||||
config.set("options.appVisible", true);
|
config.set("options.appVisible", true);
|
||||||
|
clickCb(item);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -144,6 +152,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
click: () => {
|
click: () => {
|
||||||
config.set("options.tray", true);
|
config.set("options.tray", true);
|
||||||
config.set("options.appVisible", true);
|
config.set("options.appVisible", true);
|
||||||
|
clickCb(item);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -154,6 +163,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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" },
|
||||||
@ -163,6 +173,7 @@ const mainMenuTemplate = (win, withRoles = true) => [
|
|||||||
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);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@ -9,9 +9,9 @@ var { mainMenuTemplate } = require("../../menu");
|
|||||||
const originTemplate = mainMenuTemplate;
|
const originTemplate = mainMenuTemplate;
|
||||||
mainMenuTemplate = function (winHook) {
|
mainMenuTemplate = function (winHook) {
|
||||||
//get template
|
//get template
|
||||||
let template = originTemplate(winHook, false);
|
let template = originTemplate(winHook, false, (item) => {
|
||||||
//fix checkbox and roles
|
checkCheckbox(item);
|
||||||
fixMenu(template);
|
});
|
||||||
//return as normal
|
//return as normal
|
||||||
return template;
|
return template;
|
||||||
};
|
};
|
||||||
@ -51,25 +51,6 @@ function switchMenuVisibility() {
|
|||||||
win.webContents.send("updateMenu", visible);
|
win.webContents.send("updateMenu", visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
//go over each item in menu
|
|
||||||
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") {
|
|
||||||
let ogOnclick = item.click;
|
|
||||||
item.click = (itemClicked) => {
|
|
||||||
ogOnclick(itemClicked);
|
|
||||||
checkCheckbox(itemClicked);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkCheckbox(item) {
|
function checkCheckbox(item) {
|
||||||
//check item
|
//check item
|
||||||
item.checked = !item.checked;
|
item.checked = !item.checked;
|
||||||
|
|||||||
Reference in New Issue
Block a user