-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathAnalyticsService.ts
77 lines (70 loc) · 2.79 KB
/
AnalyticsService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as os from 'os';
import * as vscode from 'vscode';
import { Version } from '../common/version';
import { GUAService } from './GUAService';
import { TelerikAnalyticsService } from './TelerikAnalyticsService';
import { AnalyticsBaseInfo, OperatingSystem } from './AnalyticsBaseInfo';
import { ExtensionHostServices as Services } from '../services/extensionHostServices';
import * as utils from '../common/utilities';
export class AnalyticsService {
private _baseInfo: AnalyticsBaseInfo;
private _gua: GUAService;
private _ta: TelerikAnalyticsService;
private _analyticsEnabled: boolean;
public static generateMachineId(): string {
let machineId = '';
try {
let netInterfaces = os.networkInterfaces();
Object.keys(netInterfaces).forEach(interfName => {
netInterfaces[interfName].forEach(interf => {
if (!interf.internal) {
machineId += `${interf.mac}-`;
}
});
});
} catch(e) {}
return machineId;
}
constructor() {
this._analyticsEnabled = vscode.workspace.getConfiguration('nativescript').get('analytics.enabled') as boolean;
let operatingSystem = OperatingSystem.Other;
switch(process.platform) {
case 'win32': { operatingSystem = OperatingSystem.Windows; break; }
case 'darwin': { operatingSystem = OperatingSystem.OSX; break; }
case 'linux':
case 'freebsd': { operatingSystem = OperatingSystem.Linux; break; }
};
this._baseInfo = {
cliVersion: Services.cli.version.toString(),
extensionVersion: utils.getInstalledExtensionVersion().toString(),
operatingSystem: operatingSystem,
userId: AnalyticsService.generateMachineId()
};
if(this._analyticsEnabled) {
this._gua = new GUAService('UA-111455-29', this._baseInfo);
this._ta = new TelerikAnalyticsService('b8b2e51f188f43e9b0dfb899f7b71cc6', this._baseInfo);
}
}
public launchDebugger(request: string, platform: string): Promise<any> {
if(this._analyticsEnabled) {
try {
return Promise.all([
this._gua.launchDebugger(request, platform),
this._ta.launchDebugger(request, platform)
]);
} catch(e) {}
}
return Promise.resolve();
}
public runRunCommand(platform: string): Promise<any> {
if(this._analyticsEnabled) {
try {
return Promise.all([
this._gua.runRunCommand(platform),
this._ta.runRunCommand(platform)
]);
} catch(e) { }
}
return Promise.resolve();
}
}