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' ;
73import * 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' ;
98
109export 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' ;
1313 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.
1617 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+ }
1935
2036 private _globalState : vscode . Memento ;
21- private _baseInfo : AnalyticsBaseInfo ;
37+ private _logger : ILogger ;
38+ private _baseInfo : IAnalyticsBaseInfo ;
2239 private _gua : GUAService ;
2340 private _analyticsEnabled : boolean ;
2441
25- constructor ( globalState : vscode . Memento ) {
42+ constructor ( globalState : vscode . Memento , cliVersion : string , extensionVersion : string , logger : ILogger ) {
2643 this . _globalState = globalState ;
44+ this . _logger = logger ;
2745
2846 vscode . workspace . onDidChangeConfiguration ( ( ) => this . updateAnalyticsEnabled ( ) ) ;
2947
3048 this . _baseInfo = {
31- cliVersion : Services . cli ( ) . version . toString ( ) ,
32- extensionVersion : utils . getInstalledExtensionVersion ( ) . toString ( ) ,
49+ cliVersion,
50+ clientId : this . getOrGenerateClientId ( ) ,
51+ extensionVersion,
3352 operatingSystem : AnalyticsService . getOperatingSystem ( ) ,
34- clientId : this . getOrGenerateClientId ( )
3553 } ;
3654 }
3755
3856 public launchDebugger ( request : string , platform : string ) : Promise < any > {
39- if ( this . _analyticsEnabled ) {
57+ if ( this . _analyticsEnabled ) {
4058 try {
4159 return this . _gua . launchDebugger ( request , platform ) ;
42- } catch ( e ) { }
60+ } catch ( e ) {
61+ this . _logger . log ( `Analytics error: ${ _ . isString ( e ) ? e : e . message } ` ) ;
62+ }
4363 }
4464
4565 return Promise . resolve ( ) ;
4666 }
4767
4868 public runRunCommand ( platform : string ) : Promise < any > {
49- if ( this . _analyticsEnabled ) {
69+ if ( this . _analyticsEnabled ) {
5070 try {
5171 return this . _gua . runRunCommand ( platform ) ;
52- } catch ( e ) { }
72+ } catch ( e ) {
73+ this . _logger . log ( `Analytics error: ${ _ . isString ( e ) ? e : e . message } ` ) ;
74+ }
5375 }
5476
5577 return Promise . resolve ( ) ;
5678 }
5779
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 {
7381 const hasAnalyticsPromptShown = this . _globalState . get < boolean > ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN_KEY ) ;
74- if ( ! hasAnalyticsPromptShown ) {
82+
83+ if ( ! hasAnalyticsPromptShown ) {
7584 vscode . window . showInformationMessage ( AnalyticsService . ANALYTICS_PROMPT_MESSAGE ,
7685 AnalyticsService . ANALYTICS_PROMPT_ACCEPT_ACTION ,
77- AnalyticsService . ANALYTICS_PROMPT_DENY_ACTION
86+ AnalyticsService . ANALYTICS_PROMPT_DENY_ACTION ,
7887 )
79- . then ( result => this . onAnalyticsMessageConfirmation ( result ) ) ;
88+ . then ( ( result ) => this . onAnalyticsMessageConfirmation ( result ) ) ;
8089
8190 return ;
8291 }
@@ -87,28 +96,28 @@ export class AnalyticsService {
8796 private getOrGenerateClientId ( ) : string {
8897 let clientId = this . _globalState . get < string > ( AnalyticsService . CLIENT_ID_KEY ) ;
8998
90- if ( ! clientId ) {
99+ if ( ! clientId ) {
91100 clientId = uuid . v4 ( ) ;
92101 this . _globalState . update ( AnalyticsService . CLIENT_ID_KEY , clientId ) ;
93102 }
94103
95104 return clientId ;
96105 }
97106
98- private onAnalyticsMessageConfirmation ( result : string ) : void {
107+ private onAnalyticsMessageConfirmation ( result : string ) : void {
99108 const shouldEnableAnalytics = result === AnalyticsService . ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false ;
100109
101110 this . _globalState . update ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN_KEY , true ) ;
102111
103- Services . workspaceConfigService ( ) . isAnalyticsEnabled = shouldEnableAnalytics ;
112+ services . workspaceConfigService . isAnalyticsEnabled = shouldEnableAnalytics ;
104113 this . updateAnalyticsEnabled ( ) ;
105114 }
106115
107116 private updateAnalyticsEnabled ( ) {
108- this . _analyticsEnabled = Services . workspaceConfigService ( ) . isAnalyticsEnabled ;
117+ this . _analyticsEnabled = services . workspaceConfigService . isAnalyticsEnabled ;
109118
110- if ( this . _analyticsEnabled && ! this . _gua ) {
119+ if ( this . _analyticsEnabled && ! this . _gua ) {
111120 this . _gua = new GUAService ( 'UA-111455-29' , this . _baseInfo ) ;
112121 }
113122 }
114- }
123+ }
0 commit comments