mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
Use template builder in custom menu plugin
This commit is contained in:
@ -5,24 +5,10 @@ const electronLocalshortcut = require("electron-localshortcut");
|
|||||||
const config = require("../../config");
|
const config = require("../../config");
|
||||||
var { mainMenuTemplate } = require("../../menu");
|
var { mainMenuTemplate } = require("../../menu");
|
||||||
|
|
||||||
//override menu template for custom menu
|
|
||||||
const originTemplate = mainMenuTemplate;
|
|
||||||
mainMenuTemplate = function (winHook) {
|
|
||||||
//get template
|
|
||||||
let template = originTemplate(winHook, false, (item) => {
|
|
||||||
checkCheckbox(item);
|
|
||||||
});
|
|
||||||
//return as normal
|
|
||||||
return template;
|
|
||||||
};
|
|
||||||
//win hook for fixing menu
|
|
||||||
let win;
|
|
||||||
|
|
||||||
//check that menu doesn't get created twice
|
//check that menu doesn't get created twice
|
||||||
let done = false;
|
let done = false;
|
||||||
|
|
||||||
module.exports = (winImport) => {
|
module.exports = (win) => {
|
||||||
win = winImport;
|
|
||||||
// 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"));
|
||||||
win.on("ready-to-show", () => {
|
win.on("ready-to-show", () => {
|
||||||
@ -31,27 +17,29 @@ module.exports = (winImport) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
let template = mainMenuTemplate(win);
|
let template = mainMenuTemplate(win, false, (item) => {
|
||||||
|
checkCheckbox(win, item);
|
||||||
|
});
|
||||||
let menu = Menu.buildFromTemplate(template);
|
let menu = Menu.buildFromTemplate(template);
|
||||||
Menu.setApplicationMenu(menu);
|
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")) {
|
||||||
switchMenuVisibility();
|
switchMenuVisibility(win);
|
||||||
electronLocalshortcut.register(win, "Esc", () => {
|
electronLocalshortcut.register(win, "Esc", () => {
|
||||||
switchMenuVisibility();
|
switchMenuVisibility(win);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let visible = true;
|
let visible = true;
|
||||||
function switchMenuVisibility() {
|
function switchMenuVisibility(win) {
|
||||||
visible = !visible;
|
visible = !visible;
|
||||||
win.webContents.send("updateMenu", visible);
|
win.webContents.send("updateMenu", visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCheckbox(item) {
|
function checkCheckbox(win, item) {
|
||||||
//check item
|
//check item
|
||||||
item.checked = !item.checked;
|
item.checked = !item.checked;
|
||||||
//update menu (closes it)
|
//update menu (closes it)
|
||||||
|
|||||||
Reference in New Issue
Block a user