提交 3cdca85a 编写于 作者: B Benjamin Pasero

towards better quit handling (for #22138)

上级 c78e43ef
......@@ -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 {
......
......@@ -58,7 +58,6 @@ import product from 'vs/platform/node/product';
import pkg from 'vs/platform/node/package';
import * as fs from 'original-fs';
ipc.on('vscode:fetchShellEnv', (event, windowId) => {
const win = BrowserWindow.fromId(windowId);
getShellEnvironment().then(shellEnv => {
......@@ -71,6 +70,7 @@ ipc.on('vscode:fetchShellEnv', (event, windowId) => {
function quit(accessor: ServicesAccessor, errorOrMessage?: Error | string): void {
const logService = accessor.get(ILogService);
const lifecycleService = accessor.get(ILifecycleService);
let exitCode = 0;
if (typeof errorOrMessage === 'string') {
......@@ -84,7 +84,7 @@ function quit(accessor: ServicesAccessor, errorOrMessage?: Error | string): void
}
}
process.exit(exitCode); // in main, process.exit === app.exit
lifecycleService.kill(exitCode);
}
// TODO@Joao wow this is huge, clean up!
......@@ -247,7 +247,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
logService.log('IPC#vscode:exit', code);
dispose();
process.exit(code); // in main, process.exit === app.exit
lifecycleService.kill(code);
});
// Lifecycle
......@@ -397,13 +397,13 @@ function start(): void {
args = validatePaths(args);
} catch (err) {
console.error(err.message);
process.exit(1);
app.exit(1);
return;
}
const instantiationService = createServices(args);
return instantiationService.invokeFunction(accessor => {
const environmentService = accessor.get(IEnvironmentService);
const instanceEnv: typeof process.env = {
......
......@@ -1318,7 +1318,7 @@ export class WindowsManager implements IWindowsMainService {
// Otherwise: normal quit
else {
setTimeout(() => {
app.quit();
this.lifecycleService.quit();
}, 10 /* delay to unwind callback stack (IPC) */);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册