Skip to content

Commit 2dd208c

Browse files
authored
Merge pull request #596 from Araxeus/update-custom-electron-titlebar
update in-app-menu
2 parents c7fe814 + 0acd16f commit 2dd208c

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
/dist
33
/assets/generated
44
electron-builder.yml
5+
.vscode/settings.json

menu.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const mainMenuTemplate = (win) => {
3333
const refreshMenu = () => {
3434
this.setApplicationMenu(win);
3535
if (inAppMenuActive) {
36-
win.webContents.send("updateMenu", true);
36+
win.webContents.send("refreshMenu");
3737
}
3838
}
3939
return [
@@ -254,6 +254,8 @@ const mainMenuTemplate = (win) => {
254254
{ role: "zoomIn" },
255255
{ role: "zoomOut" },
256256
{ role: "resetZoom" },
257+
{ type: "separator" },
258+
{ role: "togglefullscreen" },
257259
],
258260
},
259261
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"browser-id3-writer": "^4.4.0",
9494
"chokidar": "^3.5.3",
9595
"custom-electron-prompt": "^1.4.1",
96-
"custom-electron-titlebar": "^3.2.10",
96+
"custom-electron-titlebar": "^4.1.0",
9797
"discord-rpc": "^4.0.1",
9898
"electron-better-web-request": "^1.0.1",
9999
"electron-debug": "^3.2.0",

plugins/in-app-menu/back.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ const electronLocalshortcut = require("electron-localshortcut");
55
const config = require("../../config");
66
const { injectCSS } = require("../utils");
77

8+
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main');
9+
setupTitlebar();
10+
811
//tracks menu visibility
9-
let visible = true;
12+
let visible = !config.get("options.hideMenu");
1013

1114
module.exports = (win) => {
1215
// css for custom scrollbar + disable drag area(was causing bugs)
1316
injectCSS(win.webContents, path.join(__dirname, "style.css"));
1417

1518
win.once("ready-to-show", () => {
19+
attachTitlebarToWindow(win);
20+
1621
//register keyboard shortcut && hide menu if hideMenu is enabled
1722
if (config.get("options.hideMenu")) {
1823
electronLocalshortcut.register(win, "Esc", () => {
@@ -21,13 +26,8 @@ module.exports = (win) => {
2126
}
2227
});
2328

24-
win.webContents.once("did-finish-load", () => {
25-
// fix bug with menu not applying on start when no internet connection available
26-
setMenuVisibility(!config.get("options.hideMenu"));
27-
});
28-
2929
function setMenuVisibility(value) {
3030
visible = value;
31-
win.webContents.send("updateMenu", visible);
31+
win.webContents.send("refreshMenu", visible);
3232
}
3333
};

plugins/in-app-menu/front.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
const { ipcRenderer } = require("electron");
2-
const { Menu } = require("@electron/remote");
3-
4-
5-
const customTitlebar = require("custom-electron-titlebar");
2+
const config = require("../../config");
3+
const { Titlebar, Color } = require("custom-electron-titlebar");
64
function $(selector) { return document.querySelector(selector); }
75

86
module.exports = () => {
9-
const bar = new customTitlebar.Titlebar({
10-
backgroundColor: customTitlebar.Color.fromHex("#050505"),
11-
itemBackgroundColor: customTitlebar.Color.fromHex("#121212"),
7+
let visible = !config.get("options.hideMenu");
8+
const bar = new Titlebar({
9+
backgroundColor: Color.fromHex("#050505"),
10+
itemBackgroundColor: Color.fromHex("#1d1d1d"),
11+
svgColor: Color.WHITE,
12+
menu: visible ? undefined : null
1213
});
1314
bar.updateTitle(" ");
1415
document.title = "Youtube Music";
1516

16-
ipcRenderer.on("updateMenu", function (_event, showMenu) {
17-
bar.updateMenu(showMenu ? Menu.getApplicationMenu() : null);
17+
ipcRenderer.on("refreshMenu", (_, showMenu) => {
18+
if (showMenu === undefined && !visible) return;
19+
if (showMenu === false) {
20+
bar.updateMenu(null);
21+
visible = false;
22+
} else {
23+
bar.refreshMenu();
24+
visible = true;
25+
}
1826
});
1927

2028
// Increases the right margin of Navbar background when the scrollbar is visible to avoid blocking it (z-index doesn't affect it)

providers/prompt-custom-titlebar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const customTitlebar = require("custom-electron-titlebar");
1+
const { Titlebar, Color } = require("custom-electron-titlebar");
22

33
module.exports = () => {
4-
new customTitlebar.Titlebar({
5-
backgroundColor: customTitlebar.Color.fromHex("#050505"),
4+
new Titlebar({
5+
backgroundColor: Color.fromHex("#050505"),
66
minimizable: false,
77
maximizable: false,
88
menu: null

providers/prompt-options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const promptOptions = is.macOS() ? {
1212
// The following are used for custom titlebar
1313
frame: false,
1414
customScript: customTitlebarPath,
15-
enableRemoteModule: true
1615
};
1716

1817
module.exports = () => promptOptions;

yarn.lock

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,6 @@
716716
global-agent "^3.0.0"
717717
global-tunnel-ng "^2.7.1"
718718

719-
"@electron/remote@^1.0.0":
720-
version "1.2.2"
721-
resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-1.2.2.tgz#4c390a2e669df47af973c09eec106162a296c323"
722-
integrity sha512-PfnXpQGWh4vpX866NNucJRnNOzDRZcsLcLaT32fUth9k0hccsohfxprqEDYLzRg+ZK2xRrtyUN5wYYoHimMCJg==
723-
724719
"@electron/remote@^2.0.4":
725720
version "2.0.4"
726721
resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-2.0.4.tgz#c3dae436aed79d1b8adcefc5a4963c06750ad5d8"
@@ -2730,12 +2725,10 @@ custom-electron-prompt@^1.4.1:
27302725
resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.4.1.tgz#79adc3d5cd9a372e5dfe43b21de70f0fe7d1c2f7"
27312726
integrity sha512-bR6JhEusBxKnooXfFFlIIUhDbF23eaDhaYwvqcw3ZTcdEzzJew63+ilwhIwD7flRAO+sCroaLwP495VBexHg/A==
27322727

2733-
custom-electron-titlebar@^3.2.10:
2734-
version "3.2.10"
2735-
resolved "https://registry.yarnpkg.com/custom-electron-titlebar/-/custom-electron-titlebar-3.2.10.tgz#8d3375e82997a97193669c249c4ebfe665a928bf"
2736-
integrity sha512-l2DRcuGzMGRHw5yDtcmmEve4DwVoWoJxWtsPrXeEePmWfrG3vA90eMtcbk1+qzHTrBPOpnNbVBJakdTNoxZIMQ==
2737-
dependencies:
2738-
"@electron/remote" "^1.0.0"
2728+
custom-electron-titlebar@^4.1.0:
2729+
version "4.1.0"
2730+
resolved "https://registry.yarnpkg.com/custom-electron-titlebar/-/custom-electron-titlebar-4.1.0.tgz#a34b4e557e661d604a5bb7807cd5127a68c46921"
2731+
integrity sha512-5iHiOAF+m97ZDBqhrn1KRtQr7j4ALEERNVqljryVx2tMcFv535wAZs4Tj7XSrbALJLHIixKvXQyypnvEf27NhA==
27392732

27402733
dashdash@^1.12.0:
27412734
version "1.14.1"

0 commit comments

Comments
 (0)