2024-05-09 10:32:03 -04:00
# include "pch.h"
# include "trace.h"
TRACELOGGING_DEFINE_PROVIDER (
g_hProvider ,
" Microsoft.PowerToys " ,
// {38e8889b-9731-53f5-e901-e8a7c1753074}
( 0x38e8889b , 0x9731 , 0x53f5 , 0xe9 , 0x01 , 0xe8 , 0xa7 , 0xc1 , 0x75 , 0x30 , 0x74 ) ,
TraceLoggingOptionProjectTelemetry ( ) ) ;
// Log if the user has AdvancedPaste enabled or disabled
void Trace : : AdvancedPaste_Enable ( const bool enabled ) noexcept
{
2024-10-24 22:04:32 +02:00
TraceLoggingWriteWrapper (
2024-05-09 10:32:03 -04:00
g_hProvider ,
" AdvancedPaste_EnableAdvancedPaste " ,
ProjectTelemetryPrivacyDataTag ( ProjectTelemetryTag_ProductAndServicePerformance ) ,
TraceLoggingKeyword ( PROJECT_KEYWORD_MEASURE ) ,
TraceLoggingBoolean ( enabled , " Enabled " ) ) ;
}
// Log if the user has invoked AdvancedPaste
void Trace : : AdvancedPaste_Invoked ( std : : wstring mode ) noexcept
{
2024-10-24 22:04:32 +02:00
TraceLoggingWriteWrapper (
2024-05-09 10:32:03 -04:00
g_hProvider ,
" AdvancedPaste_InvokeAdvancedPaste " ,
ProjectTelemetryPrivacyDataTag ( ProjectTelemetryTag_ProductAndServicePerformance ) ,
TraceLoggingKeyword ( PROJECT_KEYWORD_MEASURE ) ,
TraceLoggingValue ( mode . c_str ( ) , " Mode " ) ) ;
}
// Log if an error occurs in AdvancedPaste
void Trace : : AdvancedPaste_Error ( const DWORD errorCode , std : : wstring errorMessage , std : : wstring methodName ) noexcept
{
2024-10-24 22:04:32 +02:00
TraceLoggingWriteWrapper (
2024-05-09 10:32:03 -04:00
g_hProvider ,
" AdvancedPaste_Error " ,
ProjectTelemetryPrivacyDataTag ( ProjectTelemetryTag_ProductAndServicePerformance ) ,
TraceLoggingKeyword ( PROJECT_KEYWORD_MEASURE ) ,
TraceLoggingValue ( methodName . c_str ( ) , " MethodName " ) ,
TraceLoggingValue ( errorCode , " ErrorCode " ) ,
TraceLoggingValue ( errorMessage . c_str ( ) , " ErrorMessage " ) ) ;
}
// Event to send settings telemetry.
void Trace : : AdvancedPaste_SettingsTelemetry ( const PowertoyModuleIface : : Hotkey & pastePlainHotkey ,
const PowertoyModuleIface : : Hotkey & advancedPasteUIHotkey ,
const PowertoyModuleIface : : Hotkey & pasteMarkdownHotkey ,
const PowertoyModuleIface : : Hotkey & pasteJsonHotkey ,
2024-12-11 10:28:44 +01:00
const bool is_advanced_ai_enabled ,
2024-10-18 15:34:09 +02:00
const bool preview_custom_format_output ,
const std : : unordered_map < std : : wstring , PowertoyModuleIface : : Hotkey > & additionalActionsHotkeys ) noexcept
2024-05-09 10:32:03 -04:00
{
2024-10-18 15:34:09 +02:00
const auto getHotKeyStr = [ ] ( const PowertoyModuleIface : : Hotkey & hotKey )
{
return std : : wstring ( hotKey . win ? L " Win + " : L " " ) +
std : : wstring ( hotKey . ctrl ? L " Ctrl + " : L " " ) +
std : : wstring ( hotKey . shift ? L " Shift + " : L " " ) +
std : : wstring ( hotKey . alt ? L " Alt + " : L " " ) +
std : : wstring ( L " VK " ) + std : : to_wstring ( hotKey . key ) ;
} ;
2024-05-09 10:32:03 -04:00
2024-10-18 15:34:09 +02:00
std : : vector < std : : wstring > hotkeyStrs ;
const auto getHotkeyCStr = [ & ] ( const PowertoyModuleIface : : Hotkey & hotkey )
{
hotkeyStrs . push_back ( getHotKeyStr ( hotkey ) ) ; // Probably unnecessary, but offers protection against the macro TraceLoggingWideString expanding to something that would invalidate the pointer
return hotkeyStrs . back ( ) . c_str ( ) ;
} ;
2024-05-09 10:32:03 -04:00
2024-10-18 15:34:09 +02:00
const auto getAdditionalActionHotkeyCStr = [ & ] ( const std : : wstring & name )
{
const auto it = additionalActionsHotkeys . find ( name ) ;
return it ! = additionalActionsHotkeys . end ( ) ? getHotkeyCStr ( it - > second ) : L " " ;
} ;
2024-05-09 10:32:03 -04:00
2024-10-24 22:04:32 +02:00
TraceLoggingWriteWrapper (
2024-05-09 10:32:03 -04:00
g_hProvider ,
" AdvancedPaste_Settings " ,
ProjectTelemetryPrivacyDataTag ( ProjectTelemetryTag_ProductAndServicePerformance ) ,
TraceLoggingKeyword ( PROJECT_KEYWORD_MEASURE ) ,
2024-10-18 15:34:09 +02:00
TraceLoggingWideString ( getHotkeyCStr ( pastePlainHotkey ) , " PastePlainHotkey " ) ,
TraceLoggingWideString ( getHotkeyCStr ( advancedPasteUIHotkey ) , " AdvancedPasteUIHotkey " ) ,
TraceLoggingWideString ( getHotkeyCStr ( pasteMarkdownHotkey ) , " PasteMarkdownHotkey " ) ,
TraceLoggingWideString ( getHotkeyCStr ( pasteJsonHotkey ) , " PasteJsonHotkey " ) ,
2024-12-11 10:28:44 +01:00
TraceLoggingBoolean ( is_advanced_ai_enabled , " IsAdvancedAIEnabled " ) ,
2024-10-18 15:34:09 +02:00
TraceLoggingBoolean ( preview_custom_format_output , " ShowCustomPreview " ) ,
TraceLoggingWideString ( getAdditionalActionHotkeyCStr ( L " ImageToText " ) , " ImageToTextHotkey " ) ,
TraceLoggingWideString ( getAdditionalActionHotkeyCStr ( L " PasteAsTxtFile " ) , " PasteAsTxtFileHotkey " ) ,
TraceLoggingWideString ( getAdditionalActionHotkeyCStr ( L " PasteAsPngFile " ) , " PasteAsPngFileHotkey " ) ,
TraceLoggingWideString ( getAdditionalActionHotkeyCStr ( L " PasteAsHtmlFile " ) , " PasteAsHtmlFileHotkey " )
2024-05-09 10:32:03 -04:00
) ;
}