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
3296 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
36
// TODO@deepak1556 TODO@bpasero temporary until a real fix lands upstream
37
readonly enableRDPDisplayTracking: boolean;
38
39
unsetSnapExportedVariables(): void;
40
restoreSnapExportedVariables(): void;
41
}
42
43
export class EnvironmentMainService extends NativeEnvironmentService implements IEnvironmentMainService {
44
45
private _snapEnv: Record<string, string> = {};
46
47
@memoize
48
get backupHome(): string { return join(this.userDataPath, 'Backups'); }
49
50
@memoize
51
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }
52
53
@memoize
54
get mainLockfile(): string { return join(this.userDataPath, 'code.lock'); }
55
56
@memoize
57
get disableUpdates(): boolean { return !!this.args['disable-updates']; }
58
59
@memoize
60
get crossOriginIsolated(): boolean { return !!this.args['enable-coi']; }
61
62
@memoize
63
get enableRDPDisplayTracking(): boolean { return !!this.args['enable-rdp-display-tracking']; }
64
65
@memoize
66
get codeCachePath(): string | undefined { return process.env['VSCODE_CODE_CACHE_PATH'] || undefined; }
67
68
@memoize
69
get useCodeCache(): boolean { return !!this.codeCachePath; }
70
71
unsetSnapExportedVariables() {
72
if (!isLinux) {
73
return;
74
}
75
for (const key in process.env) {
76
if (key.endsWith('_VSCODE_SNAP_ORIG')) {
77
const originalKey = key.slice(0, -17); // Remove the _VSCODE_SNAP_ORIG suffix
78
if (this._snapEnv[originalKey]) {
79
continue;
80
}
81
// Preserve the original value in case the snap env is re-entered
82
if (process.env[originalKey]) {
83
this._snapEnv[originalKey] = process.env[originalKey]!;
84
}
85
// Copy the original value from before entering the snap env if available,
86
// if not delete the env variable.
87
if (process.env[key]) {
88
process.env[originalKey] = process.env[key];
89
} else {
90
delete process.env[originalKey];
91
}
92
}
93
}
94
}
95
96
restoreSnapExportedVariables() {
97
if (!isLinux) {
98
return;
99
}
100
for (const key in this._snapEnv) {
101
process.env[key] = this._snapEnv[key];
102
delete this._snapEnv[key];
103
}
104
}
105
}
106
107