提交 a678fe0b 编写于 作者: S Sofian Hnaide

fix #2311

上级 03df65d8
......@@ -7,7 +7,7 @@ import getmac = require('getmac');
import crypto = require('crypto');
import {MainTelemetryService, TelemetryServiceConfig} from 'vs/platform/telemetry/browser/mainTelemetryService';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {ITelemetryService, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry';
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
import errors = require('vs/base/common/errors');
import uuid = require('vs/base/common/uuid');
......@@ -19,49 +19,74 @@ class StorageKeys {
export class ElectronTelemetryService extends MainTelemetryService implements ITelemetryService {
private _setupIds: Promise<ITelemetryInfo>;
constructor(@IStorageService private storageService: IStorageService, config?:TelemetryServiceConfig) {
super(config);
this.setupInstanceId();
this.setupMachineId();
this._setupIds = this.setupIds();
}
/**
* override the base getTelemetryInfo to make sure this information is not retrieved before it's ready
*/
public getTelemetryInfo(): Promise<ITelemetryInfo> {
return this._setupIds;
}
private setupInstanceId(){
private setupIds(): Promise<ITelemetryInfo> {
return Promise.all([this.setupInstanceId(), this.setupMachineId()]).then(()=> {
return {
machineId: this.machineId,
instanceId: this.instanceId,
sessionId: this.sessionId
}
});
}
private setupInstanceId(): Promise<string> {
var instanceId = this.storageService.get(StorageKeys.InstanceId);
if(!instanceId) {
instanceId = uuid.generateUuid();
this.storageService.store(StorageKeys.InstanceId, instanceId);
}
this.instanceId = instanceId;
return Promise.resolve(this.instanceId);
}
private setupMachineId(){
private setupMachineId(): Promise<string> {
var machineId = this.storageService.get(StorageKeys.MachineId);
if (machineId) {
this.machineId = machineId;
return Promise.resolve(this.machineId);
} else {
try {
// add a unique machine id as a hash of the macAddress
getmac.getMac( (error, macAddress) => {
if (!error) {
// crypt machine id
machineId = crypto.createHash('sha256').update(macAddress, 'utf8').digest('hex');
} else {
// generate a UUID
machineId = uuid.generateUuid();
}
return new Promise((resolve, reject) => {
try {
// add a unique machine id as a hash of the macAddress
getmac.getMac((error, macAddress) => {
if (!error) {
// crypt machine id
machineId = crypto.createHash('sha256').update(macAddress, 'utf8').digest('hex');
} else {
// generate a UUID
machineId = uuid.generateUuid();
}
this.machineId = machineId;
this.storageService.store(StorageKeys.MachineId, machineId);
resolve(this.machineId);
});
} catch (err) {
errors.onUnexpectedError(err);
// generate a UUID
machineId = uuid.generateUuid();
this.machineId = machineId;
this.storageService.store(StorageKeys.MachineId, machineId);
});
} catch (err) {
errors.onUnexpectedError(err);
resolve(this.machineId);
}
});
// generate a UUID
machineId = uuid.generateUuid();
this.machineId = machineId;
this.storageService.store(StorageKeys.MachineId, machineId);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册