@@ -5,18 +5,8 @@ const electron = require("electron");
5
5
const is = require ( "electron-is" ) ;
6
6
const { autoUpdater } = require ( "electron-updater" ) ;
7
7
8
+ const config = require ( "./config" ) ;
8
9
const { setApplicationMenu } = require ( "./menu" ) ;
9
- const {
10
- autoUpdate,
11
- disableHardwareAcceleration,
12
- getEnabledPlugins,
13
- hideMenu,
14
- isAppVisible,
15
- isTrayEnabled,
16
- setOptions,
17
- store,
18
- startAtLogin,
19
- } = require ( "./store" ) ;
20
10
const { fileExists, injectCSS } = require ( "./plugins/utils" ) ;
21
11
const { isTesting } = require ( "./utils/testing" ) ;
22
12
const { setUpTray } = require ( "./tray" ) ;
@@ -28,7 +18,7 @@ app.commandLine.appendSwitch(
28
18
"--experimental-wasm-threads --experimental-wasm-bulk-memory"
29
19
) ;
30
20
app . allowRendererProcessReuse = true ; // https://github.com/electron/electron/issues/18397
31
- if ( disableHardwareAcceleration ( ) ) {
21
+ if ( config . get ( "options.disableHardwareAcceleration" ) ) {
32
22
if ( is . dev ( ) ) {
33
23
console . log ( "Disabling hardware acceleration" ) ;
34
24
}
@@ -64,19 +54,19 @@ function loadPlugins(win) {
64
54
}
65
55
} ) ;
66
56
67
- getEnabledPlugins ( ) . forEach ( ( plugin ) => {
57
+ config . plugins . getEnabled ( ) . forEach ( ( [ plugin , options ] ) => {
68
58
console . log ( "Loaded plugin - " + plugin ) ;
69
59
const pluginPath = path . join ( __dirname , "plugins" , plugin , "back.js" ) ;
70
60
fileExists ( pluginPath , ( ) => {
71
61
const handle = require ( pluginPath ) ;
72
- handle ( win ) ;
62
+ handle ( win , options ) ;
73
63
} ) ;
74
64
} ) ;
75
65
}
76
66
77
67
function createMainWindow ( ) {
78
- const windowSize = store . get ( "window-size" ) ;
79
- const windowMaximized = store . get ( "window-maximized" ) ;
68
+ const windowSize = config . get ( "window-size" ) ;
69
+ const windowMaximized = config . get ( "window-maximized" ) ;
80
70
81
71
const win = new electron . BrowserWindow ( {
82
72
icon : icon ,
@@ -94,31 +84,34 @@ function createMainWindow() {
94
84
} ,
95
85
frame : ! is . macOS ( ) ,
96
86
titleBarStyle : is . macOS ( ) ? "hiddenInset" : "default" ,
97
- autoHideMenuBar : hideMenu ( ) ,
87
+ autoHideMenuBar : config . get ( "options.hideMenu" ) ,
98
88
} ) ;
99
89
if ( windowMaximized ) {
100
90
win . maximize ( ) ;
101
91
}
102
92
103
- win . webContents . loadURL ( store . get ( "url" ) ) ;
93
+ win . webContents . loadURL ( config . get ( "url" ) ) ;
104
94
win . on ( "closed" , onClosed ) ;
105
95
106
96
win . on ( "move" , ( ) => {
107
97
let position = win . getPosition ( ) ;
108
- store . set ( "window-position" , { x : position [ 0 ] , y : position [ 1 ] } ) ;
98
+ config . set ( "window-position" , { x : position [ 0 ] , y : position [ 1 ] } ) ;
109
99
} ) ;
110
100
111
101
win . on ( "resize" , ( ) => {
112
102
const windowSize = win . getSize ( ) ;
113
103
114
- store . set ( "window-maximized" , win . isMaximized ( ) ) ;
104
+ config . set ( "window-maximized" , win . isMaximized ( ) ) ;
115
105
if ( ! win . isMaximized ( ) ) {
116
- store . set ( "window-size" , { width : windowSize [ 0 ] , height : windowSize [ 1 ] } ) ;
106
+ config . set ( "window-size" , {
107
+ width : windowSize [ 0 ] ,
108
+ height : windowSize [ 1 ] ,
109
+ } ) ;
117
110
}
118
111
} ) ;
119
112
120
113
win . once ( "ready-to-show" , ( ) => {
121
- if ( isAppVisible ( ) ) {
114
+ if ( config . get ( "options.appVisible" ) ) {
122
115
win . show ( ) ;
123
116
}
124
117
} ) ;
@@ -143,7 +136,7 @@ app.on("browser-window-created", (event, win) => {
143
136
win . webContents . on ( "did-navigate-in-page" , ( ) => {
144
137
const url = win . webContents . getURL ( ) ;
145
138
if ( url . startsWith ( "https://music.youtube.com" ) ) {
146
- store . set ( "url" , url ) ;
139
+ config . set ( "url" , url ) ;
147
140
}
148
141
} ) ;
149
142
@@ -196,14 +189,17 @@ app.on("activate", () => {
196
189
app . on ( "ready" , ( ) => {
197
190
mainWindow = createMainWindow ( ) ;
198
191
setApplicationMenu ( mainWindow ) ;
192
+ config . watch ( ( ) => {
193
+ setApplicationMenu ( mainWindow ) ;
194
+ } ) ;
199
195
setUpTray ( app , mainWindow ) ;
200
196
201
197
// Autostart at login
202
198
app . setLoginItemSettings ( {
203
- openAtLogin : startAtLogin ( ) ,
199
+ openAtLogin : config . get ( "options.startAtLogin" ) ,
204
200
} ) ;
205
201
206
- if ( ! is . dev ( ) && autoUpdate ( ) ) {
202
+ if ( ! is . dev ( ) && config . get ( "options.autoUpdates" ) ) {
207
203
autoUpdater . checkForUpdatesAndNotify ( ) ;
208
204
autoUpdater . on ( "update-available" , ( ) => {
209
205
const downloadLink =
@@ -223,7 +219,7 @@ app.on("ready", () => {
223
219
break ;
224
220
// Disable updates
225
221
case 2 :
226
- setOptions ( { autoUpdates : false } ) ;
222
+ config . set ( "options. autoUpdates" , false ) ;
227
223
break ;
228
224
default :
229
225
break ;
@@ -234,7 +230,7 @@ app.on("ready", () => {
234
230
235
231
// Optimized for Mac OS X
236
232
if ( is . macOS ( ) ) {
237
- if ( ! isAppVisible ( ) ) {
233
+ if ( ! config . get ( "options.appVisible" ) ) {
238
234
app . dock . hide ( ) ;
239
235
}
240
236
}
@@ -244,7 +240,7 @@ app.on("ready", () => {
244
240
forceQuit = true ;
245
241
} ) ;
246
242
247
- if ( is . macOS ( ) || isTrayEnabled ( ) ) {
243
+ if ( is . macOS ( ) || config . get ( "options.tray" ) ) {
248
244
mainWindow . on ( "close" , ( event ) => {
249
245
// Hide the window instead of quitting (quit is available in tray options)
250
246
if ( ! forceQuit ) {
0 commit comments