Merge VS Code 1.23.1 (#1520)

This commit is contained in:
Matt Irvine
2018-06-05 11:24:51 -07:00
committed by GitHub
parent e3baf5c443
commit 0c58f09e59
3651 changed files with 74249 additions and 48599 deletions

View File

@@ -5,7 +5,7 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import Event from 'vs/base/common/event';
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const ILifecycleService = createDecorator<ILifecycleService>('lifecycleService');

View File

@@ -9,7 +9,7 @@ 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 { 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';

View File

@@ -9,11 +9,12 @@ import { ipcMain as ipc, app } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ILogService } from 'vs/platform/log/common/log';
import { IStateService } from 'vs/platform/state/common/state';
import Event, { Emitter } from 'vs/base/common/event';
import { Event, Emitter } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { ReadyState } from 'vs/platform/windows/common/windows';
import { handleVetos } from 'vs/platform/lifecycle/common/lifecycle';
import { isMacintosh, isWindows } from 'vs/base/common/platform';
export const ILifecycleService = createDecorator<ILifecycleService>('lifecycleService');
@@ -38,12 +39,24 @@ export interface ILifecycleService {
*/
wasRestarted: boolean;
/**
* Will be true if the program was requested to quit.
*/
isQuitRequested: boolean;
/**
* Due to the way we handle lifecycle with eventing, the general app.on('before-quit')
* event cannot be used because it can be called twice on shutdown. Instead the onBeforeQuit
* event cannot be used because it can be called twice on shutdown. Instead the onBeforeShutdown
* handler in this module can be used and it is only called once on a shutdown sequence.
*/
onBeforeQuit: Event<void>;
onBeforeShutdown: Event<void>;
/**
* An event that fires after the onBeforeShutdown event has been fired and after no window has
* vetoed the shutdown sequence. At this point listeners are ensured that the application will
* quit without veto.
*/
onShutdown: Event<void>;
/**
* We provide our own event when we close a window because the general window.on('close')
@@ -65,7 +78,6 @@ export interface ILifecycleService {
relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void;
quit(fromUpdate?: boolean): TPromise<boolean /* veto */>;
isQuitRequested(): boolean;
kill(code?: number): void;
}
@@ -82,9 +94,13 @@ export class LifecycleService implements ILifecycleService {
private pendingQuitPromiseComplete: TValueCallback<boolean>;
private oneTimeListenerTokenGenerator: number;
private _wasRestarted: boolean;
private windowCounter: number;
private _onBeforeQuit = new Emitter<void>();
onBeforeQuit: Event<void> = this._onBeforeQuit.event;
private _onBeforeShutdown = new Emitter<void>();
onBeforeShutdown: Event<void> = this._onBeforeShutdown.event;
private _onShutdown = new Emitter<void>();
onShutdown: Event<void> = this._onShutdown.event;
private _onBeforeWindowClose = new Emitter<ICodeWindow>();
onBeforeWindowClose: Event<ICodeWindow> = this._onBeforeWindowClose.event;
@@ -100,6 +116,7 @@ export class LifecycleService implements ILifecycleService {
this.quitRequested = false;
this.oneTimeListenerTokenGenerator = 0;
this._wasRestarted = false;
this.windowCounter = 0;
this.handleRestarted();
}
@@ -116,6 +133,10 @@ export class LifecycleService implements ILifecycleService {
return this._wasRestarted;
}
public get isQuitRequested(): boolean {
return !!this.quitRequested;
}
public ready(): void {
this.registerListeners();
}
@@ -126,11 +147,23 @@ export class LifecycleService implements ILifecycleService {
app.on('before-quit', e => {
this.logService.trace('Lifecycle#before-quit');
if (!this.quitRequested) {
this._onBeforeQuit.fire(); // only send this if this is the first quit request we have
if (this.quitRequested) {
this.logService.trace('Lifecycle#before-quit - returning because quit was already requested');
return;
}
this.quitRequested = true;
// Emit event to indicate that we are about to shutdown
this.logService.trace('Lifecycle#onBeforeShutdown.fire()');
this._onBeforeShutdown.fire();
// macOS: can run without any window open. in that case we fire
// the onShutdown() event directly because there is no veto to be expected.
if (isMacintosh && this.windowCounter === 0) {
this.logService.trace('Lifecycle#onShutdown.fire()');
this._onShutdown.fire();
}
});
// window-all-closed
@@ -147,6 +180,9 @@ export class LifecycleService implements ILifecycleService {
public registerWindow(window: ICodeWindow): void {
// track window count
this.windowCounter++;
// Window Before Closing: Main -> Renderer
window.win.on('close', e => {
const windowId = window.id;
@@ -166,7 +202,10 @@ export class LifecycleService implements ILifecycleService {
this.unload(window, UnloadReason.CLOSE).done(veto => {
if (!veto) {
this.windowToCloseRequest[windowId] = true;
this.logService.trace('Lifecycle#onBeforeWindowClose.fire()');
this._onBeforeWindowClose.fire(window);
window.close();
} else {
this.quitRequested = false;
@@ -174,6 +213,23 @@ export class LifecycleService implements ILifecycleService {
}
});
});
// Window After Closing
window.win.on('closed', e => {
const windowId = window.id;
this.logService.trace('Lifecycle#window-closed', windowId);
// update window count
this.windowCounter--;
// if there are no more code windows opened, fire the onShutdown event, unless
// we are on macOS where it is perfectly fine to close the last window and
// the application continues running (unless quit was actually requested)
if (this.windowCounter === 0 && (!isMacintosh || this.isQuitRequested)) {
this.logService.trace('Lifecycle#onShutdown.fire()');
this._onShutdown.fire();
}
});
}
public unload(window: ICodeWindow, reason: UnloadReason): TPromise<boolean /* veto */> {
@@ -279,7 +335,10 @@ export class LifecycleService implements ILifecycleService {
// Store as field to access it from a window cancellation
this.pendingQuitPromiseComplete = c;
// The will-quit event is fired when all windows have closed without veto
app.once('will-quit', () => {
this.logService.trace('Lifecycle#will-quit');
if (this.pendingQuitPromiseComplete) {
if (fromUpdate) {
this.stateService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true);
@@ -291,8 +350,13 @@ export class LifecycleService implements ILifecycleService {
}
});
// Calling app.quit() will trigger the close handlers of each opened window
// and only if no window vetoed the shutdown, we will get the will-quit event
this.logService.trace('Lifecycle#quit() - calling app.quit()');
app.quit();
});
} else {
this.logService.trace('Lifecycle#quit() - a pending quit was found');
}
return this.pendingQuitPromise;
@@ -325,6 +389,19 @@ export class LifecycleService implements ILifecycleService {
app.once('quit', () => {
if (!vetoed) {
this.stateService.setItem(LifecycleService.QUIT_FROM_RESTART_MARKER, true);
// Windows: we are about to restart and as such we need to restore the original
// current working directory we had on startup to get the exact same startup
// behaviour. As such, we briefly change back to the VSCODE_CWD and then when
// Code starts it will set it back to the installation directory again.
try {
if (isWindows) {
process.chdir(process.env['VSCODE_CWD']);
}
} catch (err) {
this.logService.error(err);
}
app.relaunch({ args });
}
});
@@ -333,8 +410,4 @@ export class LifecycleService implements ILifecycleService {
vetoed = veto;
});
}
public isQuitRequested(): boolean {
return !!this.quitRequested;
}
}