Path: blob/main/src/vs/platform/environment/electron-main/environmentMainService.ts
5255 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;34readonly isPortable: boolean;3536// TODO@deepak1556 temporary until a real fix lands upstream37readonly enableRDPDisplayTracking: boolean;3839unsetSnapExportedVariables(): void;40restoreSnapExportedVariables(): void;41}4243export class EnvironmentMainService extends NativeEnvironmentService implements IEnvironmentMainService {4445private _snapEnv: Record<string, string> = {};4647@memoize48get backupHome(): string { return join(this.userDataPath, 'Backups'); }4950@memoize51get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }5253@memoize54get mainLockfile(): string { return join(this.userDataPath, 'code.lock'); }5556@memoize57get disableUpdates(): boolean { return !!this.args['disable-updates']; }5859@memoize60get isPortable(): boolean { return !!process.env['VSCODE_PORTABLE']; }6162@memoize63get crossOriginIsolated(): boolean { return !!this.args['enable-coi']; }6465@memoize66get enableRDPDisplayTracking(): boolean { return !!this.args['enable-rdp-display-tracking']; }6768@memoize69get codeCachePath(): string | undefined { return process.env['VSCODE_CODE_CACHE_PATH'] || undefined; }7071@memoize72get useCodeCache(): boolean { return !!this.codeCachePath; }7374unsetSnapExportedVariables() {75if (!isLinux) {76return;77}78for (const key in process.env) {79if (key.endsWith('_VSCODE_SNAP_ORIG')) {80const originalKey = key.slice(0, -17); // Remove the _VSCODE_SNAP_ORIG suffix81if (this._snapEnv[originalKey]) {82continue;83}84// Preserve the original value in case the snap env is re-entered85if (process.env[originalKey]) {86this._snapEnv[originalKey] = process.env[originalKey]!;87}88// Copy the original value from before entering the snap env if available,89// if not delete the env variable.90if (process.env[key]) {91process.env[originalKey] = process.env[key];92} else {93delete process.env[originalKey];94}95}96}97}9899restoreSnapExportedVariables() {100if (!isLinux) {101return;102}103for (const key in this._snapEnv) {104process.env[key] = this._snapEnv[key];105delete this._snapEnv[key];106}107}108}109110111