towards better quit handling (for #22138)

This commit is contained in:
Benjamin Pasero
2017-04-05 10:56:55 +02:00
parent c78e43ef02
commit 3cdca85a7d
3 changed files with 27 additions and 10 deletions

View File

@@ -47,10 +47,15 @@ export interface ILifecycleService {
ready(): void;
registerWindow(vscodeWindow: VSCodeWindow): void;
unload(vscodeWindow: VSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */>;
relaunch(options?: { addArgs?: string[], removeArgs?: string[] });
quit(fromUpdate?: boolean): TPromise<boolean /* veto */>;
relaunch(options: { addArgs?: string[], removeArgs?: string[] });
isQuitRequested(): boolean;
kill(code?: number);
}
export class LifecycleService implements ILifecycleService {
@@ -210,6 +215,7 @@ export class LifecycleService implements ILifecycleService {
if (fromUpdate) {
this.storageService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true);
}
this.pendingQuitPromiseComplete(false /* no veto */);
this.pendingQuitPromiseComplete = null;
this.pendingQuitPromise = null;
@@ -223,6 +229,10 @@ export class LifecycleService implements ILifecycleService {
return this.pendingQuitPromise;
}
public kill(code?: number): void {
app.exit(code);
}
public relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void {
const args = process.argv.slice(1);
if (options && options.addArgs) {
@@ -238,10 +248,17 @@ export class LifecycleService implements ILifecycleService {
}
}
this.storageService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true);
let vetod = false;
app.once('quit', () => {
if (!vetod) {
this.storageService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true);
app.relaunch({ args });
}
});
app.quit();
app.once('quit', () => app.relaunch({ args }));
this.quit().then(veto => {
vetod = veto;
});
}
public isQuitRequested(): boolean {