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';
7
import { 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
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api';
18
import { generateUuid } from 'vs/base/common/uuid';
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

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 已提交
38
	backupWorkspaceResource?: URI;
39 40 41 42

	workspace?: IWorkspaceIdentifier;
	folderUri?: ISingleFolderWorkspaceIdentifier;

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

	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;
}

65
interface IBrowserWorkbenchEnvironemntConstructionOptions extends IWorkbenchConstructionOptions {
S
Sandeep Somavarapu 已提交
66
	workspaceId: string;
67
	logsPath: URI;
S
Sandeep Somavarapu 已提交
68 69
}

70
export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironmentService {
71

72
	_serviceBrand!: ServiceIdentifier<IWorkbenchEnvironmentService>;
73 74 75

	readonly configuration: IWindowConfiguration = new BrowserWindowConfiguration();

76
	constructor(readonly options: IBrowserWorkbenchEnvironemntConstructionOptions) {
77
		this.args = { _: [] };
78
		this.logsPath = options.logsPath.path;
S
Sandeep Somavarapu 已提交
79
		this.logFile = joinPath(options.logsPath, 'window.log');
80 81 82
		this.appRoot = '/web/';
		this.appNameLong = 'Visual Studio Code - Web';

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

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

99
		this.untitledWorkspacesHome = URI.from({ scheme: Schemas.untitled, path: 'Workspaces' });
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
	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;
	mainIPCHandle: string;
	sharedIPCHandle: string;
	nodeCachedDataDir?: string;
	installSourcePath: string;
	disableUpdates: boolean;
	disableCrashReporter: boolean;
	driverHandle?: string;
	driverVerbose: boolean;
179
	galleryMachineIdResource?: URI;
180
	readonly logFile: URI;
181 182

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

186
	get webviewCspSource(): string {
187
		return this.options.webviewEndpoint ? this.options.webviewEndpoint : 'vscode-resource:';
M
Matt Bierner 已提交
188
	}
189
}
S
Sandeep Somavarapu 已提交
190

191 192 193 194 195 196
/**
 * See https://stackoverflow.com/a/25490531
 */
function getCookieValue(name: string): string | undefined {
	const m = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)');
	return m ? m.pop() : undefined;
197
}