From b4d75e3240485864188915c63359cbe0208c66b6 Mon Sep 17 00:00:00 2001 From: ryanbodrug-microsoft <56318517+ryanbodrug-microsoft@users.noreply.github.com> Date: Tue, 5 May 2020 11:44:54 -0700 Subject: [PATCH] Adding telemetry events for Settings Enabled or Disabled Modules --- .../EnabledModules.cs | 169 ++++++++++++++---- ...Microsoft.PowerToys.Settings.UI.Lib.csproj | 1 + .../Telemetry/Events/EnabledModuleEvent.cs | 15 ++ .../MainWindow.xaml.cs | 3 +- 4 files changed, 151 insertions(+), 37 deletions(-) create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/Telemetry/Events/EnabledModuleEvent.cs diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs index 50e271df78..d93717eb56 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs @@ -1,47 +1,144 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace Microsoft.PowerToys.Settings.UI.Lib -{ - public class EnabledModules - { - public EnabledModules() - { - this.FancyZones = false; - this.ImageResizer = false; - this.FileExplorerPreview = false; - this.PowerRename = false; - this.ShortcutGuide = false; - this.PowerLauncher = true; - } +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.CompilerServices; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.PowerToys.Settings.Telemetry; +using Microsoft.PowerToys.Telemetry; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class EnabledModules + { + public EnabledModules() + { + } + + private bool fancyZones = true; [JsonPropertyName("FancyZones")] - public bool FancyZones { get; set; } + public bool FancyZones + { + get => this.fancyZones; + set + { + if (this.fancyZones != value) + { + LogTelemetryEvent(value); + this.fancyZones = value; + } + } + } + + private bool imageResizer = true; [JsonPropertyName("Image Resizer")] - public bool ImageResizer { get; set; } + public bool ImageResizer + { + get => this.imageResizer; + set + { + if (this.imageResizer != value) + { + LogTelemetryEvent(value); + this.imageResizer = value; + } + } + } + + private bool fileExplorerPreview = true; [JsonPropertyName("File Explorer Preview")] - public bool FileExplorerPreview { get; set; } + public bool FileExplorerPreview + { + get => this.fileExplorerPreview; + set + { + if (this.fileExplorerPreview != value) + { + LogTelemetryEvent(value); + this.fileExplorerPreview = value; + } + } + } + + private bool shortcutGuide = true; [JsonPropertyName("Shortcut Guide")] - public bool ShortcutGuide { get; set; } - - public bool PowerRename { get; set; } - - [JsonPropertyName("Keyboard Manager")] - public bool KeyboardManager { get; set; } - - [JsonPropertyName("Run")] - public bool PowerLauncher { get; set; } - - public string ToJsonString() + public bool ShortcutGuide { - return JsonSerializer.Serialize(this); + get => this.shortcutGuide; + set + { + if (this.shortcutGuide != value) + { + LogTelemetryEvent(value); + this.shortcutGuide = value; + } + } } - } + + private bool powerRename = true; + + public bool PowerRename + { + get => this.powerRename; + set + { + if (this.powerRename != value) + { + LogTelemetryEvent(value); + this.powerRename = value; + } + } + } + + private bool keyboardManager = true; + [JsonPropertyName("Keyboard Manager")] + public bool KeyboardManager + { + get => this.keyboardManager; + set + { + if (this.keyboardManager != value) + { + LogTelemetryEvent(value); + this.keyboardManager = value; + } + } + } + + private bool powerLauncher = true; + + [JsonPropertyName("Run")] + public bool PowerLauncher + { + get => this.powerLauncher; + set + { + if (this.powerLauncher != value) + { + LogTelemetryEvent(value); + this.powerLauncher = value; + } + } +} + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + + private void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null ) + { + var dataEvent = new EnabledModuleEvent() + { + Value = value, + ModuleName = moduleName, + }; + PowerToysTelemetry.Log.WriteEvent(dataEvent); + } + } } \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/Microsoft.PowerToys.Settings.UI.Lib.csproj b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Microsoft.PowerToys.Settings.UI.Lib.csproj index db1d040113..b8d8e05ec2 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/Microsoft.PowerToys.Settings.UI.Lib.csproj +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Microsoft.PowerToys.Settings.UI.Lib.csproj @@ -33,6 +33,7 @@ + diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/Telemetry/Events/EnabledModuleEvent.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Telemetry/Events/EnabledModuleEvent.cs new file mode 100644 index 0000000000..658c41adef --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/Telemetry/Events/EnabledModuleEvent.cs @@ -0,0 +1,15 @@ +using System.Diagnostics.Tracing; +using Microsoft.PowerToys.Telemetry; + +namespace Microsoft.PowerToys.Settings.Telemetry +{ + [EventData] + public class EnabledModuleEvent : IEvent + { + public string EventName { get; } = "Settings_EnableModule"; + + public string ModuleName { get; set; } + + public bool Value { get; set; } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs index 3eb5d43604..e6fc42b0d0 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs @@ -29,7 +29,8 @@ namespace Microsoft.PowerToys.Settings.UI.Runner // send IPC Message shellPage.SetDefaultSndMessageCallback(msg => { - Program.GetTwoWayIPCManager().Send(msg); + //IPC Manager is null when launching runner directly + Program.GetTwoWayIPCManager()?.Send(msg); }); // send IPC Message