Skip to content

Commit 34986b2

Browse files
authored
Merge pull request microsoft#205536 from microsoft/benibenj/brief-egret
Report client OS / Desktop Environment
2 parents 43d55cb + 8ec6cec commit 34986b2

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 { env } from 'vs/base/common/process';
7+
8+
// Define the enumeration for Desktop Environments
9+
enum DesktopEnvironment {
10+
UNKNOWN = 'UNKNOWN',
11+
CINNAMON = 'CINNAMON',
12+
DEEPIN = 'DEEPIN',
13+
GNOME = 'GNOME',
14+
KDE3 = 'KDE3',
15+
KDE4 = 'KDE4',
16+
KDE5 = 'KDE5',
17+
KDE6 = 'KDE6',
18+
PANTHEON = 'PANTHEON',
19+
UNITY = 'UNITY',
20+
XFCE = 'XFCE',
21+
UKUI = 'UKUI',
22+
LXQT = 'LXQT',
23+
}
24+
25+
const kXdgCurrentDesktopEnvVar = 'XDG_CURRENT_DESKTOP';
26+
const kKDESessionEnvVar = 'KDE_SESSION_VERSION';
27+
28+
export function getDesktopEnvironment(): DesktopEnvironment {
29+
const xdgCurrentDesktop = env[kXdgCurrentDesktopEnvVar];
30+
if (xdgCurrentDesktop) {
31+
const values = xdgCurrentDesktop.split(':').map(value => value.trim()).filter(value => value.length > 0);
32+
for (const value of values) {
33+
switch (value) {
34+
case 'Unity': {
35+
const desktopSessionUnity = env['DESKTOP_SESSION'];
36+
if (desktopSessionUnity && desktopSessionUnity.includes('gnome-fallback')) {
37+
return DesktopEnvironment.GNOME;
38+
}
39+
40+
return DesktopEnvironment.UNITY;
41+
}
42+
case 'Deepin':
43+
return DesktopEnvironment.DEEPIN;
44+
case 'GNOME':
45+
return DesktopEnvironment.GNOME;
46+
case 'X-Cinnamon':
47+
return DesktopEnvironment.CINNAMON;
48+
case 'KDE': {
49+
const kdeSession = env[kKDESessionEnvVar];
50+
if (kdeSession === '5') { return DesktopEnvironment.KDE5; }
51+
if (kdeSession === '6') { return DesktopEnvironment.KDE6; }
52+
return DesktopEnvironment.KDE4;
53+
}
54+
case 'Pantheon':
55+
return DesktopEnvironment.PANTHEON;
56+
case 'XFCE':
57+
return DesktopEnvironment.XFCE;
58+
case 'UKUI':
59+
return DesktopEnvironment.UKUI;
60+
case 'LXQt':
61+
return DesktopEnvironment.LXQT;
62+
}
63+
}
64+
}
65+
66+
const desktopSession = env['DESKTOP_SESSION'];
67+
if (desktopSession) {
68+
switch (desktopSession) {
69+
case 'deepin':
70+
return DesktopEnvironment.DEEPIN;
71+
case 'gnome':
72+
case 'mate':
73+
return DesktopEnvironment.GNOME;
74+
case 'kde4':
75+
case 'kde-plasma':
76+
return DesktopEnvironment.KDE4;
77+
case 'kde':
78+
if (kKDESessionEnvVar in env) {
79+
return DesktopEnvironment.KDE4;
80+
}
81+
return DesktopEnvironment.KDE3;
82+
case 'xfce':
83+
case 'xubuntu':
84+
return DesktopEnvironment.XFCE;
85+
case 'ukui':
86+
return DesktopEnvironment.UKUI;
87+
}
88+
}
89+
90+
if ('GNOME_DESKTOP_SESSION_ID' in env) {
91+
return DesktopEnvironment.GNOME;
92+
}
93+
if ('KDE_FULL_SESSION' in env) {
94+
if (kKDESessionEnvVar in env) {
95+
return DesktopEnvironment.KDE4;
96+
}
97+
return DesktopEnvironment.KDE3;
98+
}
99+
100+
return DesktopEnvironment.UNKNOWN;
101+
}

src/vs/code/node/sharedProcess/sharedProcessMain.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ import { RemoteConnectionType } from 'vs/platform/remote/common/remoteAuthorityR
116116
import { nodeSocketFactory } from 'vs/platform/remote/node/nodeSocketFactory';
117117
import { NativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
118118
import { SharedProcessRawConnection, SharedProcessLifecycle } from 'vs/platform/sharedProcess/common/sharedProcess';
119+
import { getOSReleaseInfo } from 'vs/base/node/osReleaseInfo';
120+
import { getDesktopEnvironment } from 'vs/base/common/desktopEnvironmentInfo';
119121

120122
class SharedProcessMain extends Disposable implements IClientConnectionFilter {
121123

@@ -172,6 +174,9 @@ class SharedProcessMain extends Disposable implements IClientConnectionFilter {
172174
// Report Profiles Info
173175
this.reportProfilesInfo(telemetryService, userDataProfilesService);
174176
this._register(userDataProfilesService.onDidChangeProfiles(() => this.reportProfilesInfo(telemetryService, userDataProfilesService)));
177+
178+
// Report Client OS/DE Info
179+
this.reportClientOSInfo(telemetryService, logService);
175180
});
176181

177182
// Instantiate Contributions
@@ -458,6 +463,35 @@ class SharedProcessMain extends Disposable implements IClientConnectionFilter {
458463
});
459464
}
460465

466+
private async reportClientOSInfo(telemetryService: ITelemetryService, logService: ILogService): Promise<void> {
467+
if (isLinux) {
468+
const releaseInfo = await getOSReleaseInfo(logService.error.bind(logService));
469+
const desktopEnvironment = getDesktopEnvironment();
470+
if (releaseInfo) {
471+
type ClientPlatformInfoClassification = {
472+
platformId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the operating system without any version information.' };
473+
platformVersionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the operating system version excluding any name information or release code.' };
474+
platformIdLike: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the operating system the current OS derivate is closely related to.' };
475+
desktopEnvironment: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'A string identifying the desktop environment the user is using.' };
476+
owner: 'benibenj';
477+
comment: 'Provides insight into the distro and desktop environment information on Linux.';
478+
};
479+
type ClientPlatformInfoEvent = {
480+
platformId: string;
481+
platformVersionId: string | undefined;
482+
platformIdLike: string | undefined;
483+
desktopEnvironment: string | undefined;
484+
};
485+
telemetryService.publicLog2<ClientPlatformInfoEvent, ClientPlatformInfoClassification>('clientPlatformInfo', {
486+
platformId: releaseInfo.id,
487+
platformVersionId: releaseInfo.version_id,
488+
platformIdLike: releaseInfo.id_like,
489+
desktopEnvironment: desktopEnvironment
490+
});
491+
}
492+
}
493+
}
494+
461495
handledClientConnection(e: MessageEvent): boolean {
462496

463497
// This filter on message port messages will look for

0 commit comments

Comments
 (0)