@@ -5,18 +5,8 @@ const electron = require("electron");
55const is = require ( "electron-is" ) ;
66const { autoUpdater } = require ( "electron-updater" ) ;
77
8+ const config = require ( "./config" ) ;
89const { 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" ) ;
2010const { fileExists, injectCSS } = require ( "./plugins/utils" ) ;
2111const { isTesting } = require ( "./utils/testing" ) ;
2212const { setUpTray } = require ( "./tray" ) ;
@@ -28,7 +18,7 @@ app.commandLine.appendSwitch(
2818 "--experimental-wasm-threads --experimental-wasm-bulk-memory"
2919) ;
3020app . allowRendererProcessReuse = true ; // https://github.com/electron/electron/issues/18397
31- if ( disableHardwareAcceleration ( ) ) {
21+ if ( config . get ( "options.disableHardwareAcceleration" ) ) {
3222 if ( is . dev ( ) ) {
3323 console . log ( "Disabling hardware acceleration" ) ;
3424 }
@@ -64,19 +54,19 @@ function loadPlugins(win) {
6454 }
6555 } ) ;
6656
67- getEnabledPlugins ( ) . forEach ( ( plugin ) => {
57+ config . plugins . getEnabled ( ) . forEach ( ( [ plugin , options ] ) => {
6858 console . log ( "Loaded plugin - " + plugin ) ;
6959 const pluginPath = path . join ( __dirname , "plugins" , plugin , "back.js" ) ;
7060 fileExists ( pluginPath , ( ) => {
7161 const handle = require ( pluginPath ) ;
72- handle ( win ) ;
62+ handle ( win , options ) ;
7363 } ) ;
7464 } ) ;
7565}
7666
7767function 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" ) ;
8070
8171 const win = new electron . BrowserWindow ( {
8272 icon : icon ,
@@ -94,31 +84,34 @@ function createMainWindow() {
9484 } ,
9585 frame : ! is . macOS ( ) ,
9686 titleBarStyle : is . macOS ( ) ? "hiddenInset" : "default" ,
97- autoHideMenuBar : hideMenu ( ) ,
87+ autoHideMenuBar : config . get ( "options.hideMenu" ) ,
9888 } ) ;
9989 if ( windowMaximized ) {
10090 win . maximize ( ) ;
10191 }
10292
103- win . webContents . loadURL ( store . get ( "url" ) ) ;
93+ win . webContents . loadURL ( config . get ( "url" ) ) ;
10494 win . on ( "closed" , onClosed ) ;
10595
10696 win . on ( "move" , ( ) => {
10797 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 ] } ) ;
10999 } ) ;
110100
111101 win . on ( "resize" , ( ) => {
112102 const windowSize = win . getSize ( ) ;
113103
114- store . set ( "window-maximized" , win . isMaximized ( ) ) ;
104+ config . set ( "window-maximized" , win . isMaximized ( ) ) ;
115105 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+ } ) ;
117110 }
118111 } ) ;
119112
120113 win . once ( "ready-to-show" , ( ) => {
121- if ( isAppVisible ( ) ) {
114+ if ( config . get ( "options.appVisible" ) ) {
122115 win . show ( ) ;
123116 }
124117 } ) ;
@@ -143,7 +136,7 @@ app.on("browser-window-created", (event, win) => {
143136 win . webContents . on ( "did-navigate-in-page" , ( ) => {
144137 const url = win . webContents . getURL ( ) ;
145138 if ( url . startsWith ( "https://music.youtube.com" ) ) {
146- store . set ( "url" , url ) ;
139+ config . set ( "url" , url ) ;
147140 }
148141 } ) ;
149142
@@ -196,14 +189,17 @@ app.on("activate", () => {
196189app . on ( "ready" , ( ) => {
197190 mainWindow = createMainWindow ( ) ;
198191 setApplicationMenu ( mainWindow ) ;
192+ config . watch ( ( ) => {
193+ setApplicationMenu ( mainWindow ) ;
194+ } ) ;
199195 setUpTray ( app , mainWindow ) ;
200196
201197 // Autostart at login
202198 app . setLoginItemSettings ( {
203- openAtLogin : startAtLogin ( ) ,
199+ openAtLogin : config . get ( "options.startAtLogin" ) ,
204200 } ) ;
205201
206- if ( ! is . dev ( ) && autoUpdate ( ) ) {
202+ if ( ! is . dev ( ) && config . get ( "options.autoUpdates" ) ) {
207203 autoUpdater . checkForUpdatesAndNotify ( ) ;
208204 autoUpdater . on ( "update-available" , ( ) => {
209205 const downloadLink =
@@ -223,7 +219,7 @@ app.on("ready", () => {
223219 break ;
224220 // Disable updates
225221 case 2 :
226- setOptions ( { autoUpdates : false } ) ;
222+ config . set ( "options. autoUpdates" , false ) ;
227223 break ;
228224 default :
229225 break ;
@@ -234,7 +230,7 @@ app.on("ready", () => {
234230
235231 // Optimized for Mac OS X
236232 if ( is . macOS ( ) ) {
237- if ( ! isAppVisible ( ) ) {
233+ if ( ! config . get ( "options.appVisible" ) ) {
238234 app . dock . hide ( ) ;
239235 }
240236 }
@@ -244,7 +240,7 @@ app.on("ready", () => {
244240 forceQuit = true ;
245241 } ) ;
246242
247- if ( is . macOS ( ) || isTrayEnabled ( ) ) {
243+ if ( is . macOS ( ) || config . get ( "options.tray" ) ) {
248244 mainWindow . on ( "close" , ( event ) => {
249245 // Hide the window instead of quitting (quit is available in tray options)
250246 if ( ! forceQuit ) {
0 commit comments