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

6
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
7
import { INativeWorkbenchConfiguration, INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
8 9 10
import { memoize } from 'vs/base/common/decorators';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
11
import { dirname, join } from 'vs/base/common/path';
12
import { IProductService } from 'vs/platform/product/common/productService';
13
import { isLinux, isWindows } from 'vs/base/common/platform';
14

15
export class NativeWorkbenchEnvironmentService extends EnvironmentService implements INativeWorkbenchEnvironmentService {
16

17
	declare readonly _serviceBrand: undefined;
18

19
	@memoize
20 21
	get webviewExternalEndpoint(): string {
		const baseEndpoint = 'https://{{uuid}}.vscode-webview-test.com/{{commit}}';
22

23
		return baseEndpoint.replace('{{commit}}', this.productService.commit || '0d728c31ebdf03869d2687d9be0b017667c9ff37');
24 25
	}

26
	@memoize
27
	get webviewResourceRoot(): string { return `${Schemas.vscodeWebviewResource}://{{uuid}}/{{resource}}`; }
B
Benjamin Pasero 已提交
28

29
	@memoize
30
	get webviewCspSource(): string { return `${Schemas.vscodeWebviewResource}:`; }
31

32
	@memoize
33
	get userRoamingDataHome(): URI { return this.appSettingsHome.with({ scheme: Schemas.userData }); }
34

S
Sandeep Somavarapu 已提交
35 36 37
	// Do not memoize as `backupPath` can change in configuration
	get backupWorkspaceHome(): URI | undefined { return this.configuration.backupPath ? URI.file(this.configuration.backupPath).with({ scheme: this.userRoamingDataHome.scheme }) : undefined; }

38
	@memoize
39 40 41 42
	get logFile(): URI { return URI.file(join(this.logsPath, `renderer${this.configuration.windowId}.log`)); }

	@memoize
	get extHostLogsPath(): URI { return URI.file(join(this.logsPath, `exthost${this.configuration.windowId}`)); }
43

44 45 46
	@memoize
	get skipReleaseNotes(): boolean { return !!this.args['skip-release-notes']; }

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
	@memoize
	get logExtensionHostCommunication(): boolean { return !!this.args.logExtensionHostCommunication; }

	get extensionEnabledProposedApi(): string[] | undefined {
		if (Array.isArray(this.args['enable-proposed-api'])) {
			return this.args['enable-proposed-api'];
		}

		if ('enable-proposed-api' in this.args) {
			return [];
		}

		return undefined;
	}

	@memoize
	get cliPath(): string { return this.doGetCLIPath(); }

65 66
	readonly execPath = this.configuration.execPath;

67
	constructor(
68 69
		readonly configuration: INativeWorkbenchConfiguration,
		private readonly productService: IProductService
70
	) {
71
		super(configuration);
72
	}
73 74 75 76 77 78

	private doGetCLIPath(): string {

		// Windows
		if (isWindows) {
			if (this.isBuilt) {
79
				return join(dirname(this.execPath), 'bin', `${this.productService.applicationName}.cmd`);
80 81 82 83 84 85 86 87
			}

			return join(this.appRoot, 'scripts', 'code-cli.bat');
		}

		// Linux
		if (isLinux) {
			if (this.isBuilt) {
88
				return join(dirname(this.execPath), 'bin', `${this.productService.applicationName}`);
89 90 91 92 93 94 95 96 97 98 99 100
			}

			return join(this.appRoot, 'scripts', 'code-cli.sh');
		}

		// macOS
		if (this.isBuilt) {
			return join(this.appRoot, 'bin', 'code');
		}

		return join(this.appRoot, 'scripts', 'code-cli.sh');
	}
101
}