mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
update in-app-menu
This commit is contained in:
5
menu.js
5
menu.js
@ -11,8 +11,6 @@ const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({
|
||||
label: label || plugin,
|
||||
type: "checkbox",
|
||||
checked: config.plugins.isEnabled(plugin),
|
||||
//Submenu check used in in-app-menu
|
||||
hasSubmenu: hasSubmenu || undefined,
|
||||
click: (item) => {
|
||||
if (item.checked) {
|
||||
config.plugins.enable(plugin);
|
||||
@ -21,6 +19,9 @@ const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({
|
||||
}
|
||||
if (hasSubmenu) {
|
||||
this.setApplicationMenu(win);
|
||||
if (config.plugins.isEnabled("in-app-menu")) {
|
||||
win.webContents.send("updateMenu", true);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,83 +1,33 @@
|
||||
const path = require("path");
|
||||
|
||||
const { Menu } = require("electron");
|
||||
const electronLocalshortcut = require("electron-localshortcut");
|
||||
|
||||
const config = require("../../config");
|
||||
const { setApplicationMenu } = require("../../menu");
|
||||
const { injectCSS } = require("../utils");
|
||||
|
||||
//tracks menu visibility
|
||||
let visible = true;
|
||||
// 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
|
||||
updateTemplate(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"));
|
||||
|
||||
win.once("ready-to-show", () => {
|
||||
|
||||
setApplicationMenu(win);
|
||||
|
||||
//register keyboard shortcut && hide menu if hideMenu is enabled
|
||||
if (config.get("options.hideMenu")) {
|
||||
electronLocalshortcut.register(win, "Esc", () => {
|
||||
switchMenuVisibility();
|
||||
setMenuVisibility(!visible);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//set menu visibility on load
|
||||
win.webContents.once("did-finish-load", () => {
|
||||
// fix bug with menu not applying on start when no internet connection available
|
||||
setMenuVisibility(!config.get("options.hideMenu"));
|
||||
});
|
||||
|
||||
function setMenuVisibility(value) {
|
||||
visible = value;
|
||||
win.webContents.send("updateMenu", visible);
|
||||
}
|
||||
};
|
||||
|
||||
function switchMenuVisibility() {
|
||||
setMenuVisibility(!visible);
|
||||
}
|
||||
|
||||
function setMenuVisibility(value) {
|
||||
visible = value;
|
||||
win.webContents.send("updateMenu", visible);
|
||||
}
|
||||
|
||||
function updateCheckboxesAndRadioButtons(item, isRadio, hasSubmenu) {
|
||||
if (!isRadio) {
|
||||
//fix checkbox
|
||||
item.checked = !item.checked;
|
||||
}
|
||||
//update menu if radio / hasSubmenu
|
||||
if (isRadio || hasSubmenu) {
|
||||
win.webContents.send("updateMenu", true);
|
||||
}
|
||||
}
|
||||
|
||||
// Update checkboxes/radio buttons
|
||||
function updateTemplate(template) {
|
||||
for (let item of template) {
|
||||
// Change onClick of checkbox+radio
|
||||
if ((item.type === "checkbox" || item.type === "radio") && !item.fixed) {
|
||||
const originalOnclick = item.click;
|
||||
item.click = (itemClicked) => {
|
||||
originalOnclick(itemClicked);
|
||||
updateCheckboxesAndRadioButtons(itemClicked, item.type === "radio", item.hasSubmenu);
|
||||
};
|
||||
item.fixed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,15 +10,7 @@ module.exports = () => {
|
||||
bar.updateTitle(" ");
|
||||
document.title = "Youtube Music";
|
||||
|
||||
ipcRenderer.on("updateMenu", function (event, menu) {
|
||||
if (menu) {
|
||||
bar.updateMenu(remote.Menu.getApplicationMenu());
|
||||
} else {
|
||||
try {
|
||||
bar.updateMenu(null);
|
||||
} catch (e) {
|
||||
//will always throw type error - null isn't menu, but it works
|
||||
}
|
||||
}
|
||||
ipcRenderer.on("updateMenu", function (_event, showMenu) {
|
||||
bar.updateMenu(showMenu ? remote.Menu.getApplicationMenu() : null);
|
||||
});
|
||||
};
|
||||
|
||||
@ -4,11 +4,6 @@
|
||||
font-size: 14px !important;
|
||||
}
|
||||
|
||||
/* allow submenu's to show correctly */
|
||||
.menubar-menu-container {
|
||||
overflow-y: visible !important;
|
||||
}
|
||||
|
||||
/* fixes scrollbar positioning relative to nav bar */
|
||||
#nav-bar-background.ytmusic-app-layout {
|
||||
right: 15px !important;
|
||||
|
||||
Reference in New Issue
Block a user