Browse Source

Clarified SendExceptionInfoToWebhook is async

CPKreuz 1 year ago
parent
commit
0634755138

+ 1 - 1
src/PixiEditor/App.xaml.cs

@@ -53,7 +53,7 @@ internal partial class App : Application
             {
                 try
                 {
-                    CrashHelper.SendExceptionInfoToWebhook(exception);
+                    CrashHelper.SendExceptionInfoToWebhook(exception, true);
                 }
                 finally
                 {

+ 13 - 3
src/PixiEditor/Helpers/CrashHelper.cs

@@ -112,14 +112,24 @@ internal class CrashHelper
         }
     }
 
-    public static async Task SendExceptionInfoToWebhook(Exception e, [CallerFilePath] string filePath = "<unknown>", [CallerMemberName] string memberName = "<unknown>")
+    public static void SendExceptionInfoToWebhook(Exception e, bool wait = false,
+        [CallerFilePath] string filePath = "<unknown>", [CallerMemberName] string memberName = "<unknown>")
+    {
+        var task = Task.Run(() => SendExceptionInfoToWebhookAsync(e, filePath, memberName));
+        if (wait)
+        {
+            task.Wait();
+        }
+    }
+
+    public static async Task SendExceptionInfoToWebhookAsync(Exception e, [CallerFilePath] string filePath = "<unknown>", [CallerMemberName] string memberName = "<unknown>")
     {
         if (DebugViewModel.IsDebugBuild)
             return;
-        await SendReportTextToWebhook(CrashReport.Generate(e), $"{filePath}; Method {memberName}");
+        await SendReportTextToWebhookAsync(CrashReport.Generate(e), $"{filePath}; Method {memberName}");
     }
 
-    public static async Task SendReportTextToWebhook(CrashReport report, string catchLocation = null)
+    public static async Task SendReportTextToWebhookAsync(CrashReport report, string catchLocation = null)
     {
         string reportText = report.ReportText;
         if (catchLocation is not null)

+ 2 - 2
src/PixiEditor/Models/AppExtensions/ExtensionLoader.cs

@@ -49,7 +49,7 @@ internal class ExtensionLoader
         }
         catch (Exception ex)
         {
-            Task.Run(async () => await CrashHelper.SendExceptionInfoToWebhook(ex));
+            CrashHelper.SendExceptionInfoToWebhook(ex);
         }
     }
 
@@ -86,7 +86,7 @@ internal class ExtensionLoader
         catch (Exception ex)
         {
             //MessageBox.Show(new LocalizedString("ERROR_LOADING_PACKAGE", packageJsonPath), "ERROR");
-            Task.Run(async () => await CrashHelper.SendExceptionInfoToWebhook(ex));
+            CrashHelper.SendExceptionInfoToWebhook(ex);
         }
     }
 

+ 0 - 14
src/PixiEditor/Models/DataHolders/CrashFilePathInfo.cs

@@ -1,14 +0,0 @@
-namespace PixiEditor.Models.DataHolders;
-
-public class CrashFilePathInfo
-{
-    public string? OriginalPath { get; set; }
-    
-    public string? AutosavePath { get; set; }
-    
-    public CrashFilePathInfo(string originalPath, string autosavePath)
-    {
-        OriginalPath = originalPath;
-        AutosavePath = autosavePath;
-    }
-}

+ 1 - 1
src/PixiEditor/ViewModels/CrashReportViewModel.cs

@@ -43,7 +43,7 @@ internal class CrashReportViewModel : ViewModelBase
         AttachDebuggerCommand = new(AttachDebugger);
 
         if (!IsDebugBuild)
-            _ = CrashHelper.SendReportTextToWebhook(report);
+            _ = CrashHelper.SendReportTextToWebhookAsync(report);
     }
 
     public void RecoverDocuments(object args)

+ 2 - 2
src/PixiEditor/ViewModels/SubViewModels/Main/MiscViewModel.cs

@@ -20,7 +20,7 @@ internal class MiscViewModel : SubViewModel<ViewModelMain>
     [Command.Basic("PixiEditor.Links.OpenRepository", "https://github.com/PixiEditor/PixiEditor", "REPOSITORY", "OPEN_REPOSITORY", IconPath = "Globe.png")]
     [Command.Basic("PixiEditor.Links.OpenLicense", "https://github.com/PixiEditor/PixiEditor/blob/master/LICENSE", "LICENSE", "OPEN_LICENSE", IconPath = "Globe.png")]
     [Command.Basic("PixiEditor.Links.OpenOtherLicenses", "https://pixieditor.net/docs/Third-party-licenses", "THIRD_PARTY_LICENSES", "OPEN_THIRD_PARTY_LICENSES", IconPath = "Globe.png")]
-    public static async Task OpenHyperlink(string url)
+    public static void OpenHyperlink(string url)
     {
         try
         {
@@ -28,8 +28,8 @@ internal class MiscViewModel : SubViewModel<ViewModelMain>
         }
         catch (Exception e)
         {
+            CrashHelper.SendExceptionInfoToWebhook(e);
             NoticeDialog.Show(title: "Error", message: $"Couldn't open the address {url} in your default browser");
-            await CrashHelper.SendExceptionInfoToWebhook(e);
         }
     }
 }

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/Main/UpdateViewModel.cs

@@ -222,7 +222,7 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
             }
             catch (Exception e)
             {
-                CrashHelper.SendExceptionInfoToWebhook(e);
+                CrashHelper.SendExceptionInfoToWebhookAsync(e);
                 NoticeDialog.Show("COULD_NOT_CHECK_FOR_UPDATES", "UPDATE_CHECK_FAILED");
             }
 

+ 1 - 1
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -238,7 +238,7 @@ internal partial class HelloTherePopup : Window
         {
             IsFetchingNews = false;
             FailedFetchingNews = true;
-            await CrashHelper.SendExceptionInfoToWebhook(ex);
+            await CrashHelper.SendExceptionInfoToWebhookAsync(ex);
         }
     }
 }

+ 1 - 1
src/PixiEditor/Views/MainWindow.xaml.cs

@@ -146,7 +146,7 @@ internal partial class MainWindow : Window
             }
             catch (Exception e)
             {
-                Task.Run(() => CrashHelper.SendExceptionInfoToWebhook(e)).Wait();
+                CrashHelper.SendExceptionInfoToWebhook(e, true);
                 throw;
             }
         }