@@ -32,6 +32,7 @@ import { openMention } from "../mentions"
3232import { getNonce } from "./getNonce"
3333import { getUri } from "./getUri"
3434import { telemetryService } from "../../services/telemetry/TelemetryService"
35+ import { TelemetrySetting } from "../../shared/TelemetrySetting"
3536
3637/*
3738https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -93,6 +94,7 @@ type GlobalStateKey =
9394 | "requestyModelId"
9495 | "togetherModelId"
9596 | "mcpMarketplaceCatalog"
97+ | "telemetrySetting"
9698
9799export const GlobalFileNames = {
98100 apiConversationHistory : "api_conversation_history.json" ,
@@ -454,6 +456,13 @@ export class ClineProvider implements vscode.WebviewViewProvider {
454456 }
455457 } )
456458
459+ // If user already opted in to telemetry, enable telemetry service
460+ this . getStateToPostToWebview ( ) . then ( ( state ) => {
461+ const { telemetrySetting } = state
462+ const isOptedIn = telemetrySetting === "enabled"
463+ telemetryService . updateTelemetryState ( isOptedIn )
464+ } )
465+
457466 break
458467 case "newTask" :
459468 // Code that should run in response to the hello message command
@@ -849,18 +858,19 @@ export class ClineProvider implements vscode.WebviewViewProvider {
849858 break
850859 }
851860 // telemetry
852- case "openTelemetrySettings " : {
853- await vscode . commands . executeCommand (
854- "workbench. action.openSettings ",
855- "@ext:saoudrizwan.claude-dev cline.telemetryOptIn ",
856- )
861+ case "openSettings " : {
862+ await this . postMessageToWebview ( {
863+ type : " action",
864+ action : "settingsButtonClicked ",
865+ } )
857866 break
858867 }
859- case "telemetryOptIn" : {
860- if ( message . bool !== undefined ) {
861- await vscode . workspace . getConfiguration ( "cline" ) . update ( "enableTelemetry" , message . bool , true )
862- await this . postStateToWebview ( )
863- }
868+ case "telemetrySetting" : {
869+ const telemetrySetting = message . text as TelemetrySetting
870+ await this . updateGlobalState ( "telemetrySetting" , telemetrySetting )
871+ const isOptedIn = telemetrySetting === "enabled"
872+ telemetryService . updateTelemetryState ( isOptedIn )
873+ await this . postStateToWebview ( )
864874 break
865875 }
866876 // Add more switch case statements here as more webview message commands
@@ -1628,7 +1638,7 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
16281638 userInfo,
16291639 authToken,
16301640 mcpMarketplaceEnabled,
1631- telemetryOptIn ,
1641+ telemetrySetting ,
16321642 } = await this . getState ( )
16331643
16341644 return {
@@ -1648,7 +1658,7 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
16481658 isLoggedIn : ! ! authToken ,
16491659 userInfo,
16501660 mcpMarketplaceEnabled,
1651- telemetryOptIn ,
1661+ telemetrySetting ,
16521662 }
16531663 }
16541664
@@ -1755,6 +1765,7 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
17551765 previousModeModelInfo ,
17561766 qwenApiLine ,
17571767 liteLlmApiKey ,
1768+ telemetrySetting ,
17581769 ] = await Promise . all ( [
17591770 this . getGlobalState ( "apiProvider" ) as Promise < ApiProvider | undefined > ,
17601771 this . getGlobalState ( "apiModelId" ) as Promise < string | undefined > ,
@@ -1806,6 +1817,7 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
18061817 this . getGlobalState ( "previousModeModelInfo" ) as Promise < ModelInfo | undefined > ,
18071818 this . getGlobalState ( "qwenApiLine" ) as Promise < string | undefined > ,
18081819 this . getSecret ( "liteLlmApiKey" ) as Promise < string | undefined > ,
1820+ this . getGlobalState ( "telemetrySetting" ) as Promise < TelemetrySetting | undefined > ,
18091821 ] )
18101822
18111823 let apiProvider : ApiProvider
@@ -1827,7 +1839,6 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
18271839 . get ( "reasoningEffort" , "medium" )
18281840
18291841 const mcpMarketplaceEnabled = vscode . workspace . getConfiguration ( "cline" ) . get < boolean > ( "mcpMarketplace.enabled" , true )
1830- const telemetryOptIn = vscode . workspace . getConfiguration ( "cline" ) . get < boolean | null > ( "enableTelemetry" , null )
18311842
18321843 return {
18331844 apiConfiguration : {
@@ -1884,7 +1895,7 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
18841895 previousModeModelId,
18851896 previousModeModelInfo,
18861897 mcpMarketplaceEnabled,
1887- telemetryOptIn ,
1898+ telemetrySetting : telemetrySetting || "unset" ,
18881899 }
18891900 }
18901901
0 commit comments