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' ;
63import * 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' ;
88
99export 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' ;
1213 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.
1517 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+ }
1835
1936 private _globalState : vscode . Memento ;
20- private _baseInfo : AnalyticsBaseInfo ;
37+ private _logger : ILogger ;
38+ private _baseInfo : IAnalyticsBaseInfo ;
2139 private _gua : GUAService ;
2240 private _analyticsEnabled : boolean ;
2341
24- constructor ( globalState : vscode . Memento , cliVersion : string , extensionVersion : string ) {
42+ constructor ( globalState : vscode . Memento , cliVersion : string , extensionVersion : string , logger : ILogger ) {
2543 this . _globalState = globalState ;
44+ this . _logger = logger ;
2645
2746 vscode . workspace . onDidChangeConfiguration ( ( ) => this . updateAnalyticsEnabled ( ) ) ;
2847
2948 this . _baseInfo = {
3049 cliVersion,
50+ clientId : this . getOrGenerateClientId ( ) ,
3151 extensionVersion,
3252 operatingSystem : AnalyticsService . getOperatingSystem ( ) ,
33- clientId : this . getOrGenerateClientId ( )
3453 } ;
3554 }
3655
3756 public launchDebugger ( request : string , platform : string ) : Promise < any > {
38- if ( this . _analyticsEnabled ) {
57+ if ( this . _analyticsEnabled ) {
3958 try {
4059 return this . _gua . launchDebugger ( request , platform ) ;
41- } catch ( e ) { }
60+ } catch ( e ) {
61+ this . _logger . log ( `Analytics error: ${ _ . isString ( e ) ? e : e . message } ` ) ;
62+ }
4263 }
4364
4465 return Promise . resolve ( ) ;
4566 }
4667
4768 public runRunCommand ( platform : string ) : Promise < any > {
48- if ( this . _analyticsEnabled ) {
69+ if ( this . _analyticsEnabled ) {
4970 try {
5071 return this . _gua . runRunCommand ( platform ) ;
51- } catch ( e ) { }
72+ } catch ( e ) {
73+ this . _logger . log ( `Analytics error: ${ _ . isString ( e ) ? e : e . message } ` ) ;
74+ }
5275 }
5376
5477 return Promise . resolve ( ) ;
5578 }
5679
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 {
7281 const hasAnalyticsPromptShown = this . _globalState . get < boolean > ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN_KEY ) ;
73- if ( ! hasAnalyticsPromptShown ) {
82+
83+ if ( ! hasAnalyticsPromptShown ) {
7484 vscode . window . showInformationMessage ( AnalyticsService . ANALYTICS_PROMPT_MESSAGE ,
7585 AnalyticsService . ANALYTICS_PROMPT_ACCEPT_ACTION ,
76- AnalyticsService . ANALYTICS_PROMPT_DENY_ACTION
86+ AnalyticsService . ANALYTICS_PROMPT_DENY_ACTION ,
7787 )
78- . then ( result => this . onAnalyticsMessageConfirmation ( result ) ) ;
88+ . then ( ( result ) => this . onAnalyticsMessageConfirmation ( result ) ) ;
7989
8090 return ;
8191 }
@@ -86,28 +96,28 @@ export class AnalyticsService {
8696 private getOrGenerateClientId ( ) : string {
8797 let clientId = this . _globalState . get < string > ( AnalyticsService . CLIENT_ID_KEY ) ;
8898
89- if ( ! clientId ) {
99+ if ( ! clientId ) {
90100 clientId = uuid . v4 ( ) ;
91101 this . _globalState . update ( AnalyticsService . CLIENT_ID_KEY , clientId ) ;
92102 }
93103
94104 return clientId ;
95105 }
96106
97- private onAnalyticsMessageConfirmation ( result : string ) : void {
107+ private onAnalyticsMessageConfirmation ( result : string ) : void {
98108 const shouldEnableAnalytics = result === AnalyticsService . ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false ;
99109
100110 this . _globalState . update ( AnalyticsService . HAS_ANALYTICS_PROMPT_SHOWN_KEY , true ) ;
101111
102- Services . workspaceConfigService . isAnalyticsEnabled = shouldEnableAnalytics ;
112+ services . workspaceConfigService . isAnalyticsEnabled = shouldEnableAnalytics ;
103113 this . updateAnalyticsEnabled ( ) ;
104114 }
105115
106116 private updateAnalyticsEnabled ( ) {
107- this . _analyticsEnabled = Services . workspaceConfigService . isAnalyticsEnabled ;
117+ this . _analyticsEnabled = services . workspaceConfigService . isAnalyticsEnabled ;
108118
109- if ( this . _analyticsEnabled && ! this . _gua ) {
119+ if ( this . _analyticsEnabled && ! this . _gua ) {
110120 this . _gua = new GUAService ( 'UA-111455-29' , this . _baseInfo ) ;
111121 }
112122 }
113- }
123+ }
0 commit comments