@@ -20,7 +20,7 @@ import { appendPrefixToCommand } from "../../utils";
20
20
import { ExtensionContextInfo } from "../../extensionContextInfo" ;
21
21
import { TelemetryPreference } from "../types" ;
22
22
import { cacheService } from "./cacheServiceImpl" ;
23
- import { TELEMETRY_CONSENT_POPUP_TIME_KEY , TELEMETRY_CONSENT_VERSION_SCHEMA_KEY , TELEMETRY_SETTING_VALUE_KEY } from "../constants" ;
23
+ import { TELEMETRY_CONSENT_RESPONSE_TIME_KEY , TELEMETRY_CONSENT_VERSION_SCHEMA_KEY , TELEMETRY_SETTING_VALUE_KEY } from "../constants" ;
24
24
import { TelemetryConfiguration } from "../config" ;
25
25
import { LOGGER } from "../../logger" ;
26
26
@@ -37,17 +37,11 @@ export class TelemetrySettings {
37
37
38
38
this . extensionPrefs = new ExtensionTelemetryPreference ( ) ;
39
39
this . vscodePrefs = new VscodeTelemetryPreference ( ) ;
40
-
41
- extensionContext . pushSubscription (
42
- this . extensionPrefs . onChangeTelemetrySetting ( this . onChangeTelemetrySettingCallback )
43
- ) ;
44
- extensionContext . pushSubscription (
45
- this . vscodePrefs . onChangeTelemetrySetting ( this . onChangeTelemetrySettingCallback )
46
- ) ;
47
-
40
+ extensionContext . pushSubscription ( this . extensionPrefs . onChangeTelemetrySetting ( this . onChangeTelemetrySettingCallback ) ) ;
41
+ extensionContext . pushSubscription ( this . vscodePrefs . onChangeTelemetrySetting ( this . onChangeTelemetrySettingCallback ) ) ;
42
+
48
43
this . isTelemetryEnabled = this . checkTelemetryStatus ( ) ;
49
- this . updateGlobalState ( ) ;
50
- this . checkConsentVersion ( ) ;
44
+ this . syncTelemetrySettingGlobalState ( ) ;
51
45
}
52
46
53
47
private checkTelemetryStatus = ( ) : boolean => this . extensionPrefs . getIsTelemetryEnabled ( ) && this . vscodePrefs . getIsTelemetryEnabled ( ) ;
@@ -56,14 +50,16 @@ export class TelemetrySettings {
56
50
const newTelemetryStatus = this . checkTelemetryStatus ( ) ;
57
51
if ( newTelemetryStatus !== this . isTelemetryEnabled ) {
58
52
this . isTelemetryEnabled = newTelemetryStatus ;
59
- cacheService . put ( TELEMETRY_SETTING_VALUE_KEY , newTelemetryStatus . toString ( ) ) ;
53
+ this . updateGlobalStates ( ) ;
60
54
61
55
if ( newTelemetryStatus ) {
62
56
this . onTelemetryEnableCallback ( ) ;
63
57
} else {
64
58
this . onTelemetryDisableCallback ( ) ;
65
59
}
66
- } else if ( this . vscodePrefs . getIsTelemetryEnabled ( ) && ! this . extensionPrefs . isTelemetrySettingSet ( ) ) {
60
+ } else if ( this . vscodePrefs . getIsTelemetryEnabled ( )
61
+ && ! this . extensionPrefs . isTelemetrySettingSet ( )
62
+ && ! cacheService . get ( TELEMETRY_CONSENT_RESPONSE_TIME_KEY ) ) {
67
63
this . triggerPopup ( ) ;
68
64
}
69
65
}
@@ -74,38 +70,38 @@ export class TelemetrySettings {
74
70
const isExtensionSettingSet = this . extensionPrefs . isTelemetrySettingSet ( ) ;
75
71
const isVscodeSettingEnabled = this . vscodePrefs . getIsTelemetryEnabled ( ) ;
76
72
77
- const showPopup = ! isExtensionSettingSet && isVscodeSettingEnabled ;
78
-
79
- if ( showPopup ) {
80
- cacheService . put ( TELEMETRY_CONSENT_POPUP_TIME_KEY , Date . now ( ) . toString ( ) ) ;
81
- }
82
-
83
- return showPopup ;
73
+ return ! isExtensionSettingSet && isVscodeSettingEnabled ;
84
74
}
85
75
86
76
public updateTelemetrySetting = ( value : boolean | undefined ) : void => {
87
77
this . extensionPrefs . updateTelemetryConfig ( value ) ;
88
78
}
89
79
90
- private updateGlobalState ( ) : void {
91
- const cachedValue = cacheService . get ( TELEMETRY_SETTING_VALUE_KEY ) ;
80
+ private syncTelemetrySettingGlobalState ( ) : void {
81
+ const cachedSettingValue = cacheService . get ( TELEMETRY_SETTING_VALUE_KEY ) ;
82
+ const cachedConsentSchemaVersion = cacheService . get ( TELEMETRY_CONSENT_VERSION_SCHEMA_KEY ) ;
92
83
93
- if ( this . isTelemetryEnabled . toString ( ) !== cachedValue ) {
94
- cacheService . put ( TELEMETRY_SETTING_VALUE_KEY , this . isTelemetryEnabled . toString ( ) ) ;
84
+ if ( this . isTelemetryEnabled . toString ( ) !== cachedSettingValue ) {
85
+ this . updateGlobalStates ( ) ;
95
86
}
87
+ this . checkConsentVersionSchemaGlobalState ( cachedConsentSchemaVersion ) ;
96
88
}
97
89
98
- private checkConsentVersion ( ) : void {
99
- const cachedVersion = cacheService . get ( TELEMETRY_CONSENT_VERSION_SCHEMA_KEY ) ;
100
- const currentVersion = TelemetryConfiguration . getInstance ( ) . getTelemetryConfigMetadata ( ) ?. consentSchemaVersion ;
90
+ private updateGlobalStates ( ) : void {
91
+ cacheService . put ( TELEMETRY_CONSENT_RESPONSE_TIME_KEY , Date . now ( ) . toString ( ) ) ;
92
+ cacheService . put ( TELEMETRY_CONSENT_VERSION_SCHEMA_KEY , TelemetryConfiguration . getInstance ( ) . getTelemetryConfigMetadata ( ) ?. consentSchemaVersion ) ;
93
+ cacheService . put ( TELEMETRY_SETTING_VALUE_KEY , this . isTelemetryEnabled . toString ( ) ) ;
94
+ }
101
95
102
- if ( cachedVersion !== currentVersion ) {
103
- cacheService . put ( TELEMETRY_CONSENT_VERSION_SCHEMA_KEY , currentVersion ) ;
104
- LOGGER . debug ( "Removing telemetry config from user settings" ) ;
105
- if ( this . extensionPrefs . isTelemetrySettingSet ( ) ) {
96
+ private checkConsentVersionSchemaGlobalState ( consentSchemaVersion : string | undefined ) : void {
97
+ if ( this . extensionPrefs . isTelemetrySettingSet ( ) ) {
98
+ const currentExtConsentSchemaVersion = TelemetryConfiguration . getInstance ( ) . getTelemetryConfigMetadata ( ) ?. consentSchemaVersion ;
99
+
100
+ if ( consentSchemaVersion !== currentExtConsentSchemaVersion ) {
101
+ LOGGER . debug ( "Removing telemetry config from user settings due to consent schema version change" ) ;
102
+ this . isTelemetryEnabled = false ;
106
103
this . updateTelemetrySetting ( undefined ) ;
107
104
}
108
- this . isTelemetryEnabled = false ;
109
105
}
110
106
}
111
107
}
@@ -157,9 +153,6 @@ class VscodeTelemetryPreference implements TelemetryPreference {
157
153
} ) ;
158
154
}
159
155
160
- // Question:
161
- // When consent version is changed, we have to show popup to all the users or only those who had accepted earlier?
162
-
163
156
// Test cases:
164
157
// 1. User accepts consent and VSCode telemetry is set to 'all'. Output: enabled telemetry
165
158
// 2. User accepts consent and VSCode telemetry is not set to 'all'. Output: disabled telemetry
0 commit comments