@@ -2,7 +2,12 @@ import { ipcRenderer, Menu } from 'electron';
2
2
3
3
import { createPanel } from './menu/panel' ;
4
4
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
+
6
11
import { isEnabled } from '../../config/plugins' ;
7
12
import config from '../../config' ;
8
13
@@ -11,8 +16,9 @@ function $<E extends Element = Element>(selector: string) {
11
16
}
12
17
13
18
const isMacOS = navigator . userAgent . includes ( 'Macintosh' ) ;
19
+ const isNotWindowsOrMacOS = ! navigator . userAgent . includes ( 'Windows' ) && ! isMacOS ;
14
20
15
- export default ( ) => {
21
+ export default async ( ) => {
16
22
let hideMenu = config . get ( 'options.hideMenu' ) ;
17
23
const titleBar = document . createElement ( 'title-bar' ) ;
18
24
const navBar = document . querySelector < HTMLDivElement > ( '#nav-bar-background' ) ;
@@ -39,6 +45,60 @@ export default () => {
39
45
if ( ! isMacOS ) titleBar . appendChild ( logo ) ;
40
46
document . body . appendChild ( titleBar ) ;
41
47
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
+
42
102
if ( navBar ) {
43
103
const observer = new MutationObserver ( ( mutations ) => {
44
104
mutations . forEach ( ( ) => {
@@ -69,8 +129,9 @@ export default () => {
69
129
menu . style . visibility = 'hidden' ;
70
130
}
71
131
} ) ;
132
+ if ( isNotWindowsOrMacOS ) await addWindowControls ( ) ;
72
133
} ;
73
- updateMenu ( ) ;
134
+ await updateMenu ( ) ;
74
135
75
136
document . title = 'Youtube Music' ;
76
137
0 commit comments