@@ -20,7 +20,7 @@ import { appendPrefixToCommand } from "../../utils";
2020import { ExtensionContextInfo } from "../../extensionContextInfo" ;
2121import { TelemetryPreference } from "../types" ;
2222import { 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" ;
2424import { TelemetryConfiguration } from "../config" ;
2525import { LOGGER } from "../../logger" ;
2626
@@ -37,17 +37,11 @@ export class TelemetrySettings {
3737
3838 this . extensionPrefs = new ExtensionTelemetryPreference ( ) ;
3939 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+
4843 this . isTelemetryEnabled = this . checkTelemetryStatus ( ) ;
49- this . updateGlobalState ( ) ;
50- this . checkConsentVersion ( ) ;
44+ this . syncTelemetrySettingGlobalState ( ) ;
5145 }
5246
5347 private checkTelemetryStatus = ( ) : boolean => this . extensionPrefs . getIsTelemetryEnabled ( ) && this . vscodePrefs . getIsTelemetryEnabled ( ) ;
@@ -56,14 +50,16 @@ export class TelemetrySettings {
5650 const newTelemetryStatus = this . checkTelemetryStatus ( ) ;
5751 if ( newTelemetryStatus !== this . isTelemetryEnabled ) {
5852 this . isTelemetryEnabled = newTelemetryStatus ;
59- cacheService . put ( TELEMETRY_SETTING_VALUE_KEY , newTelemetryStatus . toString ( ) ) ;
53+ this . updateGlobalStates ( ) ;
6054
6155 if ( newTelemetryStatus ) {
6256 this . onTelemetryEnableCallback ( ) ;
6357 } else {
6458 this . onTelemetryDisableCallback ( ) ;
6559 }
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 ) ) {
6763 this . triggerPopup ( ) ;
6864 }
6965 }
@@ -74,38 +70,38 @@ export class TelemetrySettings {
7470 const isExtensionSettingSet = this . extensionPrefs . isTelemetrySettingSet ( ) ;
7571 const isVscodeSettingEnabled = this . vscodePrefs . getIsTelemetryEnabled ( ) ;
7672
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 ;
8474 }
8575
8676 public updateTelemetrySetting = ( value : boolean | undefined ) : void => {
8777 this . extensionPrefs . updateTelemetryConfig ( value ) ;
8878 }
8979
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 ) ;
9283
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 ( ) ;
9586 }
87+ this . checkConsentVersionSchemaGlobalState ( cachedConsentSchemaVersion ) ;
9688 }
9789
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+ }
10195
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 ;
106103 this . updateTelemetrySetting ( undefined ) ;
107104 }
108- this . isTelemetryEnabled = false ;
109105 }
110106 }
111107}
@@ -157,9 +153,6 @@ class VscodeTelemetryPreference implements TelemetryPreference {
157153 } ) ;
158154}
159155
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-
163156// Test cases:
164157// 1. User accepts consent and VSCode telemetry is set to 'all'. Output: enabled telemetry
165158// 2. User accepts consent and VSCode telemetry is not set to 'all'. Output: disabled telemetry
0 commit comments