Skip to content

Commit d45ca96

Browse files
committed
feat(in-app-menu): add toggle-menu
1 parent 0bcfdbf commit d45ca96

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

assets/menu.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/youtube-music.svg

Lines changed: 6 additions & 13 deletions
Loading

plugins/in-app-menu/front.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { ipcRenderer, Menu } from 'electron';
22

33
import { createPanel } from './menu/panel';
44

5-
import logo from '../../assets/youtube-music.svg';
5+
import logo from '../../assets/menu.svg';
66
import { isEnabled } from '../../config/plugins';
7+
import config from '../../config';
78

89
function $<E extends Element = Element>(selector: string) {
910
return document.querySelector<E>(selector);
@@ -12,11 +13,28 @@ function $<E extends Element = Element>(selector: string) {
1213
const isMacOS = navigator.userAgent.includes('Macintosh');
1314

1415
export default () => {
16+
let hideMenu = config.get('options.hideMenu');
1517
const titleBar = document.createElement('title-bar');
1618
const navBar = document.querySelector<HTMLDivElement>('#nav-bar-background');
1719
if (isMacOS) titleBar.style.setProperty('--offset-left', '70px');
1820

1921
logo.classList.add('title-bar-icon');
22+
const logoClick = () => {
23+
hideMenu = !hideMenu;
24+
let visibilityStyle: string;
25+
if (hideMenu) {
26+
visibilityStyle = 'hidden';
27+
} else {
28+
visibilityStyle = 'visible';
29+
}
30+
const menus = document.querySelectorAll<HTMLElement>('menu-button');
31+
menus.forEach((menu) => {
32+
menu.style.visibility = visibilityStyle;
33+
});
34+
};
35+
logo.onclick = logoClick;
36+
37+
ipcRenderer.on('toggleMenu', logoClick);
2038

2139
if (!isMacOS) titleBar.appendChild(logo);
2240
document.body.appendChild(titleBar);
@@ -47,6 +65,9 @@ export default () => {
4765

4866
menu.append(menuItem.label);
4967
titleBar.appendChild(menu);
68+
if (hideMenu) {
69+
menu.style.visibility = 'hidden';
70+
}
5071
});
5172
};
5273
updateMenu();

plugins/in-app-menu/menu/panel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export const createPanel = (
2929
} else {
3030
const nativeImageIcon = typeof item.icon === 'string' ? nativeImage.createFromPath(item.icon) : item.icon;
3131
const iconURL = nativeImageIcon?.toDataURL();
32-
32+
3333
if (iconURL) iconWrapper.style.background = `url(${iconURL})`;
3434
}
3535
};
3636

3737
const radioGroups: [MenuItem, HTMLElement][] = [];
3838
items.map((item) => {
3939
if (item.type === 'separator') return panel.appendChild(document.createElement('menu-separator'));
40-
40+
4141
const menu = document.createElement('menu-item');
4242
const iconWrapper = document.createElement('menu-icon');
4343

@@ -48,7 +48,7 @@ export const createPanel = (
4848
menu.addEventListener('click', async () => {
4949
await ipcRenderer.invoke('menu-event', item.commandId);
5050
const menuItem = await ipcRenderer.invoke('get-menu-by-id', item.commandId) as MenuItem | null;
51-
51+
5252
if (menuItem) {
5353
updateIconState(iconWrapper, menuItem);
5454

@@ -64,7 +64,7 @@ export const createPanel = (
6464
}
6565
}
6666
});
67-
67+
6868
if (item.type === 'radio') {
6969
radioGroups.push([item, iconWrapper]);
7070
}

0 commit comments

Comments
 (0)