@@ -948,8 +948,27 @@ export const webviewMessageHandler = async (
948948 const updatedPrompts = { ...existingPrompts , [ message . promptMode ] : message . customPrompt }
949949 await updateGlobalState ( "customModePrompts" , updatedPrompts )
950950 const currentState = await provider . getStateToPostToWebview ( )
951- const stateWithPrompts = { ...currentState , customModePrompts : updatedPrompts }
951+ const stateWithPrompts = {
952+ ...currentState ,
953+ customModePrompts : updatedPrompts ,
954+ hasOpenedModeSelector : currentState . hasOpenedModeSelector ?? false ,
955+ }
952956 provider . postMessageToWebview ( { type : "state" , state : stateWithPrompts } )
957+
958+ if ( TelemetryService . hasInstance ( ) ) {
959+ // Determine which setting was changed by comparing objects
960+ const oldPrompt = existingPrompts [ message . promptMode ] || { }
961+ const newPrompt = message . customPrompt
962+ const changedSettings = Object . keys ( newPrompt ) . filter (
963+ ( key ) =>
964+ JSON . stringify ( ( oldPrompt as Record < string , unknown > ) [ key ] ) !==
965+ JSON . stringify ( ( newPrompt as Record < string , unknown > ) [ key ] ) ,
966+ )
967+
968+ if ( changedSettings . length > 0 ) {
969+ TelemetryService . instance . captureModeSettingChanged ( changedSettings [ 0 ] )
970+ }
971+ }
953972 }
954973 break
955974 case "deleteMessage" : {
@@ -1085,6 +1104,10 @@ export const webviewMessageHandler = async (
10851104 await updateGlobalState ( "showRooIgnoredFiles" , message . bool ?? true )
10861105 await provider . postStateToWebview ( )
10871106 break
1107+ case "hasOpenedModeSelector" :
1108+ await updateGlobalState ( "hasOpenedModeSelector" , message . bool ?? true )
1109+ await provider . postStateToWebview ( )
1110+ break
10881111 case "maxReadFileLine" :
10891112 await updateGlobalState ( "maxReadFileLine" , message . value )
10901113 await provider . postStateToWebview ( )
@@ -1437,12 +1460,41 @@ export const webviewMessageHandler = async (
14371460 break
14381461 case "updateCustomMode" :
14391462 if ( message . modeConfig ) {
1463+ // Check if this is a new mode or an update to an existing mode
1464+ const existingModes = await provider . customModesManager . getCustomModes ( )
1465+ const isNewMode = ! existingModes . some ( ( mode ) => mode . slug === message . modeConfig ?. slug )
1466+
14401467 await provider . customModesManager . updateCustomMode ( message . modeConfig . slug , message . modeConfig )
14411468 // Update state after saving the mode
14421469 const customModes = await provider . customModesManager . getCustomModes ( )
14431470 await updateGlobalState ( "customModes" , customModes )
14441471 await updateGlobalState ( "mode" , message . modeConfig . slug )
14451472 await provider . postStateToWebview ( )
1473+
1474+ // Track telemetry for custom mode creation or update
1475+ if ( TelemetryService . hasInstance ( ) ) {
1476+ if ( isNewMode ) {
1477+ // This is a new custom mode
1478+ TelemetryService . instance . captureCustomModeCreated (
1479+ message . modeConfig . slug ,
1480+ message . modeConfig . name ,
1481+ )
1482+ } else {
1483+ // Determine which setting was changed by comparing objects
1484+ const existingMode = existingModes . find ( ( mode ) => mode . slug === message . modeConfig ?. slug )
1485+ const changedSettings = existingMode
1486+ ? Object . keys ( message . modeConfig ) . filter (
1487+ ( key ) =>
1488+ JSON . stringify ( ( existingMode as Record < string , unknown > ) [ key ] ) !==
1489+ JSON . stringify ( ( message . modeConfig as Record < string , unknown > ) [ key ] ) ,
1490+ )
1491+ : [ ]
1492+
1493+ if ( changedSettings . length > 0 ) {
1494+ TelemetryService . instance . captureModeSettingChanged ( changedSettings [ 0 ] )
1495+ }
1496+ }
1497+ }
14461498 }
14471499 break
14481500 case "deleteCustomMode" :
@@ -1627,6 +1679,7 @@ export const webviewMessageHandler = async (
16271679 )
16281680 await provider . postStateToWebview ( )
16291681 console . log ( `Marketplace item installed and config file opened: ${ configFilePath } ` )
1682+
16301683 // Send success message to webview
16311684 provider . postMessageToWebview ( {
16321685 type : "marketplaceInstallResult" ,
@@ -1679,7 +1732,11 @@ export const webviewMessageHandler = async (
16791732
16801733 case "switchTab" : {
16811734 if ( message . tab ) {
1682- // Send a message to the webview to switch to the specified tab
1735+ // Capture tab shown event for all switchTab messages (which are user-initiated)
1736+ if ( TelemetryService . hasInstance ( ) ) {
1737+ TelemetryService . instance . captureTabShown ( message . tab )
1738+ }
1739+
16831740 await provider . postMessageToWebview ( { type : "action" , action : "switchTab" , tab : message . tab } )
16841741 }
16851742 break
0 commit comments