@@ -216,8 +216,8 @@ export const createWindow = async () => {
216
216
app . on ( 'window-all-closed' , ( ) => {
217
217
// Respect the OSX convention of having the application in memory even
218
218
// after all windows have been closed
219
- app . quit ( ) ; // todo: remove
220
219
if ( process . platform !== 'darwin' ) {
220
+ onExit ( ) ;
221
221
app . quit ( ) ;
222
222
}
223
223
} ) ;
@@ -226,29 +226,37 @@ app.on('window-all-closed', () => {
226
226
let isFullQuit = false ;
227
227
export const fullQuit = ( ) => {
228
228
isFullQuit = true ;
229
+ onExit ( ) ;
229
230
app . quit ( ) ;
230
231
} ;
231
232
232
233
export const setFullQuitForNextQuit = ( _isNextQuitAFullQuit : boolean ) => {
233
234
isFullQuit = _isNextQuitAFullQuit ;
234
235
} ;
235
236
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 ) => {
238
242
// Remove dev env check to test background. This is to prevent
239
243
// multiple instances of the app staying open in dev env where we
240
244
// regularly quit the app.
241
- app . quit ( ) ; // todo: remove
245
+ logger . info ( ` app.on('will-quit'): isFullQuit: ${ isFullQuit } ` ) ;
242
246
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
245
251
} else {
246
- console . log ( 'quitting app from foreground' ) ;
252
+ logger . info ( 'quitting app from foreground' ) ;
247
253
// This allows NN to run in the background. The purpose is to keep a tray icon updated,
248
254
// monitor node's statuses and alert the user when a node is down, and to continuously
249
255
// track node usage.
250
- e . preventDefault ( ) ;
256
+ e . preventDefault ( ) ; // halts electron's full quitting action
257
+ // todo: close windows?
251
258
if ( process . platform === 'darwin' && app . dock ) {
259
+ mainWindow ?. close ( ) ; // close the main window
252
260
app . dock . hide ( ) ; // app appears "quitted" in the dock
253
261
}
254
262
}
@@ -269,7 +277,6 @@ const onExit = () => {
269
277
onExitNodeManager ( ) ;
270
278
monitor . onExit ( ) ;
271
279
cronJobs . onExit ( ) ;
272
- app . quit ( ) ; // todo: remove
273
280
} ;
274
281
275
282
// no blocking work
0 commit comments