Browse Source

Don't send analytics on repeated shortcut press

CPKreuz 1 year ago
parent
commit
ba407ae178

+ 2 - 2
src/PixiEditor/Models/AnalyticsAPI/Analytics.cs

@@ -41,8 +41,8 @@ public static class Analytics
         SendEvent(AnalyticEventTypes.SwitchTool, ("NewTool", newTool?.ToolName), ("OldTool", oldTool?.ToolName), ("Source", sourceInfo));
 
     internal static AnalyticEvent? SendCommand(string commandName, ICommandExecutionSourceInfo? source) =>
-        SendEvent(AnalyticEventTypes.GeneralCommand, ("CommandName", commandName), ("Source", source));
-    
+        source is ShortcutSourceInfo { IsRepeat: true } ? null : SendEvent(AnalyticEventTypes.GeneralCommand, ("CommandName", commandName), ("Source", source));
+
     private static AnalyticEvent? SendEvent(string name, params (string, object)[] data) =>
         SendEvent(name, data.ToDictionary());
 

+ 5 - 3
src/PixiEditor/Models/Commands/CommandContext/ShortcutSourceInfo.cs

@@ -2,12 +2,14 @@
 
 namespace PixiEditor.Models.Commands.CommandContext;
 
-public class ShortcutSourceInfo(KeyCombination shortcut) : ICommandExecutionSourceInfo
+public class ShortcutSourceInfo(KeyCombination shortcut, bool isRepeat) : ICommandExecutionSourceInfo
 {
     public CommandExecutionSourceType SourceType => CommandExecutionSourceType.Shortcut;
 
     public KeyCombination Shortcut { get; } = shortcut;
 
-    public static CommandExecutionContext GetContext(KeyCombination shortcut) =>
-        new(null, new ShortcutSourceInfo(shortcut));
+    public bool IsRepeat { get; set; } = isRepeat;
+
+    public static CommandExecutionContext GetContext(KeyCombination shortcut, bool isRepeat) =>
+        new(null, new ShortcutSourceInfo(shortcut, isRepeat));
 }

+ 2 - 2
src/PixiEditor/Models/Controllers/ShortcutController.cs

@@ -48,7 +48,7 @@ internal class ShortcutController
         return CommandController.Current.Commands.First(x => x is Command.ToolCommand tool && tool.ToolType == type).Shortcut;
     }
 
-    public void KeyPressed(Key key, KeyModifiers modifiers)
+    public void KeyPressed(bool isRepeat, Key key, KeyModifiers modifiers)
     {
         KeyCombination shortcut = new(key, modifiers);
 
@@ -66,7 +66,7 @@ internal class ShortcutController
 
         LastCommands = commands;
 
-        var context = ShortcutSourceInfo.GetContext(shortcut);
+        var context = ShortcutSourceInfo.GetContext(shortcut, isRepeat);
         foreach (var command in commands)
         {
             command.Execute(context, false);

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/IoViewModel.cs

@@ -126,7 +126,7 @@ internal class IoViewModel : SubViewModel<ViewModelMain>
             Owner.ToolsSubViewModel.HandleToolRepeatShortcutDown();
         }
 
-        Owner.ShortcutController.KeyPressed(key, argsModifiers);
+        Owner.ShortcutController.KeyPressed(isRepeat, key, argsModifiers);
     }
 
     private void OnKeyUp(object? sender, FilteredKeyEventArgs args)