From 09bd271df2b657f2a5bcee5b701c44351456975b Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Sun, 6 Feb 2022 03:32:15 +0200 Subject: [PATCH] update in-app-menu --- menu.js | 2 +- package.json | 2 +- plugins/in-app-menu/back.js | 14 +++++++------- plugins/in-app-menu/front.js | 26 +++++++++++++++++--------- providers/prompt-custom-titlebar.js | 6 +++--- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/menu.js b/menu.js index 0a62249b..fe49b44b 100644 --- a/menu.js +++ b/menu.js @@ -33,7 +33,7 @@ const mainMenuTemplate = (win) => { const refreshMenu = () => { this.setApplicationMenu(win); if (inAppMenuActive) { - win.webContents.send("updateMenu", true); + win.webContents.send("refreshMenu"); } } return [ diff --git a/package.json b/package.json index 15be4d6e..20b6cd98 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "browser-id3-writer": "^4.4.0", "chokidar": "^3.5.2", "custom-electron-prompt": "^1.4.0", - "custom-electron-titlebar": "^3.2.10", + "custom-electron-titlebar": "^4.1.0", "discord-rpc": "^3.2.0", "electron-better-web-request": "^1.0.1", "electron-debug": "^3.2.0", diff --git a/plugins/in-app-menu/back.js b/plugins/in-app-menu/back.js index 9624bb77..b75e8a32 100644 --- a/plugins/in-app-menu/back.js +++ b/plugins/in-app-menu/back.js @@ -5,14 +5,19 @@ const electronLocalshortcut = require("electron-localshortcut"); const config = require("../../config"); const { injectCSS } = require("../utils"); +const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main'); +setupTitlebar(); + //tracks menu visibility -let visible = true; +let visible = !config.get("options.hideMenu"); module.exports = (win) => { // css for custom scrollbar + disable drag area(was causing bugs) injectCSS(win.webContents, path.join(__dirname, "style.css")); win.once("ready-to-show", () => { + attachTitlebarToWindow(win); + //register keyboard shortcut && hide menu if hideMenu is enabled if (config.get("options.hideMenu")) { electronLocalshortcut.register(win, "Esc", () => { @@ -21,13 +26,8 @@ module.exports = (win) => { } }); - win.webContents.once("did-finish-load", () => { - // fix bug with menu not applying on start when no internet connection available - setMenuVisibility(!config.get("options.hideMenu")); - }); - function setMenuVisibility(value) { visible = value; - win.webContents.send("updateMenu", visible); + win.webContents.send("refreshMenu", visible); } }; diff --git a/plugins/in-app-menu/front.js b/plugins/in-app-menu/front.js index f576f588..1bd8d4be 100644 --- a/plugins/in-app-menu/front.js +++ b/plugins/in-app-menu/front.js @@ -1,20 +1,28 @@ const { ipcRenderer } = require("electron"); -const { Menu } = require("@electron/remote"); - - -const customTitlebar = require("custom-electron-titlebar"); +const config = require("../../config"); +const { Titlebar, Color } = require("custom-electron-titlebar"); function $(selector) { return document.querySelector(selector); } module.exports = () => { - const bar = new customTitlebar.Titlebar({ - backgroundColor: customTitlebar.Color.fromHex("#050505"), - itemBackgroundColor: customTitlebar.Color.fromHex("#121212"), + let visible = !config.get("options.hideMenu"); + const bar = new Titlebar({ + backgroundColor: Color.fromHex("#050505"), + itemBackgroundColor: Color.fromHex("#121212"), + svgColor: Color.WHITE, + menu: visible ? undefined : null }); bar.updateTitle(" "); document.title = "Youtube Music"; - ipcRenderer.on("updateMenu", function (_event, showMenu) { - bar.updateMenu(showMenu ? Menu.getApplicationMenu() : null); + ipcRenderer.on("refreshMenu", (_, showMenu) => { + if (showMenu === undefined && !visible) return; + if (showMenu === false) { + bar.updateMenu(null); + visible = false; + } else { + bar.refreshMenu(); + visible = true; + } }); // Increases the right margin of Navbar background when the scrollbar is visible to avoid blocking it (z-index doesn't affect it) diff --git a/providers/prompt-custom-titlebar.js b/providers/prompt-custom-titlebar.js index affa9206..222a6bd6 100644 --- a/providers/prompt-custom-titlebar.js +++ b/providers/prompt-custom-titlebar.js @@ -1,8 +1,8 @@ -const customTitlebar = require("custom-electron-titlebar"); +const { Titlebar, Color } = require("custom-electron-titlebar"); module.exports = () => { - new customTitlebar.Titlebar({ - backgroundColor: customTitlebar.Color.fromHex("#050505"), + new Titlebar({ + backgroundColor: Color.fromHex("#050505"), minimizable: false, maximizable: false, menu: null