@@ -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 ( )
@@ -1414,12 +1437,41 @@ export const webviewMessageHandler = async (
14141437 break
14151438 case "updateCustomMode" :
14161439 if ( message . modeConfig ) {
1440+ // Check if this is a new mode or an update to an existing mode
1441+ const existingModes = await provider . customModesManager . getCustomModes ( )
1442+ const isNewMode = ! existingModes . some ( ( mode ) => mode . slug === message . modeConfig ?. slug )
1443+
14171444 await provider . customModesManager . updateCustomMode ( message . modeConfig . slug , message . modeConfig )
14181445 // Update state after saving the mode
14191446 const customModes = await provider . customModesManager . getCustomModes ( )
14201447 await updateGlobalState ( "customModes" , customModes )
14211448 await updateGlobalState ( "mode" , message . modeConfig . slug )
14221449 await provider . postStateToWebview ( )
1450+
1451+ // Track telemetry for custom mode creation or update
1452+ if ( TelemetryService . hasInstance ( ) ) {
1453+ if ( isNewMode ) {
1454+ // This is a new custom mode
1455+ TelemetryService . instance . captureCustomModeCreated (
1456+ message . modeConfig . slug ,
1457+ message . modeConfig . name ,
1458+ )
1459+ } else {
1460+ // Determine which setting was changed by comparing objects
1461+ const existingMode = existingModes . find ( ( mode ) => mode . slug === message . modeConfig ?. slug )
1462+ const changedSettings = existingMode
1463+ ? Object . keys ( message . modeConfig ) . filter (
1464+ ( key ) =>
1465+ JSON . stringify ( ( existingMode as Record < string , unknown > ) [ key ] ) !==
1466+ JSON . stringify ( ( message . modeConfig as Record < string , unknown > ) [ key ] ) ,
1467+ )
1468+ : [ ]
1469+
1470+ if ( changedSettings . length > 0 ) {
1471+ TelemetryService . instance . captureModeSettingChanged ( changedSettings [ 0 ] )
1472+ }
1473+ }
1474+ }
14231475 }
14241476 break
14251477 case "deleteCustomMode" :
@@ -1604,6 +1656,7 @@ export const webviewMessageHandler = async (
16041656 )
16051657 await provider . postStateToWebview ( )
16061658 console . log ( `Marketplace item installed and config file opened: ${ configFilePath } ` )
1659+
16071660 // Send success message to webview
16081661 provider . postMessageToWebview ( {
16091662 type : "marketplaceInstallResult" ,
@@ -1656,7 +1709,11 @@ export const webviewMessageHandler = async (
16561709
16571710 case "switchTab" : {
16581711 if ( message . tab ) {
1659- // Send a message to the webview to switch to the specified tab
1712+ // Capture tab shown event for all switchTab messages (which are user-initiated)
1713+ if ( TelemetryService . hasInstance ( ) ) {
1714+ TelemetryService . instance . captureTabShown ( message . tab )
1715+ }
1716+
16601717 await provider . postMessageToWebview ( { type : "action" , action : "switchTab" , tab : message . tab } )
16611718 }
16621719 break
0 commit comments