@@ -862,6 +862,21 @@ export const webviewMessageHandler = async (
862862 hasOpenedModeSelector : currentState . hasOpenedModeSelector ?? false ,
863863 }
864864 provider . postMessageToWebview ( { type : "state" , state : stateWithPrompts } )
865+
866+ if ( TelemetryService . hasInstance ( ) ) {
867+ // Determine which setting was changed by comparing objects
868+ const oldPrompt = existingPrompts [ message . promptMode ] || { }
869+ const newPrompt = message . customPrompt
870+ const changedSettings = Object . keys ( newPrompt ) . filter (
871+ ( key ) =>
872+ JSON . stringify ( ( oldPrompt as Record < string , unknown > ) [ key ] ) !==
873+ JSON . stringify ( ( newPrompt as Record < string , unknown > ) [ key ] ) ,
874+ )
875+
876+ if ( changedSettings . length > 0 ) {
877+ TelemetryService . instance . captureModeSettingChanged ( changedSettings [ 0 ] )
878+ }
879+ }
865880 }
866881 break
867882 case "deleteMessage" : {
@@ -1326,12 +1341,41 @@ export const webviewMessageHandler = async (
13261341 break
13271342 case "updateCustomMode" :
13281343 if ( message . modeConfig ) {
1344+ // Check if this is a new mode or an update to an existing mode
1345+ const existingModes = await provider . customModesManager . getCustomModes ( )
1346+ const isNewMode = ! existingModes . some ( ( mode ) => mode . slug === message . modeConfig ?. slug )
1347+
13291348 await provider . customModesManager . updateCustomMode ( message . modeConfig . slug , message . modeConfig )
13301349 // Update state after saving the mode
13311350 const customModes = await provider . customModesManager . getCustomModes ( )
13321351 await updateGlobalState ( "customModes" , customModes )
13331352 await updateGlobalState ( "mode" , message . modeConfig . slug )
13341353 await provider . postStateToWebview ( )
1354+
1355+ // Track telemetry for custom mode creation or update
1356+ if ( TelemetryService . hasInstance ( ) ) {
1357+ if ( isNewMode ) {
1358+ // This is a new custom mode
1359+ TelemetryService . instance . captureCustomModeCreated (
1360+ message . modeConfig . slug ,
1361+ message . modeConfig . name ,
1362+ )
1363+ } else {
1364+ // Determine which setting was changed by comparing objects
1365+ const existingMode = existingModes . find ( ( mode ) => mode . slug === message . modeConfig ?. slug )
1366+ const changedSettings = existingMode
1367+ ? Object . keys ( message . modeConfig ) . filter (
1368+ ( key ) =>
1369+ JSON . stringify ( ( existingMode as Record < string , unknown > ) [ key ] ) !==
1370+ JSON . stringify ( ( message . modeConfig as Record < string , unknown > ) [ key ] ) ,
1371+ )
1372+ : [ ]
1373+
1374+ if ( changedSettings . length > 0 ) {
1375+ TelemetryService . instance . captureModeSettingChanged ( changedSettings [ 0 ] )
1376+ }
1377+ }
1378+ }
13351379 }
13361380 break
13371381 case "deleteCustomMode" :
@@ -1510,6 +1554,7 @@ export const webviewMessageHandler = async (
15101554 )
15111555 await provider . postStateToWebview ( )
15121556 console . log ( `Marketplace item installed and config file opened: ${ configFilePath } ` )
1557+
15131558 // Send success message to webview
15141559 provider . postMessageToWebview ( {
15151560 type : "marketplaceInstallResult" ,
@@ -1562,7 +1607,11 @@ export const webviewMessageHandler = async (
15621607
15631608 case "switchTab" : {
15641609 if ( message . tab ) {
1565- // Send a message to the webview to switch to the specified tab
1610+ // This could be more generic, but keeping it specific for now
1611+ if ( message . tab === "modes" && TelemetryService . hasInstance ( ) ) {
1612+ TelemetryService . instance . captureModesViewShown ( )
1613+ }
1614+
15661615 await provider . postMessageToWebview ( { type : "action" , action : "switchTab" , tab : message . tab } )
15671616 }
15681617 break
0 commit comments