Skip to content

Commit 73a049a

Browse files
authored
Merge pull request #1279 from th-ch/fix/1274
2 parents ef0c30e + f1050cb commit 73a049a

File tree

9 files changed

+115
-13
lines changed

9 files changed

+115
-13
lines changed

plugins/discord/back.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ const resetInfo = () => {
3939
console.log('discord disconnected');
4040
}
4141

42-
setTimeout(() => {
43-
for (const cb of refreshCallbacks) {
44-
cb();
45-
}
46-
}, 100);
47-
42+
for (const cb of refreshCallbacks) {
43+
cb();
44+
}
4845
};
4946

5047
const connectTimeout = () => new Promise((resolve, reject) => setTimeout(() => {

plugins/in-app-menu/assets/close.svg

+3
Loading
+3
Loading
File renamed without changes.
+3
Loading
Loading

plugins/in-app-menu/back.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'node:path';
2-
31
import { register } from 'electron-localshortcut';
42

53
import { BrowserWindow, Menu, MenuItem, ipcMain } from 'electron';
@@ -25,7 +23,7 @@ export default (win: BrowserWindow) => {
2523
(key: string, value: unknown) => (key !== 'commandsMap' && key !== 'menu') ? value : undefined),
2624
),
2725
);
28-
26+
2927
const getMenuItemById = (commandId: number): MenuItem | null => {
3028
const menu = Menu.getApplicationMenu();
3129

@@ -40,7 +38,7 @@ export default (win: BrowserWindow) => {
4038
break;
4139
}
4240
}
43-
41+
4442
return target;
4543
};
4644

@@ -57,4 +55,11 @@ export default (win: BrowserWindow) => {
5755
(key: string, value: unknown) => (key !== 'commandsMap' && key !== 'menu') ? value : undefined),
5856
);
5957
});
58+
59+
ipcMain.handle('window-is-maximized', () => win.isMaximized());
60+
61+
ipcMain.handle('window-close', () => win.close());
62+
ipcMain.handle('window-minimize', () => win.minimize());
63+
ipcMain.handle('window-maximize', () => win.maximize());
64+
ipcMain.handle('window-unmaximize', () => win.unmaximize());
6065
};

plugins/in-app-menu/front.ts

+64-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { ipcRenderer, Menu } from 'electron';
22

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

5-
import logo from '../../assets/menu.svg';
5+
import logo from './assets/menu.svg';
6+
import close from './assets/close.svg';
7+
import minimize from './assets/minimize.svg';
8+
import maximize from './assets/maximize.svg';
9+
import unmaximize from './assets/unmaximize.svg';
10+
611
import { isEnabled } from '../../config/plugins';
712
import config from '../../config';
813

@@ -11,8 +16,9 @@ function $<E extends Element = Element>(selector: string) {
1116
}
1217

1318
const isMacOS = navigator.userAgent.includes('Macintosh');
19+
const isNotWindowsOrMacOS = !navigator.userAgent.includes('Windows') && !isMacOS;
1420

15-
export default () => {
21+
export default async () => {
1622
let hideMenu = config.get('options.hideMenu');
1723
const titleBar = document.createElement('title-bar');
1824
const navBar = document.querySelector<HTMLDivElement>('#nav-bar-background');
@@ -39,6 +45,60 @@ export default () => {
3945
if (!isMacOS) titleBar.appendChild(logo);
4046
document.body.appendChild(titleBar);
4147

48+
titleBar.appendChild(logo);
49+
50+
const addWindowControls = async () => {
51+
52+
// Create window control buttons
53+
const minimizeButton = document.createElement('button');
54+
minimizeButton.classList.add('window-control');
55+
minimizeButton.appendChild(minimize);
56+
minimizeButton.onclick = () => ipcRenderer.invoke('window-minimize');
57+
58+
const maximizeButton = document.createElement('button');
59+
if (await ipcRenderer.invoke('window-is-maximized')) {
60+
maximizeButton.classList.add('window-control');
61+
maximizeButton.appendChild(unmaximize);
62+
} else {
63+
maximizeButton.classList.add('window-control');
64+
maximizeButton.appendChild(maximize);
65+
}
66+
maximizeButton.onclick = async () => {
67+
if (await ipcRenderer.invoke('window-is-maximized')) {
68+
// change icon to maximize
69+
maximizeButton.removeChild(maximizeButton.firstChild!);
70+
maximizeButton.appendChild(maximize);
71+
72+
// call unmaximize
73+
await ipcRenderer.invoke('window-unmaximize');
74+
} else {
75+
// change icon to unmaximize
76+
maximizeButton.removeChild(maximizeButton.firstChild!);
77+
maximizeButton.appendChild(unmaximize);
78+
79+
// call maximize
80+
await ipcRenderer.invoke('window-maximize');
81+
}
82+
};
83+
84+
const closeButton = document.createElement('button');
85+
closeButton.classList.add('window-control');
86+
closeButton.appendChild(close);
87+
closeButton.onclick = () => ipcRenderer.invoke('window-close');
88+
89+
// Create a container div for the window control buttons
90+
const windowControlsContainer = document.createElement('div');
91+
windowControlsContainer.classList.add('window-controls-container');
92+
windowControlsContainer.appendChild(minimizeButton);
93+
windowControlsContainer.appendChild(maximizeButton);
94+
windowControlsContainer.appendChild(closeButton);
95+
96+
// Add window control buttons to the title bar
97+
titleBar.appendChild(windowControlsContainer);
98+
};
99+
100+
if (isNotWindowsOrMacOS) await addWindowControls();
101+
42102
if (navBar) {
43103
const observer = new MutationObserver((mutations) => {
44104
mutations.forEach(() => {
@@ -69,8 +129,9 @@ export default () => {
69129
menu.style.visibility = 'hidden';
70130
}
71131
});
132+
if (isNotWindowsOrMacOS) await addWindowControls();
72133
};
73-
updateMenu();
134+
await updateMenu();
74135

75136
document.title = 'Youtube Music';
76137

plugins/in-app-menu/titlebar.css

+27
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,33 @@ menu-separator {
126126
margin-left: -4px;
127127
}
128128

129+
/* Window control container */
130+
131+
.window-controls-container {
132+
-webkit-app-region: no-drag;
133+
display: flex;
134+
justify-content: flex-end; /* Align to the right end of the title-bar */
135+
align-items: center;
136+
gap: 4px; /* Add spacing between the window control buttons */
137+
position: absolute; /* Position it absolutely within title-bar */
138+
right: 4px; /* Adjust the right position as needed */
139+
}
140+
141+
/* Window control buttons */
142+
143+
.window-control {
144+
width: 24px;
145+
height: 24px;
146+
background: none;
147+
border: none;
148+
cursor: pointer;
149+
display: flex;
150+
align-items: center;
151+
color: #f1f1f1;
152+
font-size: 14px;
153+
padding: 0;
154+
}
155+
129156
/* youtube-music style */
130157

131158
ytmusic-app-layout {

0 commit comments

Comments
 (0)