1
- import * as os from 'os' ;
2
- import { GUAService } from './guaService' ;
3
- import { AnalyticsBaseInfo , OperatingSystem } from './analyticsBaseInfo' ;
4
- import { Services } from '../services/extensionHostServices' ;
5
- import * as utils from '../common/utilities' ;
1
+ import * as _ from 'lodash' ;
2
+ import * as uuid from 'uuid' ;
6
3
import * as vscode from 'vscode' ;
7
- import * as uuid from "uuid" ;
4
+ import { ILogger } from '../common/logger' ;
5
+ import { services } from '../services/extensionHostServices' ;
6
+ import { IAnalyticsBaseInfo , OperatingSystem } from './analyticsBaseInfo' ;
7
+ import { GUAService } from './guaService' ;
8
8
9
9
export class AnalyticsService {
10
- private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = "nativescript.hasAnalyticsPromptShown" ;
11
- private static CLIENT_ID_KEY = "nativescript.analyticsClientId" ;
10
+ private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = 'nativescript.hasAnalyticsPromptShown' ;
11
+ private static CLIENT_ID_KEY = 'nativescript.analyticsClientId' ;
12
+ private static DOCS_LINK = 'https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics' ;
12
13
private static ANALYTICS_PROMPT_MESSAGE = `Help us improve the NativeScript extension by allowing Progress to collect anonymous usage data.
13
- For more information about the gathered information and how it is used, read our [privacy statement](https://www.progress.com/legal/privacy-policy).
14
- You can [disable the analytics and data collection](https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics) at any given time.
14
+ For more information about the gathered information and how it is used,
15
+ read our [privacy statement](https://www.progress.com/legal/privacy-policy).
16
+ You can [disable the analytics and data collection](${ AnalyticsService . DOCS_LINK } ) at any given time.
15
17
Do you want to enable analytics?` ;
16
- private static ANALYTICS_PROMPT_ACCEPT_ACTION = "Yes" ;
17
- private static ANALYTICS_PROMPT_DENY_ACTION = "No" ;
18
+
19
+ private static ANALYTICS_PROMPT_ACCEPT_ACTION = 'Yes' ;
20
+ private static ANALYTICS_PROMPT_DENY_ACTION = 'No' ;
21
+
22
+ private static getOperatingSystem ( ) : OperatingSystem {
23
+ switch ( process . platform ) {
24
+ case 'win32' :
25
+ return OperatingSystem . Windows ;
26
+ case 'darwin' :
27
+ return OperatingSystem . OSX ;
28
+ case 'linux' :
29
+ case 'freebsd' :
30
+ return OperatingSystem . Linux ;
31
+ default :
32
+ return OperatingSystem . Other ;
33
+ }
34
+ }
18
35
19
36
private _globalState : vscode . Memento ;
20
- private _baseInfo : AnalyticsBaseInfo ;
37
+ private _logger : ILogger ;
38
+ private _baseInfo : IAnalyticsBaseInfo ;
21
39
private _gua : GUAService ;
22
40
private _analyticsEnabled : boolean ;
23
41
24
- constructor ( globalState : vscode . Memento , cliVersion : string , extensionVersion : string ) {
42
+ constructor ( globalState : vscode . Memento , cliVersion : string , extensionVersion : string , logger : ILogger ) {
25
43
this . _globalState = globalState ;
44
+ this . _logger = logger ;
26
45
27
46
vscode . workspace . onDidChangeConfiguration ( ( ) => this . updateAnalyticsEnabled ( ) ) ;
28
47
29
48
this . _baseInfo = {
30
49
cliVersion,
50
+ clientId : this . getOrGenerateClientId ( ) ,
31
51
extensionVersion,
32
52
operatingSystem : AnalyticsService . getOperatingSystem ( ) ,
33
- clientId : this . getOrGenerateClientId ( )
34
53
} ;
35
54
}
36
55
37
56
public launchDebugger ( request : string , platform : string ) : Promise < any > {
38
- if ( this . _analyticsEnabled ) {
57
+ if ( this . _analyticsEnabled ) {
39
58
try {
40
59
return this . _gua . launchDebugger ( request , platform ) ;
41
- } catch ( e ) { }
60
+ } catch ( e ) {
61
+ this . _logger . log ( `Analytics error: ${ _ . isString ( e ) ? e : e . message } ` ) ;
62
+ }
42
63
}
43
64
44
65
return Promise . resolve ( ) ;
45
66
}
46
67
47
68
public runRunCommand ( platform : string ) : Promise < any > {
48
- if ( this . _analyticsEnabled ) {
69
+ if ( this . _analyticsEnabled ) {
49
70
try {
50
71
return this . _gua . runRunCommand ( platform ) ;
51
- } catch ( e ) { }
72
+ } catch ( e ) {
73
+ this . _logger . log ( `Analytics error: ${ _ . isString ( e ) ? e : e . message } ` ) ;
74
+ }
52
75
}
53
76
54
77
return Promise . resolve ( ) ;
55
78
}
56
79
57
- private static getOperatingSystem ( ) : OperatingSystem {
58
- switch ( process . platform ) {
59
- case 'win32' :
60
- return OperatingSystem . Windows ;
61
- case 'darwin' :
62
- return OperatingSystem . OSX ;
63
- case 'linux' :
64
- case 'freebsd' :
65
- return OperatingSystem . Linux ;
66
- default :
67
- return OperatingSystem . Other ;
68
- } ;
69
- }
70
-
71
- public initialize ( ) : void {
80
+ public initialize ( ) : void {
72
81
const hasAnalyticsPromptShown = this . _globalState . get < boolean > ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN_KEY ) ;
73
- if ( ! hasAnalyticsPromptShown ) {
82
+
83
+ if ( ! hasAnalyticsPromptShown ) {
74
84
vscode . window . showInformationMessage ( AnalyticsService . ANALYTICS_PROMPT_MESSAGE ,
75
85
AnalyticsService . ANALYTICS_PROMPT_ACCEPT_ACTION ,
76
- AnalyticsService . ANALYTICS_PROMPT_DENY_ACTION
86
+ AnalyticsService . ANALYTICS_PROMPT_DENY_ACTION ,
77
87
)
78
- . then ( result => this . onAnalyticsMessageConfirmation ( result ) ) ;
88
+ . then ( ( result ) => this . onAnalyticsMessageConfirmation ( result ) ) ;
79
89
80
90
return ;
81
91
}
@@ -86,28 +96,28 @@ export class AnalyticsService {
86
96
private getOrGenerateClientId ( ) : string {
87
97
let clientId = this . _globalState . get < string > ( AnalyticsService . CLIENT_ID_KEY ) ;
88
98
89
- if ( ! clientId ) {
99
+ if ( ! clientId ) {
90
100
clientId = uuid . v4 ( ) ;
91
101
this . _globalState . update ( AnalyticsService . CLIENT_ID_KEY , clientId ) ;
92
102
}
93
103
94
104
return clientId ;
95
105
}
96
106
97
- private onAnalyticsMessageConfirmation ( result : string ) : void {
107
+ private onAnalyticsMessageConfirmation ( result : string ) : void {
98
108
const shouldEnableAnalytics = result === AnalyticsService . ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false ;
99
109
100
110
this . _globalState . update ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN_KEY , true ) ;
101
111
102
- Services . workspaceConfigService . isAnalyticsEnabled = shouldEnableAnalytics ;
112
+ services . workspaceConfigService . isAnalyticsEnabled = shouldEnableAnalytics ;
103
113
this . updateAnalyticsEnabled ( ) ;
104
114
}
105
115
106
116
private updateAnalyticsEnabled ( ) {
107
- this . _analyticsEnabled = Services . workspaceConfigService . isAnalyticsEnabled ;
117
+ this . _analyticsEnabled = services . workspaceConfigService . isAnalyticsEnabled ;
108
118
109
- if ( this . _analyticsEnabled && ! this . _gua ) {
119
+ if ( this . _analyticsEnabled && ! this . _gua ) {
110
120
this . _gua = new GUAService ( 'UA-111455-29' , this . _baseInfo ) ;
111
121
}
112
122
}
113
- }
123
+ }
0 commit comments