Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)

This commit is contained in:
Anthony Dresser
2019-05-24 12:20:30 -07:00
committed by GitHub
parent 361ada4963
commit bcc449b524
126 changed files with 3096 additions and 2255 deletions

View File

@@ -58,9 +58,9 @@ export abstract class AbstractLifecycleService extends Disposable implements ILi
}
}
when(phase: LifecyclePhase): Promise<void> {
async when(phase: LifecyclePhase): Promise<void> {
if (phase <= this._phase) {
return Promise.resolve();
return;
}
let barrier = this.phaseWhen.get(phase);
@@ -69,6 +69,6 @@ export abstract class AbstractLifecycleService extends Disposable implements ILi
this.phaseWhen.set(phase, barrier);
}
return barrier.wait().then(undefined);
await barrier.wait();
}
}

View File

@@ -75,18 +75,17 @@ export class LifecycleService extends AbstractLifecycleService {
});
// Main side indicates that we will indeed shutdown
ipc.on('vscode:onWillUnload', (_event: unknown, reply: { replyChannel: string, reason: ShutdownReason }) => {
ipc.on('vscode:onWillUnload', async (_event: unknown, reply: { replyChannel: string, reason: ShutdownReason }) => {
this.logService.trace(`lifecycle: onWillUnload (reason: ${reply.reason})`);
// trigger onWillShutdown events and joining
return this.handleWillShutdown(reply.reason).then(() => {
await this.handleWillShutdown(reply.reason);
// trigger onShutdown event now that we know we will quit
this._onShutdown.fire();
// trigger onShutdown event now that we know we will quit
this._onShutdown.fire();
// acknowledge to main side
ipc.send(reply.replyChannel, windowId);
});
// acknowledge to main side
ipc.send(reply.replyChannel, windowId);
});
// Save shutdown reason to retrieve on next startup
@@ -111,7 +110,7 @@ export class LifecycleService extends AbstractLifecycleService {
});
}
private handleWillShutdown(reason: ShutdownReason): Promise<void> {
private async handleWillShutdown(reason: ShutdownReason): Promise<void> {
const joiners: Promise<void>[] = [];
this._onWillShutdown.fire({
@@ -123,9 +122,11 @@ export class LifecycleService extends AbstractLifecycleService {
reason
});
return Promise.all(joiners).then(() => undefined, err => {
this.notificationService.error(toErrorMessage(err));
onUnexpectedError(err);
});
try {
await Promise.all(joiners);
} catch (error) {
this.notificationService.error(toErrorMessage(error));
onUnexpectedError(error);
}
}
}

View File

@@ -291,7 +291,7 @@ export class LifecycleService extends Disposable implements ILifecycleService {
});
}
unload(window: ICodeWindow, reason: UnloadReason): Promise<boolean /* veto */> {
async unload(window: ICodeWindow, reason: UnloadReason): Promise<boolean /* veto */> {
// Always allow to unload a window that is not yet ready
if (!window.isReady) {
@@ -302,27 +302,27 @@ export class LifecycleService extends Disposable implements ILifecycleService {
// first ask the window itself if it vetos the unload
const windowUnloadReason = this._quitRequested ? UnloadReason.QUIT : reason;
return this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason).then(veto => {
if (veto) {
this.logService.trace(`Lifecycle#unload() - veto in renderer (window ID ${window.id})`);
let veto = await this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason);
if (veto) {
this.logService.trace(`Lifecycle#unload() - veto in renderer (window ID ${window.id})`);
return this.handleWindowUnloadVeto(veto);
}
return this.handleWindowUnloadVeto(veto);
}
// then check for vetos in the main side
return this.onBeforeUnloadWindowInMain(window, windowUnloadReason).then(veto => {
if (veto) {
this.logService.trace(`Lifecycle#unload() - veto in main (window ID ${window.id})`);
// then check for vetos in the main side
veto = await this.onBeforeUnloadWindowInMain(window, windowUnloadReason);
if (veto) {
this.logService.trace(`Lifecycle#unload() - veto in main (window ID ${window.id})`);
return this.handleWindowUnloadVeto(veto);
}
return this.handleWindowUnloadVeto(veto);
}
this.logService.trace(`Lifecycle#unload() - no veto (window ID ${window.id})`);
this.logService.trace(`Lifecycle#unload() - no veto (window ID ${window.id})`);
// finally if there are no vetos, unload the renderer
return this.onWillUnloadWindowInRenderer(window, windowUnloadReason).then(() => false);
});
});
// finally if there are no vetos, unload the renderer
await this.onWillUnloadWindowInRenderer(window, windowUnloadReason);
return false;
}
private handleWindowUnloadVeto(veto: boolean): boolean {