mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +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");
|
||||
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
|
||||
let done = false;
|
||||
|
||||
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.on("ready-to-show", () => {
|
||||
@ -31,27 +17,29 @@ module.exports = (winImport) => {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
let template = mainMenuTemplate(win);
|
||||
let template = mainMenuTemplate(win, false, (item) => {
|
||||
checkCheckbox(win, item);
|
||||
});
|
||||
let menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
||||
|
||||
//register keyboard shortcut && hide menu if hideMenu is enabled
|
||||
if (config.get("options.hideMenu")) {
|
||||
switchMenuVisibility();
|
||||
switchMenuVisibility(win);
|
||||
electronLocalshortcut.register(win, "Esc", () => {
|
||||
switchMenuVisibility();
|
||||
switchMenuVisibility(win);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let visible = true;
|
||||
function switchMenuVisibility() {
|
||||
function switchMenuVisibility(win) {
|
||||
visible = !visible;
|
||||
win.webContents.send("updateMenu", visible);
|
||||
}
|
||||
|
||||
function checkCheckbox(item) {
|
||||
function checkCheckbox(win, item) {
|
||||
//check item
|
||||
item.checked = !item.checked;
|
||||
//update menu (closes it)
|
||||
|
||||
Reference in New Issue
Block a user