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

towards better quit handling (for #22138)

上级 c78e43ef
...@@ -47,10 +47,15 @@ export interface ILifecycleService { ...@@ -47,10 +47,15 @@ export interface ILifecycleService {
ready(): void; ready(): void;
registerWindow(vscodeWindow: VSCodeWindow): void; registerWindow(vscodeWindow: VSCodeWindow): void;
unload(vscodeWindow: VSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */>; unload(vscodeWindow: VSCodeWindow, reason: UnloadReason): TPromise<boolean /* veto */>;
relaunch(options?: { addArgs?: string[], removeArgs?: string[] });
quit(fromUpdate?: boolean): TPromise<boolean /* veto */>; quit(fromUpdate?: boolean): TPromise<boolean /* veto */>;
relaunch(options: { addArgs?: string[], removeArgs?: string[] });
isQuitRequested(): boolean; isQuitRequested(): boolean;
kill(code?: number);
} }
export class LifecycleService implements ILifecycleService { export class LifecycleService implements ILifecycleService {
...@@ -210,6 +215,7 @@ export class LifecycleService implements ILifecycleService { ...@@ -210,6 +215,7 @@ export class LifecycleService implements ILifecycleService {
if (fromUpdate) { if (fromUpdate) {
this.storageService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true); this.storageService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true);
} }
this.pendingQuitPromiseComplete(false /* no veto */); this.pendingQuitPromiseComplete(false /* no veto */);
this.pendingQuitPromiseComplete = null; this.pendingQuitPromiseComplete = null;
this.pendingQuitPromise = null; this.pendingQuitPromise = null;
...@@ -223,6 +229,10 @@ export class LifecycleService implements ILifecycleService { ...@@ -223,6 +229,10 @@ export class LifecycleService implements ILifecycleService {
return this.pendingQuitPromise; return this.pendingQuitPromise;
} }
public kill(code?: number): void {
app.exit(code);
}
public relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void { public relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void {
const args = process.argv.slice(1); const args = process.argv.slice(1);
if (options && options.addArgs) { if (options && options.addArgs) {
...@@ -238,10 +248,17 @@ export class LifecycleService implements ILifecycleService { ...@@ -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(); this.quit().then(veto => {
app.once('quit', () => app.relaunch({ args })); vetod = veto;
});
} }
public isQuitRequested(): boolean { public isQuitRequested(): boolean {
......
...@@ -58,7 +58,6 @@ import product from 'vs/platform/node/product'; ...@@ -58,7 +58,6 @@ import product from 'vs/platform/node/product';
import pkg from 'vs/platform/node/package'; import pkg from 'vs/platform/node/package';
import * as fs from 'original-fs'; import * as fs from 'original-fs';
ipc.on('vscode:fetchShellEnv', (event, windowId) => { ipc.on('vscode:fetchShellEnv', (event, windowId) => {
const win = BrowserWindow.fromId(windowId); const win = BrowserWindow.fromId(windowId);
getShellEnvironment().then(shellEnv => { getShellEnvironment().then(shellEnv => {
...@@ -71,6 +70,7 @@ ipc.on('vscode:fetchShellEnv', (event, windowId) => { ...@@ -71,6 +70,7 @@ ipc.on('vscode:fetchShellEnv', (event, windowId) => {
function quit(accessor: ServicesAccessor, errorOrMessage?: Error | string): void { function quit(accessor: ServicesAccessor, errorOrMessage?: Error | string): void {
const logService = accessor.get(ILogService); const logService = accessor.get(ILogService);
const lifecycleService = accessor.get(ILifecycleService);
let exitCode = 0; let exitCode = 0;
if (typeof errorOrMessage === 'string') { if (typeof errorOrMessage === 'string') {
...@@ -84,7 +84,7 @@ function quit(accessor: ServicesAccessor, errorOrMessage?: Error | string): void ...@@ -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! // TODO@Joao wow this is huge, clean up!
...@@ -247,7 +247,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo ...@@ -247,7 +247,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
logService.log('IPC#vscode:exit', code); logService.log('IPC#vscode:exit', code);
dispose(); dispose();
process.exit(code); // in main, process.exit === app.exit lifecycleService.kill(code);
}); });
// Lifecycle // Lifecycle
...@@ -397,13 +397,13 @@ function start(): void { ...@@ -397,13 +397,13 @@ function start(): void {
args = validatePaths(args); args = validatePaths(args);
} catch (err) { } catch (err) {
console.error(err.message); console.error(err.message);
process.exit(1); app.exit(1);
return; return;
} }
const instantiationService = createServices(args); const instantiationService = createServices(args);
return instantiationService.invokeFunction(accessor => { return instantiationService.invokeFunction(accessor => {
const environmentService = accessor.get(IEnvironmentService); const environmentService = accessor.get(IEnvironmentService);
const instanceEnv: typeof process.env = { const instanceEnv: typeof process.env = {
......
...@@ -1318,7 +1318,7 @@ export class WindowsManager implements IWindowsMainService { ...@@ -1318,7 +1318,7 @@ export class WindowsManager implements IWindowsMainService {
// Otherwise: normal quit // Otherwise: normal quit
else { else {
setTimeout(() => { setTimeout(() => {
app.quit(); this.lifecycleService.quit();
}, 10 /* delay to unwind callback stack (IPC) */); }, 10 /* delay to unwind callback stack (IPC) */);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册