From 048724a942079bcc5b0c3839b9a002db386ce3de Mon Sep 17 00:00:00 2001 From: GabrielDuf Date: Mon, 13 Apr 2026 15:41:02 -0400 Subject: [PATCH 1/7] Migrate crash report to devolutions cloud --- src/UniGetUI/App.xaml.cs | 18 ++++++ src/UniGetUI/AutoUpdater.cs | 1 + src/UniGetUI/CrashHandler.cs | 34 +++++------ src/UniGetUI/CrashReportWindow.xaml | 72 +++++++++++++++++++++++ src/UniGetUI/CrashReportWindow.xaml.cs | 80 ++++++++++++++++++++++++++ 5 files changed, 186 insertions(+), 19 deletions(-) create mode 100644 src/UniGetUI/CrashReportWindow.xaml create mode 100644 src/UniGetUI/CrashReportWindow.xaml.cs diff --git a/src/UniGetUI/App.xaml.cs b/src/UniGetUI/App.xaml.cs index 970f5826cb..745c564df1 100644 --- a/src/UniGetUI/App.xaml.cs +++ b/src/UniGetUI/App.xaml.cs @@ -332,6 +332,24 @@ private async Task LoadComponentsAsync() // Create MainWindow InitializeMainWindow(); + MainWindow.Activate(); + + // Show crash report from the previous session on top of the loading + // screen and wait for the user to dismiss it before continuing. + if (File.Exists(CrashHandler.PendingCrashFile)) + { + try + { + string report = File.ReadAllText(CrashHandler.PendingCrashFile); + File.Delete(CrashHandler.PendingCrashFile); + var tcs = new TaskCompletionSource(); + var crashWindow = new CrashReportWindow(report); + crashWindow.Closed += (_, _) => tcs.TrySetResult(); + crashWindow.Activate(); + await tcs.Task; + } + catch { /* must not prevent normal startup */ } + } IEnumerable iniTasks = [ diff --git a/src/UniGetUI/AutoUpdater.cs b/src/UniGetUI/AutoUpdater.cs index f5b58d8430..af157652d5 100644 --- a/src/UniGetUI/AutoUpdater.cs +++ b/src/UniGetUI/AutoUpdater.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +using System.Text.Json; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.Windows.AppNotifications; diff --git a/src/UniGetUI/CrashHandler.cs b/src/UniGetUI/CrashHandler.cs index 2f810d7fa1..a63306d1ac 100644 --- a/src/UniGetUI/CrashHandler.cs +++ b/src/UniGetUI/CrashHandler.cs @@ -1,7 +1,6 @@ using System.Diagnostics; -using System.Runtime.InteropServices.JavaScript; +using System.Runtime.InteropServices; using System.Text; -using Microsoft.UI.Xaml.Markup; using UniGetUI.Core.Data; using UniGetUI.Core.Tools; @@ -9,6 +8,8 @@ namespace UniGetUI; public static class CrashHandler { + public static readonly string PendingCrashFile = + Path.Combine(Path.GetTempPath(), "UniGetUI_pending_crash.txt"); private const uint MB_ICONSTOP = 0x00000010; private const uint MB_OKCANCEL = 0x00000001; private const uint MB_YESNOCANCEL = 0x00000003; @@ -16,12 +17,10 @@ public static class CrashHandler private const int IDYES = 6; private const int IDNO = 7; - [System.Runtime.InteropServices.DllImport( - "user32.dll", - CharSet = System.Runtime.InteropServices.CharSet.Unicode - )] + [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType); + // ── Missing-files handler ───────────────────────────────────────────────── private static void _reportMissingFiles(out bool showDetailedReport) { try @@ -206,19 +205,16 @@ Inner exception details (depth level: {{i}}) Console.WriteLine(Error_String); - string ErrorUrl = - $"https://www.marticliment.com/error-report/" - + $"?appName=UniGetUI" - + $"&appVersion={Uri.EscapeDataString(CoreData.VersionName)}" - + $"&buildNumber={Uri.EscapeDataString(CoreData.BuildNumber.ToString())}" - + $"&errorBody={Uri.EscapeDataString(Error_String)}"; - Console.WriteLine(ErrorUrl); - - using Process p = new(); - p.StartInfo.FileName = ErrorUrl; - p.StartInfo.CreateNoWindow = true; - p.StartInfo.UseShellExecute = true; - p.Start(); + // Persist crash data so the next normal app launch can show the report. + try + { + File.WriteAllText(PendingCrashFile, Error_String, Encoding.UTF8); + } + catch + { + // If we can't write the file, nothing more we can do — just exit. + } + Environment.Exit(1); } } diff --git a/src/UniGetUI/CrashReportWindow.xaml b/src/UniGetUI/CrashReportWindow.xaml new file mode 100644 index 0000000000..d9466e6816 --- /dev/null +++ b/src/UniGetUI/CrashReportWindow.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + +