@@ -17,6 +17,7 @@ import { ILogService } from 'vs/platform/log/common/log';
17
17
import { IStateMainService } from 'vs/platform/state/electron-main/state' ;
18
18
import { ICodeWindow , LoadReason , UnloadReason } from 'vs/platform/window/electron-main/window' ;
19
19
import { ISingleFolderWorkspaceIdentifier , IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace' ;
20
+ import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService' ;
20
21
21
22
export const ILifecycleMainService = createDecorator < ILifecycleMainService > ( 'lifecycleMainService' ) ;
22
23
@@ -219,7 +220,8 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
219
220
220
221
constructor (
221
222
@ILogService private readonly logService : ILogService ,
222
- @IStateMainService private readonly stateMainService : IStateMainService
223
+ @IStateMainService private readonly stateMainService : IStateMainService ,
224
+ @IEnvironmentMainService private readonly environmentMainService : IEnvironmentMainService
223
225
) {
224
226
super ( ) ;
225
227
@@ -245,11 +247,11 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
245
247
return ;
246
248
}
247
249
248
- this . logService . trace ( 'Lifecycle#app.on(before-quit)' ) ;
250
+ this . trace ( 'Lifecycle#app.on(before-quit)' ) ;
249
251
this . _quitRequested = true ;
250
252
251
253
// Emit event to indicate that we are about to shutdown
252
- this . logService . trace ( 'Lifecycle#onBeforeShutdown.fire()' ) ;
254
+ this . trace ( 'Lifecycle#onBeforeShutdown.fire()' ) ;
253
255
this . _onBeforeShutdown . fire ( ) ;
254
256
255
257
// macOS: can run without any window open. in that case we fire
@@ -265,7 +267,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
265
267
// was closed. We override this event to be in charge if app.quit()
266
268
// should be called or not.
267
269
const windowAllClosedListener = ( ) => {
268
- this . logService . trace ( 'Lifecycle#app.on(window-all-closed)' ) ;
270
+ this . trace ( 'Lifecycle#app.on(window-all-closed)' ) ;
269
271
270
272
// Windows/Linux: we quit when all windows have closed
271
273
// Mac: we only quit when quit was requested
@@ -278,7 +280,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
278
280
// will-quit: an event that is fired after all windows have been
279
281
// closed, but before actually quitting.
280
282
app . once ( 'will-quit' , e => {
281
- this . logService . trace ( 'Lifecycle#app.on(will-quit)' ) ;
283
+ this . trace ( 'Lifecycle#app.on(will-quit)' ) ;
282
284
283
285
// Prevent the quit until the shutdown promise was resolved
284
286
e . preventDefault ( ) ;
@@ -307,7 +309,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
307
309
return this . pendingWillShutdownPromise ; // shutdown is already running
308
310
}
309
311
310
- this . logService . trace ( 'Lifecycle#onWillShutdown.fire()' ) ;
312
+ this . trace ( 'Lifecycle#onWillShutdown.fire()' ) ;
311
313
312
314
const joiners : Promise < void > [ ] = [ ] ;
313
315
@@ -348,7 +350,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
348
350
return ;
349
351
}
350
352
351
- this . logService . trace ( `lifecycle (main): phase changed (value: ${ value } )` ) ;
353
+ this . trace ( `lifecycle (main): phase changed (value: ${ value } )` ) ;
352
354
353
355
this . _phase = value ;
354
356
@@ -394,7 +396,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
394
396
return ;
395
397
}
396
398
397
- this . logService . trace ( `Lifecycle#window.on('close') - window ID ${ window . id } ` ) ;
399
+ this . trace ( `Lifecycle#window.on('close') - window ID ${ window . id } ` ) ;
398
400
399
401
// Otherwise prevent unload and handle it from window
400
402
e . preventDefault ( ) ;
@@ -407,7 +409,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
407
409
this . windowToCloseRequest . add ( windowId ) ;
408
410
409
411
// Fire onBeforeCloseWindow before actually closing
410
- this . logService . trace ( `Lifecycle#onBeforeCloseWindow.fire() - window ID ${ windowId } ` ) ;
412
+ this . trace ( `Lifecycle#onBeforeCloseWindow.fire() - window ID ${ windowId } ` ) ;
411
413
this . _onBeforeCloseWindow . fire ( window ) ;
412
414
413
415
// No veto, close window now
@@ -417,7 +419,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
417
419
418
420
// Window After Closing
419
421
win . on ( 'closed' , ( ) => {
420
- this . logService . trace ( `Lifecycle#window.on('closed') - window ID ${ window . id } ` ) ;
422
+ this . trace ( `Lifecycle#window.on('closed') - window ID ${ window . id } ` ) ;
421
423
422
424
// update window count
423
425
this . windowCounter -- ;
@@ -467,13 +469,13 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
467
469
return false ;
468
470
}
469
471
470
- this . logService . trace ( `Lifecycle#unload() - window ID ${ window . id } ` ) ;
472
+ this . trace ( `Lifecycle#unload() - window ID ${ window . id } ` ) ;
471
473
472
474
// first ask the window itself if it vetos the unload
473
475
const windowUnloadReason = this . _quitRequested ? UnloadReason . QUIT : reason ;
474
476
const veto = await this . onBeforeUnloadWindowInRenderer ( window , windowUnloadReason ) ;
475
477
if ( veto ) {
476
- this . logService . trace ( `Lifecycle#unload() - veto in renderer (window ID ${ window . id } )` ) ;
478
+ this . trace ( `Lifecycle#unload() - veto in renderer (window ID ${ window . id } )` ) ;
477
479
478
480
return this . handleWindowUnloadVeto ( veto ) ;
479
481
}
@@ -536,12 +538,14 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
536
538
}
537
539
538
540
quit ( willRestart ?: boolean ) : Promise < boolean /* veto */ > {
541
+ this . trace ( `Lifecycle#quit() - begin (willRestart: ${ willRestart } )` ) ;
542
+
539
543
if ( this . pendingQuitPromise ) {
544
+ this . trace ( 'Lifecycle#quit() - returning pending quit promise' ) ;
545
+
540
546
return this . pendingQuitPromise ;
541
547
}
542
548
543
- this . logService . trace ( `Lifecycle#quit() - will restart: ${ willRestart } ` ) ;
544
-
545
549
// Remember if we are about to restart
546
550
if ( willRestart ) {
547
551
this . stateMainService . setItem ( LifecycleMainService . QUIT_AND_RESTART_KEY , true ) ;
@@ -554,15 +558,23 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
554
558
555
559
// Calling app.quit() will trigger the close handlers of each opened window
556
560
// and only if no window vetoed the shutdown, we will get the will-quit event
557
- this . logService . trace ( 'Lifecycle#quit() - calling app.quit()' ) ;
561
+ this . trace ( 'Lifecycle#quit() - calling app.quit()' ) ;
558
562
app . quit ( ) ;
559
563
} ) ;
560
564
561
565
return this . pendingQuitPromise ;
562
566
}
563
567
568
+ private trace ( msg : string ) : void {
569
+ if ( this . environmentMainService . args [ 'enable-smoke-test-driver' ] ) {
570
+ this . logService . info ( msg ) ; // helps diagnose issues with exiting from smoke tests
571
+ } else {
572
+ this . logService . trace ( msg ) ;
573
+ }
574
+ }
575
+
564
576
async relaunch ( options ?: { addArgs ?: string [ ] ; removeArgs ?: string [ ] } ) : Promise < void > {
565
- this . logService . trace ( 'Lifecycle#relaunch()' ) ;
577
+ this . trace ( 'Lifecycle#relaunch()' ) ;
566
578
567
579
const args = process . argv . slice ( 1 ) ;
568
580
if ( options ?. addArgs ) {
@@ -595,7 +607,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
595
607
}
596
608
597
609
// relaunch after we are sure there is no veto
598
- this . logService . trace ( 'Lifecycle#relaunch() - calling app.relaunch()' ) ;
610
+ this . trace ( 'Lifecycle#relaunch() - calling app.relaunch()' ) ;
599
611
app . relaunch ( { args } ) ;
600
612
} ;
601
613
app . once ( 'quit' , quitListener ) ;
@@ -609,7 +621,7 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
609
621
}
610
622
611
623
async kill ( code ?: number ) : Promise < void > {
612
- this . logService . trace ( 'Lifecycle#kill()' ) ;
624
+ this . trace ( 'Lifecycle#kill()' ) ;
613
625
614
626
// Give main process participants a chance to orderly shutdown
615
627
await this . fireOnWillShutdown ( ShutdownReason . KILL ) ;
0 commit comments