environmentService.ts 6.3 KB
Newer Older
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IWindowConfiguration, IPath, IPathsToWaitFor } from 'vs/platform/windows/common/windows';
S
Sandeep Somavarapu 已提交
7
import { IEnvironmentService, IExtensionHostDebugParams, IDebugParams, BACKUPS } from 'vs/platform/environment/common/environment';
8 9 10 11 12 13 14
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { URI } from 'vs/base/common/uri';
import { IProcessEnvironment } from 'vs/base/common/platform';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { ExportData } from 'vs/base/common/performance';
import { LogLevel } from 'vs/platform/log/common/log';
import { joinPath } from 'vs/base/common/resources';
15
import { Schemas } from 'vs/base/common/network';
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

export class BrowserWindowConfiguration implements IWindowConfiguration {

	_: any[];

	machineId: string;
	windowId: number;
	logLevel: LogLevel;

	mainPid: number;

	appRoot: string;
	execPath: string;
	isInitialStartup?: boolean;

	userEnv: IProcessEnvironment;
	nodeCachedDataDir?: string;

	backupPath?: string;
B
Benjamin Pasero 已提交
35
	backupWorkspaceResource?: URI;
36 37 38 39

	workspace?: IWorkspaceIdentifier;
	folderUri?: ISingleFolderWorkspaceIdentifier;

B
Benjamin Pasero 已提交
40 41
	remoteAuthority?: string;
	connectionToken?: string;
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

	zoomLevel?: number;
	fullscreen?: boolean;
	maximized?: boolean;
	highContrast?: boolean;
	frameless?: boolean;
	accessibilitySupport?: boolean;
	partsSplashPath?: string;

	perfStartTime?: number;
	perfAppReady?: number;
	perfWindowLoadTime?: number;
	perfEntries: ExportData;

	filesToOpenOrCreate?: IPath[];
	filesToDiff?: IPath[];
	filesToWait?: IPathsToWaitFor;
	termProgram?: string;
}

S
Sandeep Somavarapu 已提交
62 63 64 65
export interface IBrowserWindowConfiguration {
	workspaceId: string;
	remoteAuthority?: string;
	webviewEndpoint?: string;
S
Sandeep Somavarapu 已提交
66
	connectionToken?: string;
S
Sandeep Somavarapu 已提交
67 68
}

69
export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
70 71

	_serviceBrand!: ServiceIdentifier<IEnvironmentService>;
72 73 74

	readonly configuration: IWindowConfiguration = new BrowserWindowConfiguration();

S
Sandeep Somavarapu 已提交
75
	constructor(configuration: IBrowserWindowConfiguration) {
76 77 78 79 80
		this.args = { _: [] };
		this.appRoot = '/web/';
		this.appNameLong = 'Visual Studio Code - Web';

		this.configuration.remoteAuthority = configuration.remoteAuthority;
S
Sandeep Somavarapu 已提交
81
		this.userRoamingDataHome = URI.file('/User').with({ scheme: Schemas.userData });
82 83 84
		this.settingsResource = joinPath(this.userRoamingDataHome, 'settings.json');
		this.keybindingsResource = joinPath(this.userRoamingDataHome, 'keybindings.json');
		this.keyboardLayoutResource = joinPath(this.userRoamingDataHome, 'keyboardLayout.json');
85
		this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
S
Sandeep Somavarapu 已提交
86 87
		this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
		this.configuration.backupWorkspaceResource = joinPath(this.backupHome, configuration.workspaceId);
S
Sandeep Somavarapu 已提交
88
		this.configuration.connectionToken = configuration.connectionToken || this.getConnectionTokenFromLocation();
89 90 91 92 93 94 95 96 97

		this.logsPath = '/web/logs';

		this.debugExtensionHost = {
			port: null,
			break: false
		};

		this.webviewEndpoint = configuration.webviewEndpoint;
98
		this.untitledWorkspacesHome = URI.from({ scheme: Schemas.untitled, path: 'Workspaces' });
99 100 101 102 103 104 105 106 107

		if (document && document.location && document.location.search) {

			const map = new Map<string, string>();
			const query = document.location.search.substring(1);
			const vars = query.split('&');
			for (let p of vars) {
				const pair = p.split('=');
				if (pair.length >= 2) {
108
					map.set(pair[0], decodeURIComponent(pair[1]));
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
				}
			}

			const edp = map.get('edp');
			if (edp) {
				this.extensionDevelopmentLocationURI = [URI.parse(edp)];
				this.isExtensionDevelopment = true;
			}

			const di = map.get('di');
			if (di) {
				this.debugExtensionHost.debugId = di;
			}

			const ibe = map.get('ibe');
			if (ibe) {
				this.debugExtensionHost.port = parseInt(ibe);
				this.debugExtensionHost.break = false;
			}
		}
129 130 131 132 133 134 135 136 137 138 139 140 141
	}

	untitledWorkspacesHome: URI;
	extensionTestsLocationURI?: URI;
	args: any;
	execPath: string;
	cliPath: string;
	appRoot: string;
	userHome: string;
	userDataPath: string;
	appNameLong: string;
	appQuality?: string;
	appSettingsHome: URI;
