From cd467785f2cd1b709fa8ff1bad1f4eacf9dcd24e Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Sat, 15 Nov 2025 07:07:52 -0600 Subject: [PATCH] CmdPal: Adding page Id to OpenPage telemetry event (#43584) @niels9001 requested this. As the name says --- .../PageViewModel.cs | 3 +++ .../Microsoft.CmdPal.UI/Events/OpenPage.cs | 5 ++++- .../Pages/ShellPage.xaml.cs | 21 +++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs b/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs index 62434a632a..2a82f80a02 100644 --- a/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs +++ b/src/modules/cmdpal/Core/Microsoft.CmdPal.Core.ViewModels/PageViewModel.cs @@ -64,6 +64,8 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext public string Title { get => string.IsNullOrEmpty(field) ? Name : field; protected set; } = string.Empty; + public string Id { get; protected set; } = string.Empty; + // This property maps to `IPage.IsLoading`, but we want to expose our own // `IsLoading` property as a combo of this value and `IsInitialized` public bool ModelIsLoading { get; protected set; } = true; @@ -142,6 +144,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext return; // throw? } + Id = page.Id; Name = page.Name; ModelIsLoading = page.IsLoading; Title = page.Title; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Events/OpenPage.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Events/OpenPage.cs index 040dd146d0..ac941b7724 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Events/OpenPage.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Events/OpenPage.cs @@ -15,9 +15,12 @@ public class OpenPage : EventBase, IEvent { public int PageDepth { get; set; } - public OpenPage(int pageDepth) + public string Id { get; set; } + + public OpenPage(int pageDepth, string id) { PageDepth = pageDepth; + Id = id; EventName = "CmdPal_OpenPage"; } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs index d009c626e0..e51597d268 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs @@ -21,7 +21,6 @@ using Microsoft.PowerToys.Telemetry; using Microsoft.UI.Dispatching; using Microsoft.UI.Input; using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media.Animation; @@ -160,7 +159,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page, new AsyncNavigationRequest(message.Page, message.CancellationToken), message.WithAnimation ? DefaultPageAnimation : _noAnimation); - PowerToysTelemetry.Log.WriteEvent(new OpenPage(RootFrame.BackStackDepth)); + PowerToysTelemetry.Log.WriteEvent(new OpenPage(RootFrame.BackStackDepth, message.Page.Id)); if (!ViewModel.IsNested) { @@ -655,15 +654,15 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page, e.Handled = true; break; default: - { - // The CommandBar is responsible for handling all the item keybindings, - // since the bound context item may need to then show another - // context menu - TryCommandKeybindingMessage msg = new(ctrlPressed, altPressed, shiftPressed, winPressed, e.Key); - WeakReferenceMessenger.Default.Send(msg); - e.Handled = msg.Handled; - break; - } + { + // The CommandBar is responsible for handling all the item keybindings, + // since the bound context item may need to then show another + // context menu + TryCommandKeybindingMessage msg = new(ctrlPressed, altPressed, shiftPressed, winPressed, e.Key); + WeakReferenceMessenger.Default.Send(msg); + e.Handled = msg.Handled; + break; + } } }