mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
add menu icon to in-app-menu
This commit is contained in:
2
menu.js
2
menu.js
@ -163,7 +163,7 @@ const mainMenuTemplate = (win) => {
|
|||||||
if (item.checked && !config.get("options.hideMenuWarned")) {
|
if (item.checked && !config.get("options.hideMenuWarned")) {
|
||||||
dialog.showMessageBox(win, {
|
dialog.showMessageBox(win, {
|
||||||
type: 'info', title: 'Hide Menu Enabled',
|
type: 'info', title: 'Hide Menu Enabled',
|
||||||
message: "Menu will be hidden on next launch, use 'Alt' to show it (or 'Escape' if using in-app-menu)"
|
message: "Menu will be hidden on next launch, use [Alt] to show it (or backtick [`] if using in-app-menu)"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,14 +2,12 @@ const path = require("path");
|
|||||||
|
|
||||||
const electronLocalshortcut = require("electron-localshortcut");
|
const electronLocalshortcut = require("electron-localshortcut");
|
||||||
|
|
||||||
const config = require("../../config");
|
|
||||||
const { injectCSS } = require("../utils");
|
const { injectCSS } = require("../utils");
|
||||||
|
|
||||||
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main');
|
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main');
|
||||||
setupTitlebar();
|
setupTitlebar();
|
||||||
|
|
||||||
//tracks menu visibility
|
//tracks menu visibility
|
||||||
let visible = !config.get("options.hideMenu");
|
|
||||||
|
|
||||||
module.exports = (win) => {
|
module.exports = (win) => {
|
||||||
// css for custom scrollbar + disable drag area(was causing bugs)
|
// css for custom scrollbar + disable drag area(was causing bugs)
|
||||||
@ -18,16 +16,8 @@ module.exports = (win) => {
|
|||||||
win.once("ready-to-show", () => {
|
win.once("ready-to-show", () => {
|
||||||
attachTitlebarToWindow(win);
|
attachTitlebarToWindow(win);
|
||||||
|
|
||||||
//register keyboard shortcut && hide menu if hideMenu is enabled
|
electronLocalshortcut.register(win, "`", () => {
|
||||||
if (config.get("options.hideMenu")) {
|
win.webContents.send("refreshMenu", true);
|
||||||
electronLocalshortcut.register(win, "Esc", () => {
|
|
||||||
setMenuVisibility(!visible);
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function setMenuVisibility(value) {
|
|
||||||
visible = value;
|
|
||||||
win.webContents.send("refreshMenu", visible);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,7 @@ function $(selector) { return document.querySelector(selector); }
|
|||||||
module.exports = (options) => {
|
module.exports = (options) => {
|
||||||
let visible = !config.get("options.hideMenu");
|
let visible = !config.get("options.hideMenu");
|
||||||
const bar = new Titlebar({
|
const bar = new Titlebar({
|
||||||
|
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,
|
||||||
@ -15,19 +16,28 @@ module.exports = (options) => {
|
|||||||
bar.updateTitle(" ");
|
bar.updateTitle(" ");
|
||||||
document.title = "Youtube Music";
|
document.title = "Youtube Music";
|
||||||
|
|
||||||
const hideIcon = hide => $('.cet-window-icon').style.display = hide ? 'none' : 'flex';
|
const icon = $('.cet-window-icon');
|
||||||
|
|
||||||
if (options.hideIcon) hideIcon(true);
|
icon.style.webkitAppRegion = 'no-drag';
|
||||||
|
|
||||||
ipcRenderer.on("refreshMenu", (_, showMenu) => {
|
icon.firstChild.style.webkitUserDrag = 'none';
|
||||||
if (showMenu === undefined && !visible) return;
|
icon.firstChild.style.filter = 'invert(50%)';
|
||||||
if (showMenu === false) {
|
|
||||||
|
const updateMenu = () => {
|
||||||
|
if (visible) {
|
||||||
bar.updateMenu(null);
|
bar.updateMenu(null);
|
||||||
visible = false;
|
visible = false;
|
||||||
} else {
|
} else {
|
||||||
bar.refreshMenu();
|
bar.refreshMenu();
|
||||||
visible = true;
|
visible = true;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
icon.addEventListener('click', updateMenu);
|
||||||
|
|
||||||
|
ipcRenderer.on("refreshMenu", (_, fromBack) => {
|
||||||
|
if (fromBack === undefined && !visible) return;
|
||||||
|
updateMenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isEnabled("picture-in-picture")) {
|
if (isEnabled("picture-in-picture")) {
|
||||||
@ -36,8 +46,6 @@ module.exports = (options) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcRenderer.on("hideIcon", (_, hide) => hideIcon(hide));
|
|
||||||
|
|
||||||
// Increases the right margin of Navbar background when the scrollbar is visible to avoid blocking it (z-index doesn't affect it)
|
// Increases the right margin of Navbar background when the scrollbar is visible to avoid blocking it (z-index doesn't affect it)
|
||||||
document.addEventListener('apiLoaded', () => {
|
document.addEventListener('apiLoaded', () => {
|
||||||
setNavbarMargin();
|
setNavbarMargin();
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
const { setOptions } = require("../../config/plugins");
|
|
||||||
|
|
||||||
module.exports = (win, options) => [
|
|
||||||
{
|
|
||||||
label: "Hide Icon",
|
|
||||||
type: "checkbox",
|
|
||||||
checked: options.hideIcon,
|
|
||||||
click: (item) => {
|
|
||||||
win.webContents.send("hideIcon", item.checked);
|
|
||||||
options.hideIcon = item.checked;
|
|
||||||
setOptions("in-app-menu", options);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
];
|
|
||||||
Reference in New Issue
Block a user