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