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:
@ -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