From 46d5fcc62a1123dc5d5bcf2f8d0a78a12c677d9e Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Wed, 14 Aug 2024 17:56:34 -0700 Subject: [PATCH 1/4] Log action dispatch occurrence --- .../TerminalApp/ShortcutActionDispatch.cpp | 36 ++++++++++++++++++- .../TerminalSettingsModel/Command.idl | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp index 0d8d2e8dbc6..1796fcee670 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp @@ -19,6 +19,27 @@ using namespace winrt::TerminalApp; namespace winrt::TerminalApp::implementation { + std::wstring ExtractAction(const ActionAndArgs& actionAndArgs) + { + std::wstring id{ actionAndArgs.GenerateID() }; + const auto segment1 = id.find(L'.'); + const auto segment2 = id.find(L'.', segment1 + 1); + if (segment1 != std::wstring::npos) + { + if (segment2 != std::wstring::npos) + { + return id.substr(segment1 + 1, segment2 - segment1 - 1); + } + else + { + return id.substr(segment1 + 1); + } + } + // This shouldn't be possible. + // GenerateID() returns L"User.{}" unless it's invalid + return nullptr; + } + // Method Description: // - Dispatch the appropriate event for the given ActionAndArgs. Constructs // an ActionEventArgs to hold the IActionArgs payload for the event, and @@ -49,7 +70,20 @@ namespace winrt::TerminalApp::implementation default: return false; } - return eventArgs.Handled(); + const auto handled = eventArgs.Handled(); + + if (handled) + { + TraceLoggingWrite( + g_hTerminalAppProvider, + "ActionDispatched", + TraceLoggingDescription("Event emitted when an action was successfully performed"), + TraceLoggingValue(ExtractAction(actionAndArgs).data(), "Action"), + TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), + TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage)); + } + + return handled; } bool ShortcutActionDispatch::DoAction(const ActionAndArgs& actionAndArgs) diff --git a/src/cascadia/TerminalSettingsModel/Command.idl b/src/cascadia/TerminalSettingsModel/Command.idl index a364eabb4dd..cbde1dd32a7 100644 --- a/src/cascadia/TerminalSettingsModel/Command.idl +++ b/src/cascadia/TerminalSettingsModel/Command.idl @@ -30,6 +30,8 @@ namespace Microsoft.Terminal.Settings.Model IActionArgs Args; ShortcutAction Action; + + String GenerateID(); }; [default_interface] runtimeclass Command : ISettingsModelObject From ff4852a28567a3019f06f8a16fe4f7d06bd8ff94 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 20 Aug 2024 10:59:54 -0700 Subject: [PATCH 2/4] simplify! --- .../TerminalApp/ShortcutActionDispatch.cpp | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp index 1796fcee670..92cf900fed3 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp @@ -21,23 +21,15 @@ namespace winrt::TerminalApp::implementation { std::wstring ExtractAction(const ActionAndArgs& actionAndArgs) { - std::wstring id{ actionAndArgs.GenerateID() }; - const auto segment1 = id.find(L'.'); - const auto segment2 = id.find(L'.', segment1 + 1); - if (segment1 != std::wstring::npos) - { - if (segment2 != std::wstring::npos) - { - return id.substr(segment1 + 1, segment2 - segment1 - 1); - } - else - { - return id.substr(segment1 + 1); - } - } - // This shouldn't be possible. - // GenerateID() returns L"User.{}" unless it's invalid - return nullptr; + // Formatted as "User.{action}" or "User.{action}.{hash}" + std::wstring_view remaining{ actionAndArgs.GenerateID() }; + + // Throw away "User." + std::ignore = til::prefix_split(remaining, L'.'); + + // Get the "{action}" part + const auto actionName = til::prefix_split(remaining, L'.'); + return std::wstring{ actionName }; } // Method Description: From 29141815dad1957d9e9454af7fdd4aa70f1efe46 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 20 Aug 2024 11:40:06 -0700 Subject: [PATCH 3/4] string_views are hard --- src/cascadia/TerminalApp/ShortcutActionDispatch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp index 92cf900fed3..cd898f240a2 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp @@ -22,7 +22,8 @@ namespace winrt::TerminalApp::implementation std::wstring ExtractAction(const ActionAndArgs& actionAndArgs) { // Formatted as "User.{action}" or "User.{action}.{hash}" - std::wstring_view remaining{ actionAndArgs.GenerateID() }; + const auto id = actionAndArgs.GenerateID(); + std::wstring_view remaining{ id }; // Throw away "User." std::ignore = til::prefix_split(remaining, L'.'); From d49f4bcf54d52c44123b8f5a2b263705f9da66ed Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 20 Aug 2024 15:31:17 -0700 Subject: [PATCH 4/4] simplify --- .../TerminalApp/ShortcutActionDispatch.cpp | 16 +--------------- src/cascadia/TerminalSettingsModel/Command.idl | 2 -- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp index cd898f240a2..3f7e509ab15 100644 --- a/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp +++ b/src/cascadia/TerminalApp/ShortcutActionDispatch.cpp @@ -19,20 +19,6 @@ using namespace winrt::TerminalApp; namespace winrt::TerminalApp::implementation { - std::wstring ExtractAction(const ActionAndArgs& actionAndArgs) - { - // Formatted as "User.{action}" or "User.{action}.{hash}" - const auto id = actionAndArgs.GenerateID(); - std::wstring_view remaining{ id }; - - // Throw away "User." - std::ignore = til::prefix_split(remaining, L'.'); - - // Get the "{action}" part - const auto actionName = til::prefix_split(remaining, L'.'); - return std::wstring{ actionName }; - } - // Method Description: // - Dispatch the appropriate event for the given ActionAndArgs. Constructs // an ActionEventArgs to hold the IActionArgs payload for the event, and @@ -71,7 +57,7 @@ namespace winrt::TerminalApp::implementation g_hTerminalAppProvider, "ActionDispatched", TraceLoggingDescription("Event emitted when an action was successfully performed"), - TraceLoggingValue(ExtractAction(actionAndArgs).data(), "Action"), + TraceLoggingValue(static_cast(actionAndArgs.Action()), "Action"), TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES), TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage)); } diff --git a/src/cascadia/TerminalSettingsModel/Command.idl b/src/cascadia/TerminalSettingsModel/Command.idl index cbde1dd32a7..a364eabb4dd 100644 --- a/src/cascadia/TerminalSettingsModel/Command.idl +++ b/src/cascadia/TerminalSettingsModel/Command.idl @@ -30,8 +30,6 @@ namespace Microsoft.Terminal.Settings.Model IActionArgs Args; ShortcutAction Action; - - String GenerateID(); }; [default_interface] runtimeclass Command : ISettingsModelObject