Path: blob/main/src/vs/platform/environment/electron-main/environmentMainService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { memoize } from '../../../base/common/decorators.js';6import { join } from '../../../base/common/path.js';7import { isLinux } from '../../../base/common/platform.js';8import { createStaticIPCHandle } from '../../../base/parts/ipc/node/ipc.net.js';9import { IEnvironmentService, INativeEnvironmentService } from '../common/environment.js';10import { NativeEnvironmentService } from '../node/environmentService.js';11import { refineServiceDecorator } from '../../instantiation/common/instantiation.js';1213export const IEnvironmentMainService = refineServiceDecorator<IEnvironmentService, IEnvironmentMainService>(IEnvironmentService);1415/**16* A subclass of the `INativeEnvironmentService` to be used only in electron-main17* environments.18*/19export interface IEnvironmentMainService extends INativeEnvironmentService {2021// --- backup paths22readonly backupHome: string;2324// --- V8 code caching25readonly codeCachePath: string | undefined;26readonly useCodeCache: boolean;2728// --- IPC29readonly mainIPCHandle: string;30readonly mainLockfile: string;3132// --- config33readonly disableUpdates: boolean;3435// TODO@deepak1556 TODO@bpasero temporary until a real fix lands upstream36readonly enableRDPDisplayTracking: boolean;3738unsetSnapExportedVariables(): void;39restoreSnapExportedVariables(): void;40}4142export class EnvironmentMainService extends NativeEnvironmentService implements IEnvironmentMainService {4344private _snapEnv: Record<string, string> = {};4546@memoize47get backupHome(): string { return join(this.userDataPath, 'Backups'); }4849@memoize50get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }5152@memoize53get mainLockfile(): string { return join(this.userDataPath, 'code.lock'); }5455@memoize56get disableUpdates(): boolean { return !!this.args['disable-updates']; }5758@memoize59get crossOriginIsolated(): boolean { return !!this.args['enable-coi']; }6061@memoize62get enableRDPDisplayTracking(): boolean { return !!this.args['enable-rdp-display-tracking']; }6364@memoize65get codeCachePath(): string | undefined { return process.env['VSCODE_CODE_CACHE_PATH'] || undefined; }6667@memoize68get useCodeCache(): boolean { return !!this.codeCachePath; }6970unsetSnapExportedVariables() {71if (!isLinux) {72return;73}74for (const key in process.env) {75if (key.endsWith('_VSCODE_SNAP_ORIG')) {76const originalKey = key.slice(0, -17); // Remove the _VSCODE_SNAP_ORIG suffix77if (this._snapEnv[originalKey]) {78continue;79}80// Preserve the original value in case the snap env is re-entered81if (process.env[originalKey]) {82this._snapEnv[originalKey] = process.env[originalKey]!;83}84// Copy the original value from before entering the snap env if available,85// if not delete the env variable.86if (process.env[key]) {87process.env[originalKey] = process.env[key];88} else {89delete process.env[originalKey];90}91}92}93}9495restoreSnapExportedVariables() {96if (!isLinux) {97return;98}99for (const key in this._snapEnv) {100process.env[key] = this._snapEnv[key];101delete this._snapEnv[key];102}103}104}105106107