@@ -216,8 +216,8 @@ export const createWindow = async () => {
216216app . on ( 'window-all-closed' , ( ) => {
217217 // Respect the OSX convention of having the application in memory even
218218 // after all windows have been closed
219- app . quit ( ) ; // todo: remove
220219 if ( process . platform !== 'darwin' ) {
220+ onExit ( ) ;
221221 app . quit ( ) ;
222222 }
223223} ) ;
@@ -226,29 +226,37 @@ app.on('window-all-closed', () => {
226226let isFullQuit = false ;
227227export const fullQuit = ( ) => {
228228 isFullQuit = true ;
229+ onExit ( ) ;
229230 app . quit ( ) ;
230231} ;
231232
232233export const setFullQuitForNextQuit = ( _isNextQuitAFullQuit : boolean ) => {
233234 isFullQuit = _isNextQuitAFullQuit ;
234235} ;
235236
236- // Emitted on app.quit() after all windows have been closed
237- app . on ( 'will-quit' , ( e ) => {
237+ // app.on('will-quit') is emitted on app.quit() after all windows have been closed
238+ // However, we don't want it to close the tray window! So we catch the quit action and stop
239+ // it before it closes the tray window, and we only close the main window.
240+
241+ app . on ( 'before-quit' , ( e ) => {
238242 // Remove dev env check to test background. This is to prevent
239243 // multiple instances of the app staying open in dev env where we
240244 // regularly quit the app.
241- app . quit ( ) ; // todo: remove
245+ logger . info ( ` app.on('will-quit'): isFullQuit: ${ isFullQuit } ` ) ;
242246 if ( isFullQuit || process . env . NODE_ENV === 'development' ) {
243- console . log ( 'quitting app from background' ) ;
244- app . quit ( ) ;
247+ // if (isFullQuit) {
248+ logger . info ( 'quitting app from background' ) ;
249+ onExit ( ) ;
250+ // continue with quitting
245251 } else {
246- console . log ( 'quitting app from foreground' ) ;
252+ logger . info ( 'quitting app from foreground' ) ;
247253 // This allows NN to run in the background. The purpose is to keep a tray icon updated,
248254 // monitor node's statuses and alert the user when a node is down, and to continuously
249255 // track node usage.
250- e . preventDefault ( ) ;
256+ e . preventDefault ( ) ; // halts electron's full quitting action
257+ // todo: close windows?
251258 if ( process . platform === 'darwin' && app . dock ) {
259+ mainWindow ?. close ( ) ; // close the main window
252260 app . dock . hide ( ) ; // app appears "quitted" in the dock
253261 }
254262 }
@@ -269,7 +277,6 @@ const onExit = () => {
269277 onExitNodeManager ( ) ;
270278 monitor . onExit ( ) ;
271279 cronJobs . onExit ( ) ;
272- app . quit ( ) ; // todo: remove
273280} ;
274281
275282// no blocking work
0 commit comments