142
	userRoamingDataHome: URI;
S
Sandeep Somavarapu 已提交
143 144
	settingsResource: URI;
	keybindingsResource: URI;
P
Peng Lyu 已提交
145
	keyboardLayoutResource: URI;
146
	localeResource: URI;
147 148 149 150
	machineSettingsHome: URI;
	machineSettingsResource: URI;
	globalStorageHome: string;
	workspaceStorageHome: string;
S
Sandeep Somavarapu 已提交
151
	backupHome: URI;
152 153 154 155 156
	backupWorkspacesPath: string;
	workspacesHome: string;
	isExtensionDevelopment: boolean;
	disableExtensions: boolean | string[];
	builtinExtensionsPath: string;
157
	extensionsPath?: string;
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
	extensionDevelopmentLocationURI?: URI[];
	extensionTestsPath?: string;
	debugExtensionHost: IExtensionHostDebugParams;
	debugSearch: IDebugParams;
	logExtensionHostCommunication: boolean;
	isBuilt: boolean;
	wait: boolean;
	status: boolean;
	log?: string;
	logsPath: string;
	verbose: boolean;
	skipGettingStarted: boolean;
	skipReleaseNotes: boolean;
	skipAddToRecentlyOpened: boolean;
	mainIPCHandle: string;
	sharedIPCHandle: string;
	nodeCachedDataDir?: string;
	installSourcePath: string;
	disableUpdates: boolean;
	disableCrashReporter: boolean;
	driverHandle?: string;
	driverVerbose: boolean;
	webviewEndpoint?: string;
181
	galleryMachineIdResource?: URI;
182 183

	get webviewResourceRoot(): string {
184
		return this.webviewEndpoint ? this.webviewEndpoint + '/vscode-resource{{resource}}' : 'vscode-resource:{{resource}}';
185
	}
M
Matt Bierner 已提交
186

187
	get webviewCspSource(): string {
M
Matt Bierner 已提交
188 189
		return this.webviewEndpoint ? this.webviewEndpoint : 'vscode-resource:';
	}
S
Sandeep Somavarapu 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

	private getConnectionTokenFromLocation(): string | undefined {
		// TODO: Check with @alexd where the token will be: search or hash?
		let connectionToken: string | undefined = undefined;
		if (document.location.search) {
			connectionToken = this.getConnectionToken(document.location.search);
		}
		if (!connectionToken && document.location.hash) {
			connectionToken = this.getConnectionToken(document.location.hash);
		}
		return connectionToken;
	}

	private getConnectionToken(str: string): string | undefined {
		const m = str.match(/[#&]tkn=([^&]+)/);
		return m ? m[1] : undefined;
	}
207
}