From 51041f0f8395348968bd907741960caa8b9e53c8 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Fri, 6 Sep 2019 15:30:16 +0200 Subject: [PATCH] Added App Center events for the export of screenshot, this only stored which export was used and no sensitive information. --- .../Extensions/DestinationExtensions.cs | 2 +- src/Greenshot/Helpers/AppCenterExtensions.cs | 32 +++++++++++++++++++ src/Greenshot/Helpers/CaptureHelper.cs | 9 ++++-- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/Greenshot/Helpers/AppCenterExtensions.cs diff --git a/src/Greenshot.Addons/Extensions/DestinationExtensions.cs b/src/Greenshot.Addons/Extensions/DestinationExtensions.cs index fc6628edc..18a1c465f 100644 --- a/src/Greenshot.Addons/Extensions/DestinationExtensions.cs +++ b/src/Greenshot.Addons/Extensions/DestinationExtensions.cs @@ -45,7 +45,7 @@ namespace Greenshot.Addons.Extensions /// Find the matching IDestination /// /// IEnumerable of IDestination - /// strng with the destination + /// string with the destination /// IDestination or null public static IDestination Find(this IEnumerable destinations, string destination) { diff --git a/src/Greenshot/Helpers/AppCenterExtensions.cs b/src/Greenshot/Helpers/AppCenterExtensions.cs new file mode 100644 index 000000000..996c60fbf --- /dev/null +++ b/src/Greenshot/Helpers/AppCenterExtensions.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using Greenshot.Addons.Interfaces; +using Microsoft.AppCenter.Analytics; + +namespace Greenshot.Helpers +{ + public static class AppCenterExtensions + { + public static void HandleAppCenterEvent(this ExportInformation exportInformation) + { + if (exportInformation == null) + { + return; + } + + if (exportInformation.IsError) + { + Analytics.TrackEvent("ExportError", new Dictionary { + { "DestinationDescription", exportInformation.DestinationDescription }, + { "Destination", exportInformation.DestinationDesignation}, + { "ErrorMessage", exportInformation.ErrorMessage} + }); + return; + } + + Analytics.TrackEvent("Export", new Dictionary { + { "DestinationDescription", exportInformation.DestinationDescription }, + { "Destination", exportInformation.DestinationDesignation} + }); + } + } +} diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index 3c0e04588..21a1014f8 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -433,11 +433,11 @@ namespace Greenshot.Helpers { if (filename.ToLower().EndsWith("." + OutputFormats.greenshot)) { - var surface = ImageOutput.SurfaceFactory(); surface = ImageOutput.LoadGreenshotSurface(filename, surface); surface.CaptureDetails = _capture.CaptureDetails; - _destinationHolder.SortedActiveDestinations.Find("Editor")?.ExportCaptureAsync(true, surface, _capture.CaptureDetails).Wait(); + var exportInformation = _destinationHolder.SortedActiveDestinations.Find("Editor")?.ExportCaptureAsync(true, surface, _capture.CaptureDetails).Result; + exportInformation.HandleAppCenterEvent(); break; } } @@ -627,7 +627,9 @@ namespace Greenshot.Helpers if (captureDetails.HasDestination(typeof(PickerDestination).GetDesignation())) { - _destinationHolder.SortedActiveDestinations.Find(typeof(PickerDestination))?.ExportCaptureAsync(false, surface, captureDetails).Wait(); + var exportInformation = _destinationHolder.SortedActiveDestinations.Find(typeof(PickerDestination))?.ExportCaptureAsync(false, surface, captureDetails).Result; + exportInformation.HandleAppCenterEvent(); + captureDetails.CaptureDestinations.Clear(); canDisposeSurface = false; } @@ -652,6 +654,7 @@ namespace Greenshot.Helpers Log.Info().WriteLine("Calling destination {0}", destination.Description); var exportInformation = destination.ExportCaptureAsync(false, surface, captureDetails).Result; + exportInformation.HandleAppCenterEvent(); if ("Editor".Equals(destination.Designation) && exportInformation.ExportMade) { canDisposeSurface = false;