Differentiate between refresh/toggle menu

+ visible now checks the actual state to fix PiP bugs
This commit is contained in:
Araxeus
2023-01-19 02:32:57 +02:00
parent 5909af42d2
commit 1eb0269434
2 changed files with 11 additions and 11 deletions

View File

@ -17,7 +17,7 @@ module.exports = (win) => {
attachTitlebarToWindow(win); attachTitlebarToWindow(win);
electronLocalshortcut.register(win, "`", () => { electronLocalshortcut.register(win, "`", () => {
win.webContents.send("refreshMenu", true); win.webContents.send("toggleMenu");
}); });
}); });
}; };

View File

@ -5,13 +5,13 @@ const { isEnabled } = require("../../config/plugins");
function $(selector) { return document.querySelector(selector); } function $(selector) { return document.querySelector(selector); }
module.exports = (options) => { module.exports = (options) => {
let visible = !config.get("options.hideMenu"); let visible = () => !!$('.cet-menubar').firstChild;
const bar = new Titlebar({ const bar = new Titlebar({
icon: "https://cdn-icons-png.flaticon.com/512/5358/5358672.png", icon: "https://cdn-icons-png.flaticon.com/512/5358/5358672.png",
backgroundColor: Color.fromHex("#050505"), backgroundColor: Color.fromHex("#050505"),
itemBackgroundColor: Color.fromHex("#1d1d1d"), itemBackgroundColor: Color.fromHex("#1d1d1d"),
svgColor: Color.WHITE, svgColor: Color.WHITE,
menu: visible ? undefined : null menu: config.get("options.hideMenu") ? null : undefined
}); });
bar.updateTitle(" "); bar.updateTitle(" ");
document.title = "Youtube Music"; document.title = "Youtube Music";
@ -23,21 +23,21 @@ module.exports = (options) => {
icon.firstChild.style.webkitUserDrag = 'none'; icon.firstChild.style.webkitUserDrag = 'none';
icon.firstChild.style.filter = 'invert(50%)'; icon.firstChild.style.filter = 'invert(50%)';
const updateMenu = () => { const toggleMenu = () => {
if (visible) { if (visible()) {
bar.updateMenu(null); bar.updateMenu(null);
visible = false;
} else { } else {
bar.refreshMenu(); bar.refreshMenu();
visible = true;
} }
}; };
icon.addEventListener('click', updateMenu); icon.addEventListener('click', toggleMenu);
ipcRenderer.on("toggleMenu", toggleMenu);
ipcRenderer.on("refreshMenu", (_, fromBack) => { ipcRenderer.on("refreshMenu", () => {
if (fromBack === undefined && !visible) return; if (visible()) {
updateMenu(); bar.refreshMenu();
}
}); });
if (isEnabled("picture-in-picture")) { if (isEnabled("picture-in-picture")) {