Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -3,29 +3,28 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path';
import * as objects from 'vs/base/common/objects';
import * as nls from 'vs/nls';
import URI from 'vs/base/common/uri';
import { URI } from 'vs/base/common/uri';
import { IStateService } from 'vs/platform/state/common/state';
import { shell, screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage } from 'electron';
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs } from 'vs/platform/environment/node/argv';
import product from 'vs/platform/node/product';
import { IWindowSettings, MenuBarVisibility, IWindowConfiguration, ReadyState, IRunActionInWindowRequest } from 'vs/platform/windows/common/windows';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IWindowSettings, MenuBarVisibility, IWindowConfiguration, ReadyState, IRunActionInWindowRequest, getTitleBarStyle } from 'vs/platform/windows/common/windows';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { ICodeWindow, IWindowState, WindowMode } from 'vs/platform/windows/electron-main/windows';
import { IWorkspaceIdentifier, IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces';
import { IBackupMainService } from 'vs/platform/backup/common/backup';
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
import { mark, exportEntries } from 'vs/base/common/performance';
import * as perf from 'vs/base/common/performance';
import { resolveMarketplaceHeaders } from 'vs/platform/extensionManagement/node/extensionGalleryService';
import { getBackgroundColor } from 'vs/code/electron-main/theme';
import { IStorageMainService } from 'vs/platform/storage/node/storageMainService';
export interface IWindowCreationOptions {
state: IWindowState;
@@ -53,18 +52,13 @@ interface ITouchBarSegment extends Electron.SegmentedControlSegment {
id: string;
}
export class CodeWindow implements ICodeWindow {
static readonly themeStorageKey = 'theme';
static readonly themeBackgroundStorageKey = 'themeBackground';
private static readonly DEFAULT_BG_LIGHT = '#FFFFFF';
private static readonly DEFAULT_BG_DARK = '#1E1E1E';
private static readonly DEFAULT_BG_HC_BLACK = '#000000';
export class CodeWindow extends Disposable implements ICodeWindow {
private static readonly MIN_WIDTH = 200;
private static readonly MIN_HEIGHT = 120;
private static readonly MAX_URL_LENGTH = 2 * 1024 * 1024; // https://cs.chromium.org/chromium/src/url/url_constants.cc?l=32
private hiddenTitleBarStyle: boolean;
private showTimeoutHandle: any;
private _id: number;
@@ -73,15 +67,14 @@ export class CodeWindow implements ICodeWindow {
private _readyState: ReadyState;
private windowState: IWindowState;
private currentMenuBarVisibility: MenuBarVisibility;
private toDispose: IDisposable[];
private representedFilename: string;
private whenReadyCallbacks: TValueCallback<ICodeWindow>[];
private whenReadyCallbacks: { (window: ICodeWindow): void }[];
private currentConfig: IWindowConfiguration;
private pendingLoadConfig: IWindowConfiguration;
private marketplaceHeadersPromise: TPromise<object>;
private marketplaceHeadersPromise: Thenable<object>;
private touchBarGroups: Electron.TouchBarSegmentedControl[];
@@ -92,13 +85,15 @@ export class CodeWindow implements ICodeWindow {
@IConfigurationService private configurationService: IConfigurationService,
@IStateService private stateService: IStateService,
@IWorkspacesMainService private workspacesMainService: IWorkspacesMainService,
@IBackupMainService private backupMainService: IBackupMainService
@IBackupMainService private backupMainService: IBackupMainService,
@IStorageMainService private storageMainService: IStorageMainService
) {
super();
this.touchBarGroups = [];
this._lastFocusTime = -1;
this._readyState = ReadyState.NONE;
this.whenReadyCallbacks = [];
this.toDispose = [];
// create browser window
this.createBrowserWindow(config);
@@ -124,24 +119,22 @@ export class CodeWindow implements ICodeWindow {
// in case we are maximized or fullscreen, only show later after the call to maximize/fullscreen (see below)
const isFullscreenOrMaximized = (this.windowState.mode === WindowMode.Maximized || this.windowState.mode === WindowMode.Fullscreen);
let backgroundColor = this.getBackgroundColor();
if (isMacintosh && backgroundColor.toUpperCase() === CodeWindow.DEFAULT_BG_DARK) {
backgroundColor = '#171717'; // https://github.com/electron/electron/issues/5150
}
const options: Electron.BrowserWindowConstructorOptions = {
width: this.windowState.width,
height: this.windowState.height,
x: this.windowState.x,
y: this.windowState.y,
backgroundColor,
backgroundColor: getBackgroundColor(this.stateService),
minWidth: CodeWindow.MIN_WIDTH,
minHeight: CodeWindow.MIN_HEIGHT,
show: !isFullscreenOrMaximized,
title: product.nameLong,
webPreferences: {
'backgroundThrottling': false, // by default if Code is in the background, intervals and timeouts get throttled,
disableBlinkFeatures: 'Auxclick' // disable auxclick events (see https://developers.google.com/web/updates/2016/10/auxclick)
// By default if Code is in the background, intervals and timeouts get throttled, so we
// want to enforce that Code stays in the foreground. This triggers a disable_hidden_
// flag that Electron provides via patch:
// https://github.com/electron/libchromiumcontent/blob/master/patches/common/chromium/disable_hidden.patch
'backgroundThrottling': false
}
};
@@ -151,6 +144,10 @@ export class CodeWindow implements ICodeWindow {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
if (isMacintosh && !this.useNativeFullScreen()) {
options.fullscreenable = false; // enables simple fullscreen mode
}
if (isMacintosh) {
options.acceptFirstMouse = true; // enabled by default
@@ -159,28 +156,14 @@ export class CodeWindow implements ICodeWindow {
}
}
let useNativeTabs = false;
if (isMacintosh && windowConfig && windowConfig.nativeTabs === true) {
options.tabbingIdentifier = product.nameShort; // this opts in to sierra tabs
useNativeTabs = true;
}
let useCustomTitleStyle = false;
// {{SQL CARBON EDIT}}
// if (isMacintosh) {
// turn-off custom menus to avoid bug calculating size of SQL editor
//
// if (isMacintosh && (!windowConfig || !windowConfig.titleBarStyle || windowConfig.titleBarStyle === 'custom')) {
// const isDev = !this.environmentService.isBuilt || !!config.extensionDevelopmentPath;
// if (!isDev) {
// useCustomTitleStyle = true; // not enabled when developing due to https://github.com/electron/electron/issues/3647
// }
// }
if (useNativeTabs) {
useCustomTitleStyle = false; // native tabs on sierra do not work with custom title style
}
// const useCustomTitleStyle = getTitleBarStyle(this.configurationService, this.environmentService, !!config.extensionDevelopmentPath) === 'custom';
const useCustomTitleStyle = false;
if (useCustomTitleStyle) {
options.titleBarStyle = 'hidden';
this.hiddenTitleBarStyle = true;
@@ -193,7 +176,7 @@ export class CodeWindow implements ICodeWindow {
this._win = new BrowserWindow(options);
this._id = this._win.id;
if (useCustomTitleStyle) {
if (isMacintosh && useCustomTitleStyle) {
this._win.setSheetOffset(22); // offset dialogs by the height of the custom title bar if we have any
}
@@ -201,7 +184,7 @@ export class CodeWindow implements ICodeWindow {
this._win.maximize();
if (this.windowState.mode === WindowMode.Fullscreen) {
this._win.setFullScreen(true);
this.setFullScreen(true);
}
if (!this._win.isVisible()) {
@@ -284,6 +267,10 @@ export class CodeWindow implements ICodeWindow {
return this.currentConfig ? this.currentConfig.folderUri : void 0;
}
get remoteAuthority(): string {
return this.currentConfig ? this.currentConfig.remoteAuthority : void 0;
}
setReady(): void {
this._readyState = ReadyState.READY;
@@ -293,19 +280,19 @@ export class CodeWindow implements ICodeWindow {
}
}
ready(): TPromise<ICodeWindow> {
return new TPromise<ICodeWindow>((c) => {
if (this._readyState === ReadyState.READY) {
return c(this);
ready(): Thenable<ICodeWindow> {
return new Promise<ICodeWindow>(resolve => {
if (this.isReady) {
return resolve(this);
}
// otherwise keep and call later when we are ready
this.whenReadyCallbacks.push(c);
this.whenReadyCallbacks.push(resolve);
});
}
get readyState(): ReadyState {
return this._readyState;
get isReady(): boolean {
return this._readyState === ReadyState.READY;
}
private handleMarketplaceRequests(): void {
@@ -316,7 +303,7 @@ export class CodeWindow implements ICodeWindow {
// Inject headers when requests are incoming
const urls = ['https://marketplace.visualstudio.com/*', 'https://*.vsassets.io/*'];
this._win.webContents.session.webRequest.onBeforeSendHeaders({ urls }, (details: any, cb: any) => {
this.marketplaceHeadersPromise.done(headers => {
this.marketplaceHeadersPromise.then(headers => {
cb({ cancel: false, requestHeaders: objects.assign(details.requestHeaders, headers) });
});
});
@@ -371,20 +358,26 @@ export class CodeWindow implements ICodeWindow {
// App commands support
this.registerNavigationListenerOn('app-command', 'browser-backward', 'browser-forward', false);
// Handle code that wants to open links
this._win.webContents.on('new-window', (event: Event, url: string) => {
event.preventDefault();
shell.openExternal(url);
});
// Window Focus
this._win.on('focus', () => {
this._lastFocusTime = Date.now();
});
// Simple fullscreen doesn't resize automatically when the resolution changes
if (isMacintosh) {
const displayMetricsChangedListener = () => {
if (this.isFullScreen() && !this.useNativeFullScreen()) {
this.setFullScreen(false);
this.setFullScreen(true);
}
};
screen.addListener('display-metrics-changed', displayMetricsChangedListener);
this._register(toDisposable(() => screen.removeListener('display-metrics-changed', displayMetricsChangedListener)));
}
// Window (Un)Maximize
this._win.on('maximize', (e) => {
this._win.on('maximize', e => {
if (this.currentConfig) {
this.currentConfig.maximized = true;
}
@@ -392,7 +385,7 @@ export class CodeWindow implements ICodeWindow {
app.emit('browser-window-maximize', e, this._win);
});
this._win.on('unmaximize', (e) => {
this._win.on('unmaximize', e => {
if (this.currentConfig) {
this.currentConfig.maximized = false;
}
@@ -414,21 +407,11 @@ export class CodeWindow implements ICodeWindow {
this.logService.warn('[electron event]: fail to load, ', errorDescription);
});
// Prevent any kind of navigation triggered by the user!
// But do not touch this in dev version because it will prevent "Reload" from dev tools
if (this.environmentService.isBuilt) {
this._win.webContents.on('will-navigate', (event: Event) => {
if (event) {
event.preventDefault();
}
});
}
// Handle configuration changes
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated()));
this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated()));
// Handle Workspace events
this.toDispose.push(this.workspacesMainService.onUntitledWorkspaceDeleted(e => this.onUntitledWorkspaceDeleted(e)));
this._register(this.workspacesMainService.onUntitledWorkspaceDeleted(e => this.onUntitledWorkspaceDeleted(e)));
// TODO@Ben workaround for https://github.com/Microsoft/vscode/issues/13612
// It looks like smooth scrolling disappears as soon as the window is minimized
@@ -488,7 +471,7 @@ export class CodeWindow implements ICodeWindow {
private registerNavigationListenerOn(command: 'swipe' | 'app-command', back: 'left' | 'browser-backward', forward: 'right' | 'browser-forward', acrossEditors: boolean) {
this._win.on(command as 'swipe' /* | 'app-command' */, (e: Electron.Event, cmd: string) => {
if (this.readyState !== ReadyState.READY) {
if (!this.isReady) {
return; // window must be ready
}
@@ -500,11 +483,17 @@ export class CodeWindow implements ICodeWindow {
});
}
addTabbedWindow(window: ICodeWindow): void {
if (isMacintosh) {
this._win.addTabbedWindow(window.win);
}
}
load(config: IWindowConfiguration, isReload?: boolean, disableExtensions?: boolean): void {
// If this is the first time the window is loaded, we associate the paths
// directly with the window because we assume the loading will just work
if (this.readyState === ReadyState.NONE) {
if (this._readyState === ReadyState.NONE) {
this.currentConfig = config;
}
@@ -541,7 +530,7 @@ export class CodeWindow implements ICodeWindow {
}
// Load URL
mark('main:loadWindow');
perf.mark('main:loadWindow');
this._win.loadURL(this.getUrl(configuration));
// Make window visible if it did not open in N seconds because this indicates an error
@@ -601,7 +590,7 @@ export class CodeWindow implements ICodeWindow {
}
// Set fullscreen state
windowConfiguration.fullscreen = this._win.isFullScreen();
windowConfiguration.fullscreen = this.isFullScreen();
// Set Accessibility Config
let autoDetectHighContrast = true;
@@ -611,54 +600,45 @@ export class CodeWindow implements ICodeWindow {
windowConfiguration.highContrast = isWindows && autoDetectHighContrast && systemPreferences.isInvertedColorScheme();
windowConfiguration.accessibilitySupport = app.isAccessibilitySupportEnabled();
// Theme
windowConfiguration.baseTheme = this.getBaseTheme();
windowConfiguration.backgroundColor = this.getBackgroundColor();
// Title style related
windowConfiguration.maximized = this._win.isMaximized();
windowConfiguration.frameless = this.hasHiddenTitleBarStyle() && !isMacintosh;
// Perf Counters
windowConfiguration.perfEntries = exportEntries();
windowConfiguration.perfStartTime = (<any>global).perfStartTime;
windowConfiguration.perfWindowLoadTime = Date.now();
// Dump Perf Counters
windowConfiguration.perfEntries = perf.exportEntries();
// Parts splash
windowConfiguration.partsSplashData = this.storageMainService.get('parts-splash-data', void 0);
// Config (combination of process.argv and window configuration)
const environment = parseArgs(process.argv);
const config = objects.assign(environment, windowConfiguration);
for (let key in config) {
if (config[key] === void 0 || config[key] === null || config[key] === '') {
if (config[key] === void 0 || config[key] === null || config[key] === '' || config[key] === false) {
delete config[key]; // only send over properties that have a true value
}
}
return `${require.toUrl('vs/workbench/electron-browser/bootstrap/index.html')}?config=${encodeURIComponent(JSON.stringify(config))}`;
// In the unlikely event of the URL becoming larger than 2MB, remove parts of
// it that are not under our control. Mainly, the user environment can be very
// large depending on user configuration, so we can only remove it in that case.
let configUrl = this.doGetUrl(config);
if (configUrl.length > CodeWindow.MAX_URL_LENGTH) {
delete config.userEnv;
this.logService.warn('Application URL exceeds maximum of 2MB and was shortened.');
configUrl = this.doGetUrl(config);
if (configUrl.length > CodeWindow.MAX_URL_LENGTH) {
this.logService.error('Application URL exceeds maximum of 2MB and cannot be loaded.');
}
}
return configUrl;
}
private getBaseTheme(): string {
if (isWindows && systemPreferences.isInvertedColorScheme()) {
return 'hc-black';
}
const theme = this.stateService.getItem<string>(CodeWindow.themeStorageKey, 'vs-dark');
return theme.split(' ')[0];
}
private getBackgroundColor(): string {
if (isWindows && systemPreferences.isInvertedColorScheme()) {
return CodeWindow.DEFAULT_BG_HC_BLACK;
}
const background = this.stateService.getItem<string>(CodeWindow.themeBackgroundStorageKey, null);
if (!background) {
const baseTheme = this.getBaseTheme();
return baseTheme === 'hc-black' ? CodeWindow.DEFAULT_BG_HC_BLACK : (baseTheme === 'vs' ? CodeWindow.DEFAULT_BG_LIGHT : CodeWindow.DEFAULT_BG_DARK);
}
return background;
private doGetUrl(config: object): string {
return `${require.toUrl('vs/code/electron-browser/workbench/workbench.html')}?config=${encodeURIComponent(JSON.stringify(config))}`;
}
serializeWindowState(): IWindowState {
@@ -667,19 +647,27 @@ export class CodeWindow implements ICodeWindow {
}
// fullscreen gets special treatment
if (this._win.isFullScreen()) {
if (this.isFullScreen()) {
const display = screen.getDisplayMatching(this.getBounds());
return {
const defaultState = defaultWindowState();
const res = {
mode: WindowMode.Fullscreen,
display: display ? display.id : void 0,
// still carry over window dimensions from previous sessions!
width: this.windowState.width,
height: this.windowState.height,
x: this.windowState.x,
y: this.windowState.y
// Still carry over window dimensions from previous sessions
// if we can compute it in fullscreen state.
// does not seem possible in all cases on Linux for example
// (https://github.com/Microsoft/vscode/issues/58218) so we
// fallback to the defaults in that case.
width: this.windowState.width || defaultState.width,
height: this.windowState.height || defaultState.height,
x: this.windowState.x || 0,
y: this.windowState.y || 0
};
return res;
}
const state: IWindowState = Object.create(null);
@@ -825,15 +813,63 @@ export class CodeWindow implements ICodeWindow {
}
toggleFullScreen(): void {
const willBeFullScreen = !this._win.isFullScreen();
this.setFullScreen(!this.isFullScreen());
}
// set fullscreen flag on window
this._win.setFullScreen(willBeFullScreen);
private setFullScreen(fullscreen: boolean): void {
// respect configured menu bar visibility or default to toggle if not set
// Set fullscreen state
if (this.useNativeFullScreen()) {
this.setNativeFullScreen(fullscreen);
} else {
this.setSimpleFullScreen(fullscreen);
}
// Events
this.sendWhenReady(fullscreen ? 'vscode:enterFullScreen' : 'vscode:leaveFullScreen');
// Respect configured menu bar visibility or default to toggle if not set
this.setMenuBarVisibility(this.currentMenuBarVisibility, false);
}
isFullScreen(): boolean {
return this._win.isFullScreen() || this._win.isSimpleFullScreen();
}
private setNativeFullScreen(fullscreen: boolean): void {
if (this._win.isSimpleFullScreen()) {
this._win.setSimpleFullScreen(false);
}
this._win.setFullScreen(fullscreen);
}
private setSimpleFullScreen(fullscreen: boolean): void {
if (this._win.isFullScreen()) {
this._win.setFullScreen(false);
}
this._win.setSimpleFullScreen(fullscreen);
this._win.webContents.focus(); // workaround issue where focus is not going into window
}
private useNativeFullScreen(): boolean {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
if (!windowConfig || typeof windowConfig.nativeFullScreen !== 'boolean') {
return true; // default
}
if (windowConfig.nativeTabs) {
return true; // https://github.com/electron/electron/issues/16142
}
return windowConfig.nativeFullScreen !== false;
}
isMinimized(): boolean {
return this._win.isMinimized();
}
private getMenuBarVisibility(): MenuBarVisibility {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
if (!windowConfig || !windowConfig.menuBarVisibility) {
@@ -874,7 +910,7 @@ export class CodeWindow implements ICodeWindow {
}
private doSetMenuBarVisibility(visibility: MenuBarVisibility): void {
const isFullscreen = this._win.isFullScreen();
const isFullscreen = this.isFullScreen();
switch (visibility) {
case ('default'):
@@ -912,7 +948,11 @@ export class CodeWindow implements ICodeWindow {
break;
case 'Maximize':
default:
this.win.maximize();
if (this.win.isMaximized()) {
this.win.unmaximize();
} else {
this.win.maximize();
}
}
}
@@ -933,9 +973,11 @@ export class CodeWindow implements ICodeWindow {
}
sendWhenReady(channel: string, ...args: any[]): void {
this.ready().then(() => {
if (this.isReady) {
this.send(channel, ...args);
});
} else {
this.ready().then(() => this.send(channel, ...args));
}
}
send(channel: string, ...args: any[]): void {
@@ -1012,12 +1054,12 @@ export class CodeWindow implements ICodeWindow {
}
dispose(): void {
super.dispose();
if (this.showTimeoutHandle) {
clearTimeout(this.showTimeoutHandle);
}
this.toDispose = dispose(this.toDispose);
this._win = null; // Important to dereference the window object to allow for GC
}
}