mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches * A few more merges * Post npm install * Fix batch of build breaks * Fix more build breaks * Fix more build errors * Fix more build breaks * Runtime fixes 1 * Get connection dialog working with some todos * Fix a few packaging issues * Copy several node_modules to package build to fix loader issues * Fix breaks from master * A few more fixes * Make tests pass * First pass of license header updates * Second pass of license header updates * Fix restore dialog issues * Remove add additional themes menu items * fix select box issues where the list doesn't show up * formatting * Fix editor dispose issue * Copy over node modules to correct location on all platforms
This commit is contained in:
@@ -19,9 +19,16 @@ export const ILifecycleService = createDecorator<ILifecycleService>('lifecycleSe
|
||||
* a boolean directly. Returning a promise has quite an impact on the shutdown sequence!
|
||||
*/
|
||||
export interface ShutdownEvent {
|
||||
|
||||
/**
|
||||
* Allows to veto the shutdown. The veto can be a long running operation.
|
||||
*/
|
||||
veto(value: boolean | TPromise<boolean>): void;
|
||||
|
||||
/**
|
||||
* The reason why Code is shutting down.
|
||||
*/
|
||||
reason: ShutdownReason;
|
||||
payload?: object;
|
||||
}
|
||||
|
||||
export enum ShutdownReason {
|
||||
|
||||
147
src/vs/platform/lifecycle/electron-browser/lifecycleService.ts
Normal file
147
src/vs/platform/lifecycle/electron-browser/lifecycleService.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
import { ILifecycleService, ShutdownEvent, ShutdownReason, StartupKind, LifecyclePhase, handleVetos } from 'vs/platform/lifecycle/common/lifecycle';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { mark } from 'vs/base/common/performance';
|
||||
import { Barrier } from 'vs/base/common/async';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
|
||||
export class LifecycleService implements ILifecycleService {
|
||||
|
||||
private static readonly _lastShutdownReasonKey = 'lifecyle.lastShutdownReason';
|
||||
|
||||
public _serviceBrand: any;
|
||||
|
||||
private readonly _onWillShutdown = new Emitter<ShutdownEvent>();
|
||||
private readonly _onShutdown = new Emitter<ShutdownReason>();
|
||||
private readonly _startupKind: StartupKind;
|
||||
|
||||
private _phase: LifecyclePhase = LifecyclePhase.Starting;
|
||||
private _phaseWhen = new Map<LifecyclePhase, Barrier>();
|
||||
|
||||
constructor(
|
||||
@INotificationService private readonly _notificationService: INotificationService,
|
||||
@IWindowService private readonly _windowService: IWindowService,
|
||||
@IStorageService private readonly _storageService: IStorageService,
|
||||
@ILogService private readonly _logService: ILogService
|
||||
) {
|
||||
const lastShutdownReason = this._storageService.getInteger(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE);
|
||||
this._storageService.remove(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE);
|
||||
if (lastShutdownReason === ShutdownReason.RELOAD) {
|
||||
this._startupKind = StartupKind.ReloadedWindow;
|
||||
} else if (lastShutdownReason === ShutdownReason.LOAD) {
|
||||
this._startupKind = StartupKind.ReopenedWindow;
|
||||
} else {
|
||||
this._startupKind = StartupKind.NewWindow;
|
||||
}
|
||||
|
||||
this._logService.trace(`lifecycle: starting up (startup kind: ${this._startupKind})`);
|
||||
|
||||
this._registerListeners();
|
||||
}
|
||||
|
||||
private _registerListeners(): void {
|
||||
const windowId = this._windowService.getCurrentWindowId();
|
||||
|
||||
// Main side indicates that window is about to unload, check for vetos
|
||||
ipc.on('vscode:onBeforeUnload', (event, reply: { okChannel: string, cancelChannel: string, reason: ShutdownReason }) => {
|
||||
this._logService.trace(`lifecycle: onBeforeUnload (reason: ${reply.reason})`);
|
||||
|
||||
// store shutdown reason to retrieve next startup
|
||||
this._storageService.store(LifecycleService._lastShutdownReasonKey, JSON.stringify(reply.reason), StorageScope.WORKSPACE);
|
||||
|
||||
// trigger onWillShutdown events and veto collecting
|
||||
this.onBeforeUnload(reply.reason).done(veto => {
|
||||
if (veto) {
|
||||
this._logService.trace('lifecycle: onBeforeUnload prevented via veto');
|
||||
this._storageService.remove(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE);
|
||||
ipc.send(reply.cancelChannel, windowId);
|
||||
} else {
|
||||
this._logService.trace('lifecycle: onBeforeUnload continues without veto');
|
||||
ipc.send(reply.okChannel, windowId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Main side indicates that we will indeed shutdown
|
||||
ipc.on('vscode:onWillUnload', (event, reply: { replyChannel: string, reason: ShutdownReason }) => {
|
||||
this._logService.trace(`lifecycle: onWillUnload (reason: ${reply.reason})`);
|
||||
|
||||
this._onShutdown.fire(reply.reason);
|
||||
ipc.send(reply.replyChannel, windowId);
|
||||
});
|
||||
}
|
||||
|
||||
private onBeforeUnload(reason: ShutdownReason): TPromise<boolean> {
|
||||
const vetos: (boolean | TPromise<boolean>)[] = [];
|
||||
|
||||
this._onWillShutdown.fire({
|
||||
veto(value) {
|
||||
vetos.push(value);
|
||||
},
|
||||
reason
|
||||
});
|
||||
|
||||
return handleVetos(vetos, err => this._notificationService.error(toErrorMessage(err)));
|
||||
}
|
||||
|
||||
public get phase(): LifecyclePhase {
|
||||
return this._phase;
|
||||
}
|
||||
|
||||
public set phase(value: LifecyclePhase) {
|
||||
if (value < this.phase) {
|
||||
throw new Error('Lifecycle cannot go backwards');
|
||||
}
|
||||
|
||||
if (this._phase === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._logService.trace(`lifecycle: phase changed (value: ${value})`);
|
||||
|
||||
this._phase = value;
|
||||
mark(`LifecyclePhase/${LifecyclePhase[value]}`);
|
||||
|
||||
if (this._phaseWhen.has(this._phase)) {
|
||||
this._phaseWhen.get(this._phase).open();
|
||||
this._phaseWhen.delete(this._phase);
|
||||
}
|
||||
}
|
||||
|
||||
public when(phase: LifecyclePhase): Thenable<any> {
|
||||
if (phase <= this._phase) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
let barrier = this._phaseWhen.get(phase);
|
||||
if (!barrier) {
|
||||
barrier = new Barrier();
|
||||
this._phaseWhen.set(phase, barrier);
|
||||
}
|
||||
|
||||
return barrier.wait();
|
||||
}
|
||||
|
||||
public get startupKind(): StartupKind {
|
||||
return this._startupKind;
|
||||
}
|
||||
|
||||
public get onWillShutdown(): Event<ShutdownEvent> {
|
||||
return this._onWillShutdown.event;
|
||||
}
|
||||
|
||||
public get onShutdown(): Event<ShutdownReason> {
|
||||
return this._onShutdown.event;
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export interface ILifecycleService {
|
||||
ready(): void;
|
||||
registerWindow(window: ICodeWindow): void;
|
||||
|
||||
unload(window: ICodeWindow, reason: UnloadReason, payload?: object): TPromise<boolean /* veto */>;
|
||||
unload(window: ICodeWindow, reason: UnloadReason): TPromise<boolean /* veto */>;
|
||||
|
||||
relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void;
|
||||
|
||||
@@ -123,7 +123,7 @@ export class LifecycleService implements ILifecycleService {
|
||||
private registerListeners(): void {
|
||||
|
||||
// before-quit
|
||||
app.on('before-quit', (e) => {
|
||||
app.on('before-quit', e => {
|
||||
this.logService.trace('Lifecycle#before-quit');
|
||||
|
||||
if (!this.quitRequested) {
|
||||
@@ -176,7 +176,7 @@ export class LifecycleService implements ILifecycleService {
|
||||
});
|
||||
}
|
||||
|
||||
public unload(window: ICodeWindow, reason: UnloadReason, payload?: object): TPromise<boolean /* veto */> {
|
||||
public unload(window: ICodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
|
||||
|
||||
// Always allow to unload a window that is not yet ready
|
||||
if (window.readyState !== ReadyState.READY) {
|
||||
@@ -188,13 +188,26 @@ export class LifecycleService implements ILifecycleService {
|
||||
const windowUnloadReason = this.quitRequested ? UnloadReason.QUIT : reason;
|
||||
|
||||
// first ask the window itself if it vetos the unload
|
||||
return this.doUnloadWindowInRenderer(window, windowUnloadReason, payload).then(veto => {
|
||||
return this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason).then(veto => {
|
||||
if (veto) {
|
||||
this.logService.trace('Lifecycle#unload(): veto in renderer', window.id);
|
||||
|
||||
return this.handleVeto(veto);
|
||||
}
|
||||
|
||||
// then check for vetos in the main side
|
||||
return this.doUnloadWindowInMain(window, windowUnloadReason).then(veto => this.handleVeto(veto));
|
||||
return this.onBeforeUnloadWindowInMain(window, windowUnloadReason).then(veto => {
|
||||
if (veto) {
|
||||
this.logService.trace('Lifecycle#unload(): veto in main', window.id);
|
||||
|
||||
return this.handleVeto(veto);
|
||||
} else {
|
||||
this.logService.trace('Lifecycle#unload(): unload continues without veto', window.id);
|
||||
}
|
||||
|
||||
// finally if there are no vetos, unload the renderer
|
||||
return this.onWillUnloadWindowInRenderer(window, windowUnloadReason).then(() => false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -210,8 +223,8 @@ export class LifecycleService implements ILifecycleService {
|
||||
return veto;
|
||||
}
|
||||
|
||||
private doUnloadWindowInRenderer(window: ICodeWindow, reason: UnloadReason, payload?: object): TPromise<boolean /* veto */> {
|
||||
return new TPromise<boolean>((c) => {
|
||||
private onBeforeUnloadWindowInRenderer(window: ICodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
|
||||
return new TPromise<boolean>(c => {
|
||||
const oneTimeEventToken = this.oneTimeListenerTokenGenerator++;
|
||||
const okChannel = `vscode:ok${oneTimeEventToken}`;
|
||||
const cancelChannel = `vscode:cancel${oneTimeEventToken}`;
|
||||
@@ -224,11 +237,11 @@ export class LifecycleService implements ILifecycleService {
|
||||
c(true); // veto
|
||||
});
|
||||
|
||||
window.send('vscode:beforeUnload', { okChannel, cancelChannel, reason, payload });
|
||||
window.send('vscode:onBeforeUnload', { okChannel, cancelChannel, reason });
|
||||
});
|
||||
}
|
||||
|
||||
private doUnloadWindowInMain(window: ICodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
|
||||
private onBeforeUnloadWindowInMain(window: ICodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
|
||||
const vetos: (boolean | TPromise<boolean>)[] = [];
|
||||
|
||||
this._onBeforeWindowUnload.fire({
|
||||
@@ -242,6 +255,17 @@ export class LifecycleService implements ILifecycleService {
|
||||
return handleVetos(vetos, err => this.logService.error(err));
|
||||
}
|
||||
|
||||
private onWillUnloadWindowInRenderer(window: ICodeWindow, reason: UnloadReason): TPromise<void> {
|
||||
return new TPromise<void>(c => {
|
||||
const oneTimeEventToken = this.oneTimeListenerTokenGenerator++;
|
||||
const replyChannel = `vscode:reply${oneTimeEventToken}`;
|
||||
|
||||
ipc.once(replyChannel, () => c(void 0));
|
||||
|
||||
window.send('vscode:onWillUnload', { replyChannel, reason });
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A promise that completes to indicate if the quit request has been veto'd
|
||||
* by the user or not.
|
||||
@@ -275,10 +299,14 @@ export class LifecycleService implements ILifecycleService {
|
||||
}
|
||||
|
||||
public kill(code?: number): void {
|
||||
this.logService.trace('Lifecycle#kill()');
|
||||
|
||||
app.exit(code);
|
||||
}
|
||||
|
||||
public relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void {
|
||||
this.logService.trace('Lifecycle#relaunch()');
|
||||
|
||||
const args = process.argv.slice(1);
|
||||
if (options && options.addArgs) {
|
||||
args.push(...options.addArgs);
|
||||
|
||||
Reference in New Issue
Block a user