workbenchCommonProperties.ts 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as os from 'os';
import { TPromise } from 'vs/base/common/winjs.base';
import * as uuid from 'vs/base/common/uuid';
import { IStorageService } from 'vs/platform/storage/common/storage';
10
import { resolveCommonProperties } from '../node/commonProperties';
11

12 13
export function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string, version: string, machineId: string, installSourcePath: string): TPromise<{ [name: string]: string }> {
	return resolveCommonProperties(commit, version, machineId, installSourcePath).then(result => {
14
		// __GDPR__COMMON__ "common.version.shell" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
15
		result['common.version.shell'] = process.versions && (<any>process).versions['electron'];
16
		// __GDPR__COMMON__ "common.version.renderer" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
17
		result['common.version.renderer'] = process.versions && (<any>process).versions['chrome'];
18
		// __GDPR__COMMON__ "common.osVersion" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
19 20 21 22 23 24 25
		result['common.osVersion'] = os.release();

		const lastSessionDate = storageService.get('telemetry.lastSessionDate');
		const firstSessionDate = storageService.get('telemetry.firstSessionDate') || new Date().toUTCString();
		storageService.store('telemetry.firstSessionDate', firstSessionDate);
		storageService.store('telemetry.lastSessionDate', new Date().toUTCString());

26
		// __GDPR__COMMON__ "common.firstSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
27
		result['common.firstSessionDate'] = firstSessionDate;
28
		// __GDPR__COMMON__ "common.lastSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
29
		result['common.lastSessionDate'] = lastSessionDate;
30
		// __GDPR__COMMON__ "common.isNewSession" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
31
		result['common.isNewSession'] = !lastSessionDate ? '1' : '0';
32
		// __GDPR__COMMON__ "common.instanceId" : { "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight" }
33
		result['common.instanceId'] = getOrCreateInstanceId(storageService);
34

35
		return result;
36 37 38
	});
}

39 40
function getOrCreateInstanceId(storageService: IStorageService): string {
	const result = storageService.get('telemetry.instanceId') || uuid.generateUuid();
41 42
	storageService.store('telemetry.instanceId', result);

43 44
	return result;
}