@@ -86,8 +86,16 @@ const store = new Store({ name: "electron-config" });
8686
8787let mainWindow = null ;
8888global . appQuitting = false ;
89- global . minimizeToTray = store . get ( 'minimizeToTray' , true ) ;
89+ global . showTrayIcon = store . get ( "showTrayIcon" , true ) ;
90+ global . minimizeToTray = global . showTrayIcon && store . get ( 'minimizeToTray' , true ) ;
9091
92+ // It's important to call `path.join` so we don't end up with the packaged asar in the final path.
93+ const iconFile = `riot.${ process . platform === 'win32' ? 'ico' : 'png' } ` ;
94+ const iconPath = path . join ( __dirname , ".." , "img" , iconFile ) ;
95+ const trayConfig = {
96+ icon_path : iconPath ,
97+ brand : vectorConfig . brand || 'Riot' ,
98+ } ;
9199
92100// handle uncaught errors otherwise it displays
93101// stack traces in popup dialogs, which is terrible (which
@@ -166,6 +174,20 @@ ipcMain.on('ipcCall', async function(ev, payload) {
166174 launcher . disable ( ) ;
167175 }
168176 break ;
177+ case 'getTrayIconEnabled' :
178+ ret = global . showTrayIcon ;
179+ break ;
180+ case 'setTrayIconEnabled' :
181+ if ( args [ 0 ] ) {
182+ // Create trayIcon icon
183+ tray . create ( trayConfig ) ;
184+ } else {
185+ tray . destroy ( ) ;
186+ }
187+ store . set ( 'minimizeToTray' , global . showTrayIcon = args [ 0 ] ) ;
188+ // re-evaluate whether we should be minimizing to tray
189+ global . minimizeToTray = global . showTrayIcon && store . get ( 'minimizeToTray' , true ) ;
190+ break ;
169191 case 'getMinimizeToTrayEnabled' :
170192 ret = global . minimizeToTray ;
171193 break ;
@@ -329,11 +351,6 @@ app.on('ready', () => {
329351 console . log ( 'No update_base_url is defined: auto update is disabled' ) ;
330352 }
331353
332- // It's important to call `path.join` so we don't end up with the packaged
333- // asar in the final path.
334- const iconFile = `riot.${ process . platform === 'win32' ? 'ico' : 'png' } ` ;
335- const iconPath = path . join ( __dirname , ".." , ".." , "img" , iconFile ) ;
336-
337354 // Load the previous window state with fallback to defaults
338355 const mainWindowState = windowStateKeeper ( {
339356 defaultWidth : 1024 ,
@@ -371,10 +388,7 @@ app.on('ready', () => {
371388 mainWindow . hide ( ) ;
372389
373390 // Create trayIcon icon
374- tray . create ( {
375- icon_path : iconPath ,
376- brand : vectorConfig . brand || 'Riot' ,
377- } ) ;
391+ if ( global . showTrayIcon ) tray . create ( trayConfig ) ;
378392
379393 mainWindow . once ( 'ready-to-show' , ( ) => {
380394 mainWindowState . manage ( mainWindow ) ;
0 commit comments