Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 (#15681)

* Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898

* Fixes and cleanup

* Distro

* Fix hygiene yarn

* delete no yarn lock changes file

* Fix hygiene

* Fix layer check

* Fix CI

* Skip lib checks

* Remove tests deleted in vs code

* Fix tests

* Distro

* Fix tests and add removed extension point

* Skip failing notebook tests for now

* Disable broken tests and cleanup build folder

* Update yarn.lock and fix smoke tests

* Bump sqlite

* fix contributed actions and file spacing

* Fix user data path

* Update yarn.locks

Co-authored-by: ADS Merger <karlb@microsoft.com>
This commit is contained in:
Charles Gagnon
2021-06-17 08:17:11 -07:00
committed by GitHub
parent fdcb97c7f7
commit 3cb2f552a6
2582 changed files with 124827 additions and 87099 deletions

View File

@@ -45,6 +45,8 @@ export interface ICommonNativeHostService {
readonly onDidFocusWindow: Event<number>;
readonly onDidBlurWindow: Event<number>;
readonly onDidChangeDisplay: Event<void>;
readonly onDidResumeOS: Event<unknown>;
readonly onDidChangeColorScheme: Event<IColorScheme>;
@@ -98,7 +100,7 @@ export interface ICommonNativeHostService {
moveItemToTrash(fullPath: string, deleteOnFail?: boolean): Promise<boolean>;
isAdmin(): Promise<boolean>;
writeElevated(source: URI, target: URI, options?: { overwriteReadonly?: boolean }): Promise<void>;
writeElevated(source: URI, target: URI, options?: { unlock?: boolean }): Promise<void>;
getOSProperties(): Promise<IOSProperties>;
getOSStatistics(): Promise<IOSStatistics>;

View File

@@ -5,7 +5,7 @@
import { Emitter, Event } from 'vs/base/common/event';
import { IWindowsMainService, ICodeWindow, OpenContext } from 'vs/platform/windows/electron-main/windows';
import { MessageBoxOptions, MessageBoxReturnValue, shell, OpenDevToolsOptions, SaveDialogOptions, SaveDialogReturnValue, OpenDialogOptions, OpenDialogReturnValue, Menu, BrowserWindow, app, clipboard, powerMonitor, nativeTheme } from 'electron';
import { MessageBoxOptions, MessageBoxReturnValue, shell, OpenDevToolsOptions, SaveDialogOptions, SaveDialogReturnValue, OpenDialogOptions, OpenDialogReturnValue, Menu, BrowserWindow, app, clipboard, powerMonitor, nativeTheme, screen, Display } from 'electron';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IOpenedWindow, IOpenWindowOptions, IWindowOpenable, IOpenEmptyWindowOptions, IColorScheme } from 'vs/platform/windows/common/windows';
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
@@ -24,7 +24,7 @@ import { arch, totalmem, release, platform, type, loadavg, freemem, cpus } from
import { virtualMachineHint } from 'vs/base/node/id';
import { ILogService } from 'vs/platform/log/common/log';
import { dirname, join } from 'vs/base/common/path';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { memoize } from 'vs/base/common/decorators';
import { Disposable } from 'vs/base/common/lifecycle';
import { ISharedProcess } from 'vs/platform/sharedProcess/node/sharedProcess';
@@ -47,9 +47,10 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
@IDialogMainService private readonly dialogMainService: IDialogMainService,
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService,
@IEnvironmentMainService private readonly environmentService: IEnvironmentMainService,
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@ILogService private readonly logService: ILogService
@ILogService private readonly logService: ILogService,
@IProductService private readonly productService: IProductService
) {
super();
@@ -74,16 +75,17 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Events
readonly onDidOpenWindow = Event.map(this.windowsMainService.onWindowOpened, window => window.id);
readonly onDidOpenWindow = Event.map(this.windowsMainService.onDidOpenWindow, window => window.id);
readonly onDidMaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-maximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onDidUnmaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-unmaximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onDidBlurWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-blur', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
readonly onDidFocusWindow = Event.any(
Event.map(Event.filter(Event.map(this.windowsMainService.onWindowsCountChanged, () => this.windowsMainService.getLastActiveWindow()), window => !!window), window => window!.id),
Event.map(Event.filter(Event.map(this.windowsMainService.onDidChangeWindowsCount, () => this.windowsMainService.getLastActiveWindow()), window => !!window), window => window!.id),
Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-focus', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId))
);
@@ -95,8 +97,20 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
private readonly _onDidChangePassword = this._register(new Emitter<{ account: string, service: string }>());
readonly onDidChangePassword = this._onDidChangePassword.event;
readonly onDidChangeDisplay = Event.debounce(Event.any(
Event.filter(Event.fromNodeEventEmitter(screen, 'display-metrics-changed', (event: Electron.Event, display: Display, changedMetrics?: string[]) => changedMetrics), changedMetrics => {
// Electron will emit 'display-metrics-changed' events even when actually
// going fullscreen, because the dock hides. However, we do not want to
// react on this event as there is no change in display bounds.
return !(Array.isArray(changedMetrics) && changedMetrics.length === 1 && changedMetrics[0] === 'workArea');
}),
Event.fromNodeEventEmitter(screen, 'display-added'),
Event.fromNodeEventEmitter(screen, 'display-removed')
), () => { }, 100);
//#endregion
//#region Window
async getWindows(): Promise<IOpenedWindow[]> {
@@ -105,7 +119,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
return windows.map(window => ({
id: window.id,
workspace: window.openedWorkspace,
title: window.win.getTitle(),
title: window.win?.getTitle() ?? '',
filename: window.getRepresentedFilename(),
dirty: window.isDocumentEdited()
}));
@@ -140,7 +154,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
context: OpenContext.API,
contextWindowId: windowId,
urisToOpen: toOpen,
cli: this.environmentService.args,
cli: this.environmentMainService.args,
forceNewWindow: options.forceNewWindow,
forceReuseWindow: options.forceReuseWindow,
preferNewWindow: options.preferNewWindow,
@@ -148,7 +162,8 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
addMode: options.addMode,
gotoLineMode: options.gotoLineMode,
noRecentEntry: options.noRecentEntry,
waitMarkerFileURI: options.waitMarkerFileURI
waitMarkerFileURI: options.waitMarkerFileURI,
remoteAuthority: options.remoteAuthority || undefined
});
}
}
@@ -176,7 +191,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
async isMaximized(windowId: number | undefined): Promise<boolean> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
return window.win.isMaximized();
}
@@ -185,21 +200,21 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
async maximizeWindow(windowId: number | undefined): Promise<void> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
window.win.maximize();
}
}
async unmaximizeWindow(windowId: number | undefined): Promise<void> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
window.win.unmaximize();
}
}
async minimizeWindow(windowId: number | undefined): Promise<void> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
window.win.minimize();
}
}
@@ -217,7 +232,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
async setMinimumSize(windowId: number | undefined, width: number | undefined, height: number | undefined): Promise<void> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
const [windowWidth, windowHeight] = window.win.getSize();
const [minWindowWidth, minWindowHeight] = window.win.getMinimumSize();
const [newMinWindowWidth, newMinWindowHeight] = [width ?? minWindowWidth, height ?? minWindowHeight];
@@ -234,6 +249,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Dialog
async showMessageBox(windowId: number | undefined, options: MessageBoxOptions): Promise<MessageBoxReturnValue> {
@@ -250,7 +266,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
private toBrowserWindow(windowId: number | undefined): BrowserWindow | undefined {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
return window.win;
}
@@ -293,9 +309,10 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
this.windowsMainService.open({
context: OpenContext.DIALOG,
contextWindowId: windowId,
cli: this.environmentService.args,
cli: this.environmentMainService.args,
urisToOpen: openable,
forceNewWindow: options.forceNewWindow
forceNewWindow: options.forceNewWindow,
/* remoteAuthority will be determined based on openable */
});
}
@@ -313,6 +330,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region OS
async showItemInFolder(windowId: number | undefined, path: string): Promise<void> {
@@ -373,23 +391,23 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
return isAdmin;
}
async writeElevated(windowId: number | undefined, source: URI, target: URI, options?: { overwriteReadonly?: boolean }): Promise<void> {
async writeElevated(windowId: number | undefined, source: URI, target: URI, options?: { unlock?: boolean }): Promise<void> {
const sudoPrompt = await import('sudo-prompt');
return new Promise<void>((resolve, reject) => {
const sudoCommand: string[] = [`"${this.cliPath}"`];
if (options?.overwriteReadonly) {
if (options?.unlock) {
sudoCommand.push('--file-chmod');
}
sudoCommand.push('--file-write', `"${source.fsPath}"`, `"${target.fsPath}"`);
const promptOptions = {
name: product.nameLong.replace('-', ''),
icns: (isMacintosh && this.environmentService.isBuilt) ? join(dirname(this.environmentService.appRoot), `${product.nameShort}.icns`) : undefined
name: this.productService.nameLong.replace('-', ''),
icns: (isMacintosh && this.environmentMainService.isBuilt) ? join(dirname(this.environmentMainService.appRoot), `${this.productService.nameShort}.icns`) : undefined
};
sudoPrompt.exec(sudoCommand.join(' '), promptOptions, (error: string, stdout: string, stderr: string) => {
sudoPrompt.exec(sudoCommand.join(' '), promptOptions, (error?, stdout?, stderr?) => {
if (stdout) {
this.logService.trace(`[sudo-prompt] received stdout: ${stdout}`);
}
@@ -412,28 +430,28 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
// Windows
if (isWindows) {
if (this.environmentService.isBuilt) {
return join(dirname(process.execPath), 'bin', `${product.applicationName}.cmd`);
if (this.environmentMainService.isBuilt) {
return join(dirname(process.execPath), 'bin', `${this.productService.applicationName}.cmd`);
}
return join(this.environmentService.appRoot, 'scripts', 'code-cli.bat');
return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.bat');
}
// Linux
if (isLinux) {
if (this.environmentService.isBuilt) {
return join(dirname(process.execPath), 'bin', `${product.applicationName}`);
if (this.environmentMainService.isBuilt) {
return join(dirname(process.execPath), 'bin', `${this.productService.applicationName}`);
}
return join(this.environmentService.appRoot, 'scripts', 'code-cli.sh');
return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.sh');
}
// macOS
if (this.environmentService.isBuilt) {
return join(this.environmentService.appRoot, 'bin', 'code');
if (this.environmentMainService.isBuilt) {
return join(this.environmentMainService.appRoot, 'bin', 'code');
}
return join(this.environmentService.appRoot, 'scripts', 'code-cli.sh');
return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.sh');
}
async getOSStatistics(): Promise<IOSStatistics> {
@@ -507,10 +525,11 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region macOS Touchbar
async newWindowTab(): Promise<void> {
this.windowsMainService.open({ context: OpenContext.API, cli: this.environmentService.args, forceNewTabbedWindow: true, forceEmpty: true });
this.windowsMainService.open({ context: OpenContext.API, cli: this.environmentMainService.args, forceNewTabbedWindow: true, forceEmpty: true, remoteAuthority: this.environmentMainService.args.remote || undefined });
}
async showPreviousWindowTab(): Promise<void> {
@@ -542,6 +561,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Lifecycle
async notifyReady(windowId: number | undefined): Promise<void> {
@@ -568,7 +588,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
async closeWindowById(currentWindowId: number | undefined, targetWindowId?: number | undefined): Promise<void> {
const window = this.windowById(targetWindowId);
if (window) {
if (window?.win) {
return window.win.close();
}
}
@@ -578,7 +598,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
// If the user selected to exit from an extension development host window, do not quit, but just
// close the window unless this is the last window that is opened.
const window = this.windowsMainService.getLastActiveWindow();
if (window?.isExtensionDevelopmentHost && this.windowsMainService.getWindowCount() > 1) {
if (window?.isExtensionDevelopmentHost && this.windowsMainService.getWindowCount() > 1 && window.win) {
window.win.close();
}
@@ -596,6 +616,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Connectivity
async resolveProxy(windowId: number | undefined, url: string): Promise<string | undefined> {
@@ -610,18 +631,19 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Development
async openDevTools(windowId: number | undefined, options?: OpenDevToolsOptions): Promise<void> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
window.win.webContents.openDevTools(options);
}
}
async toggleDevTools(windowId: number | undefined): Promise<void> {
const window = this.windowById(windowId);
if (window) {
if (window?.win) {
const contents = window.win.webContents;
contents.toggleDevTools();
}
@@ -629,7 +651,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
async sendInputEvent(windowId: number | undefined, event: MouseInputEvent): Promise<void> {
const window = this.windowById(windowId);
if (window && (event.type === 'mouseDown' || event.type === 'mouseUp')) {
if (window?.win && (event.type === 'mouseDown' || event.type === 'mouseUp')) {
window.win.webContents.sendInputEvent(event);
}
}
@@ -640,6 +662,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Registry (windows)
async windowsGetStringRegKey(windowId: number | undefined, hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise<string | undefined> {
@@ -657,13 +680,14 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
//#endregion
//#region Credentials
private static readonly MAX_PASSWORD_LENGTH = 2500;
private static readonly PASSWORD_CHUNK_SIZE = NativeHostMainService.MAX_PASSWORD_LENGTH - 100;
async getPassword(windowId: number | undefined, service: string, account: string): Promise<string | null> {
const keytar = await import('keytar');
const keytar = await this.withKeytar();
const password = await keytar.getPassword(service, account);
if (password) {
@@ -691,7 +715,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
}
async setPassword(windowId: number | undefined, service: string, account: string, password: string): Promise<void> {
const keytar = await import('keytar');
const keytar = await this.withKeytar();
if (isWindows && password.length > NativeHostMainService.MAX_PASSWORD_LENGTH) {
let index = 0;
@@ -719,7 +743,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
}
async deletePassword(windowId: number | undefined, service: string, account: string): Promise<boolean> {
const keytar = await import('keytar');
const keytar = await this.withKeytar();
const didDelete = await keytar.deletePassword(service, account);
if (didDelete) {
@@ -730,17 +754,25 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
}
async findPassword(windowId: number | undefined, service: string): Promise<string | null> {
const keytar = await import('keytar');
const keytar = await this.withKeytar();
return keytar.findPassword(service);
}
async findCredentials(windowId: number | undefined, service: string): Promise<Array<{ account: string, password: string }>> {
const keytar = await import('keytar');
const keytar = await this.withKeytar();
return keytar.findCredentials(service);
}
private async withKeytar(): Promise<typeof import('keytar')> {
if (this.environmentMainService.disableKeytar) {
throw new Error('keytar has been disabled via --disable-keytar option');
}
return await import('keytar');
}
//#endregion
private windowById(windowId: number | undefined): ICodeWindow | undefined {

View File

@@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService';
import { createChannelSender } from 'vs/base/parts/ipc/common/ipc';
import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services';
import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc';
// @ts-ignore: interface is implemented via proxy
export class NativeHostService implements INativeHostService {
@@ -16,7 +16,7 @@ export class NativeHostService implements INativeHostService {
readonly windowId: number,
@IMainProcessService mainProcessService: IMainProcessService
) {
return createChannelSender<INativeHostService>(mainProcessService.getChannel('nativeHost'), {
return ProxyChannel.toService<INativeHostService>(mainProcessService.getChannel('nativeHost'), {
context: windowId,
properties: (() => {
const properties = new Map<string, unknown>();