Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/environment/electron-main/environmentMainService.ts
5255 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { memoize } from '../../../base/common/decorators.js';
7
import { join } from '../../../base/common/path.js';
8
import { isLinux } from '../../../base/common/platform.js';
9
import { createStaticIPCHandle } from '../../../base/parts/ipc/node/ipc.net.js';
10
import { IEnvironmentService, INativeEnvironmentService } from '../common/environment.js';
11
import { NativeEnvironmentService } from '../node/environmentService.js';
12
import { refineServiceDecorator } from '../../instantiation/common/instantiation.js';
13
14
export const IEnvironmentMainService = refineServiceDecorator<IEnvironmentService, IEnvironmentMainService>(IEnvironmentService);
15
16
/**
17
* A subclass of the `INativeEnvironmentService` to be used only in electron-main
18
* environments.
19
*/
20
export interface IEnvironmentMainService extends INativeEnvironmentService {
21
22
// --- backup paths
23
readonly backupHome: string;
24
25
// --- V8 code caching
26
readonly codeCachePath: string | undefined;
27
readonly useCodeCache: boolean;
28
29
// --- IPC
30
readonly mainIPCHandle: string;
31
readonly mainLockfile: string;
32
33
// --- config
34
readonly disableUpdates: boolean;
35
readonly isPortable: boolean;
36
37
// TODO@deepak1556 temporary until a real fix lands upstream
38
readonly enableRDPDisplayTracking: boolean;
39
40
unsetSnapExportedVariables(): void;
41
restoreSnapExportedVariables(): void;
42
}
43
44
export class EnvironmentMainService extends NativeEnvironmentService implements IEnvironmentMainService {
45
46
private _snapEnv: Record<string, string> = {};
47
48
@memoize
49
get backupHome(): string { return join(this.userDataPath, 'Backups'); }
50
51
@memoize
52
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }
53
54
@memoize
55
get mainLockfile(): string { return join(this.userDataPath, 'code.lock'); }
56
57
@memoize
58
get disableUpdates(): boolean { return !!this.args['disable-updates']; }
59
60
@memoize
61
get isPortable(): boolean { return !!process.env['VSCODE_PORTABLE']; }
62
63
@memoize
64
get crossOriginIsolated(): boolean { return !!this.args['enable-coi']; }
65
66
@memoize
67
get enableRDPDisplayTracking(): boolean { return !!this.args['enable-rdp-display-tracking']; }
68
69
@memoize
70
get codeCachePath(): string | undefined { return process.env['VSCODE_CODE_CACHE_PATH'] || undefined; }
71
72
@memoize
73
get useCodeCache(): boolean { return !!this.codeCachePath; }
74
75
unsetSnapExportedVariables() {
76
if (!isLinux) {
77
return;
78
}
79
for (const key in process.env) {
80
if (key.endsWith('_VSCODE_SNAP_ORIG')) {
81
const originalKey = key.slice(0, -17); // Remove the _VSCODE_SNAP_ORIG suffix
82
if (this._snapEnv[originalKey]) {
83
continue;
84
}
85
// Preserve the original value in case the snap env is re-entered
86
if (process.env[originalKey]) {
87
this._snapEnv[originalKey] = process.env[originalKey]!;
88
}
89
// Copy the original value from before entering the snap env if available,
90
// if not delete the env variable.
91
if (process.env[key]) {
92
process.env[originalKey] = process.env[key];
93
} else {
94
delete process.env[originalKey];
95
}
96
}
97
}
98
}
99
100
restoreSnapExportedVariables() {
101
if (!isLinux) {
102
return;
103
}
104
for (const key in this._snapEnv) {
105
process.env[key] = this._snapEnv[key];
106
delete this._snapEnv[key];
107
}
108
}
109
}
110
111