lifecycle - emit onWillKill when app.exit

This commit is contained in:
Benjamin Pasero
2021-11-09 07:59:07 +01:00
parent 0413d4a596
commit 1b0a9c19a2
2 changed files with 16 additions and 1 deletions
@@ -91,6 +91,13 @@ export interface ILifecycleMainService {
*/
readonly onBeforeCloseWindow: Event<ICodeWindow>;
/**
* An event that fires in the rare cases where `app.exit` is triggered
* and thus we Forcefully shutdown the application. No other lifecycle
* event handlers are triggered.
*/
readonly onWillKill: Event<void>;
/**
* Make a `ICodeWindow` known to the lifecycle main service.
*/
@@ -117,7 +124,8 @@ export interface ILifecycleMainService {
quit(willRestart?: boolean): Promise<boolean /* veto */>;
/**
* Forcefully shutdown the application. No livecycle event handlers are triggered.
* Forcefully shutdown the application. The only lifecycle event handler
* that is triggered is `onWillKill`.
*/
kill(code?: number): Promise<void>;
@@ -169,6 +177,9 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
private readonly _onBeforeUnloadWindow = this._register(new Emitter<IWindowUnloadEvent>());
readonly onBeforeUnloadWindow = this._onBeforeUnloadWindow.event;
private readonly _onWillKill = this._register(new Emitter<void>());
readonly onWillKill = this._onWillKill.event;
private _quitRequested = false;
get quitRequested(): boolean { return this._quitRequested; }
@@ -589,6 +600,9 @@ export class LifecycleMainService extends Disposable implements ILifecycleMainSe
async kill(code?: number): Promise<void> {
this.logService.trace('Lifecycle#kill()');
// Event
this._onWillKill.fire();
// The kill() method is only used in 2 situations:
// - when an instance fails to start at all
// - when extension tests run from CLI to report proper exit code
@@ -57,6 +57,7 @@ suite('StorageMainService', function () {
onWillLoadWindow = Event.None;
onBeforeCloseWindow = Event.None;
onBeforeUnloadWindow = Event.None;
onWillKill = Event.None;
wasRestarted = false;
quitRequested = false;