From 1eb0269434a3012ab32f9fefd814362b8474eb45 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 19 Jan 2023 02:32:57 +0200 Subject: [PATCH] Differentiate between refresh/toggle menu + visible now checks the actual state to fix PiP bugs --- plugins/in-app-menu/back.js | 2 +- plugins/in-app-menu/front.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/in-app-menu/back.js b/plugins/in-app-menu/back.js index 133d5a29..d0a54605 100644 --- a/plugins/in-app-menu/back.js +++ b/plugins/in-app-menu/back.js @@ -17,7 +17,7 @@ module.exports = (win) => { attachTitlebarToWindow(win); electronLocalshortcut.register(win, "`", () => { - win.webContents.send("refreshMenu", true); + win.webContents.send("toggleMenu"); }); }); }; diff --git a/plugins/in-app-menu/front.js b/plugins/in-app-menu/front.js index b7fcdbc6..9f93195f 100644 --- a/plugins/in-app-menu/front.js +++ b/plugins/in-app-menu/front.js @@ -5,13 +5,13 @@ const { isEnabled } = require("../../config/plugins"); function $(selector) { return document.querySelector(selector); } module.exports = (options) => { - let visible = !config.get("options.hideMenu"); + let visible = () => !!$('.cet-menubar').firstChild; const bar = new Titlebar({ icon: "https://cdn-icons-png.flaticon.com/512/5358/5358672.png", backgroundColor: Color.fromHex("#050505"), itemBackgroundColor: Color.fromHex("#1d1d1d"), svgColor: Color.WHITE, - menu: visible ? undefined : null + menu: config.get("options.hideMenu") ? null : undefined }); bar.updateTitle(" "); document.title = "Youtube Music"; @@ -23,21 +23,21 @@ module.exports = (options) => { icon.firstChild.style.webkitUserDrag = 'none'; icon.firstChild.style.filter = 'invert(50%)'; - const updateMenu = () => { - if (visible) { + const toggleMenu = () => { + if (visible()) { bar.updateMenu(null); - visible = false; } else { bar.refreshMenu(); - visible = true; } }; - icon.addEventListener('click', updateMenu); + icon.addEventListener('click', toggleMenu); + ipcRenderer.on("toggleMenu", toggleMenu); - ipcRenderer.on("refreshMenu", (_, fromBack) => { - if (fromBack === undefined && !visible) return; - updateMenu(); + ipcRenderer.on("refreshMenu", () => { + if (visible()) { + bar.refreshMenu(); + } }); if (isEnabled("picture-in-picture")) {