@@ -5,12 +5,19 @@ import { TelerikAnalyticsService } from './telerikAnalyticsService';
5
5
import { AnalyticsBaseInfo , OperatingSystem } from './analyticsBaseInfo' ;
6
6
import { Services } from '../services/extensionHostServices' ;
7
7
import * as utils from '../common/utilities' ;
8
+ import * as vscode from 'vscode' ;
8
9
9
10
export class AnalyticsService {
11
+ private static HAS_ANALYTICS_PROMPT_SHOWN = "nativescript.hasAnalyticsPromptShown" ;
12
+ private static ANALYTICS_PROMPT_MESSAGE = "Help improve NativeScript Extension by allowing Progress to collect data usage." ;
13
+ private static ANALYTICS_PROMPT_ACTION = "Track" ;
14
+
15
+ private _globalState : vscode . Memento ;
10
16
private _baseInfo : AnalyticsBaseInfo ;
11
17
private _gua : GUAService ;
12
18
private _ta : TelerikAnalyticsService ;
13
19
private _analyticsEnabled : boolean ;
20
+ private disposables : vscode . Disposable [ ] = [ ] ;
14
21
15
22
public static generateMachineId ( ) : string {
16
23
let machineId = '' ;
@@ -27,27 +34,20 @@ export class AnalyticsService {
27
34
return machineId ;
28
35
}
29
36
30
- constructor ( ) {
31
- this . _analyticsEnabled = Services . workspaceConfigService ( ) . isAnalyticsEnabled ;
32
- let operatingSystem = OperatingSystem . Other ;
33
- switch ( process . platform ) {
34
- case 'win32' : { operatingSystem = OperatingSystem . Windows ; break ; }
35
- case 'darwin' : { operatingSystem = OperatingSystem . OSX ; break ; }
36
- case 'linux' :
37
- case 'freebsd' : { operatingSystem = OperatingSystem . Linux ; break ; }
38
- } ;
37
+ constructor ( globalState : vscode . Memento ) {
38
+ this . _globalState = globalState ;
39
+
40
+ //TODO: Dispose
41
+ vscode . workspace . onDidChangeConfiguration ( ( ) => this . updateAnalyticsEnabled ( ) ) ;
39
42
40
43
this . _baseInfo = {
41
44
cliVersion : Services . cli ( ) . version . toString ( ) ,
42
45
extensionVersion : utils . getInstalledExtensionVersion ( ) . toString ( ) ,
43
- operatingSystem : operatingSystem ,
46
+ operatingSystem : AnalyticsService . getOperatingSystem ( ) ,
44
47
userId : AnalyticsService . generateMachineId ( )
45
48
} ;
46
49
47
- if ( this . _analyticsEnabled ) {
48
- this . _gua = new GUAService ( 'UA-111455-29' , this . _baseInfo ) ;
49
- this . _ta = new TelerikAnalyticsService ( 'b8b2e51f188f43e9b0dfb899f7b71cc6' , this . _baseInfo ) ;
50
- }
50
+ this . initializeAnalytics ( ) ;
51
51
}
52
52
53
53
public launchDebugger ( request : string , platform : string ) : Promise < any > {
@@ -73,4 +73,47 @@ export class AnalyticsService {
73
73
}
74
74
return Promise . resolve ( ) ;
75
75
}
76
+
77
+ private static getOperatingSystem ( ) : OperatingSystem {
78
+ switch ( process . platform ) {
79
+ case 'win32' :
80
+ return OperatingSystem . Windows ;
81
+ case 'darwin' :
82
+ return OperatingSystem . OSX ;
83
+ case 'linux' :
84
+ case 'freebsd' :
85
+ return OperatingSystem . Linux ;
86
+ default :
87
+ return OperatingSystem . Other ;
88
+ } ;
89
+ }
90
+
91
+ private initializeAnalytics ( ) : void {
92
+ const hasAnalyticsPromptShown = this . _globalState . get ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN ) ;
93
+ if ( hasAnalyticsPromptShown ) {
94
+ vscode . window . showInformationMessage ( AnalyticsService . ANALYTICS_PROMPT_MESSAGE , AnalyticsService . ANALYTICS_PROMPT_ACTION )
95
+ . then ( result => this . onAnalyticsMessageConfirmation ( result ) ) ;
96
+
97
+ return ;
98
+ }
99
+
100
+ this . updateAnalyticsEnabled ( ) ;
101
+ }
102
+
103
+ private onAnalyticsMessageConfirmation ( result : string ) : void {
104
+ const shouldEnableAnalytics = result === AnalyticsService . ANALYTICS_PROMPT_ACTION ? true : false ;
105
+
106
+ Services . workspaceConfigService ( ) . isAnalyticsEnabled = shouldEnableAnalytics ;
107
+ this . updateAnalyticsEnabled ( ) ;
108
+ this . _globalState . update ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN , true ) ;
109
+ }
110
+
111
+ private updateAnalyticsEnabled ( ) {
112
+ this . _analyticsEnabled = Services . workspaceConfigService ( ) . isAnalyticsEnabled ;
113
+
114
+ if ( this . _analyticsEnabled ) {
115
+ this . _gua = this . _gua || new GUAService ( 'UA-111455-29' , this . _baseInfo ) ;
116
+ this . _ta = this . _ta || new TelerikAnalyticsService ( 'b8b2e51f188f43e9b0dfb899f7b71cc6' , this . _baseInfo ) ;
117
+ }
118
+ }
76
119
}
0 commit comments