-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: AOT json serialization crash issue
- Loading branch information
Showing
7 changed files
with
123 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Web; | ||
using Avalonia.Controls; | ||
using Avalonia.Threading; | ||
using MsBox.Avalonia; | ||
using MsBox.Avalonia.Dto; | ||
using MsBox.Avalonia.Models; | ||
using SubRenamer.Services; | ||
|
||
namespace SubRenamer.Helper; | ||
|
||
public class IssueReporter | ||
{ | ||
public static void CheckCrashAndShowDialog() | ||
{ | ||
Dispatcher.UIThread.Post(async () => | ||
{ | ||
if (!File.Exists(App.CrashLogFile)) return; | ||
var crashLog = await File.ReadAllTextAsync(App.CrashLogFile); | ||
var title = crashLog.Split('\n').FirstOrDefault() ?? ""; | ||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams | ||
{ | ||
ButtonDefinitions = new List<ButtonDefinition> | ||
{ | ||
new ButtonDefinition { Name = "反馈问题", IsDefault = true }, | ||
new ButtonDefinition { Name = "忽略", IsCancel = true } | ||
}, | ||
ContentTitle = "检测到程序崩溃 x_x", | ||
ContentMessage = $"{title}\n\n点击下方按钮反馈错误报告", | ||
Icon = MsBox.Avalonia.Enums.Icon.Warning, | ||
WindowStartupLocation = WindowStartupLocation.CenterScreen, | ||
CanResize = false, | ||
MaxWidth = 500, | ||
MaxHeight = 800, | ||
ShowInCenter = true, | ||
Topmost = true | ||
}); | ||
var result = await box.ShowAsync(); | ||
if (result == "反馈问题") | ||
{ | ||
CreateGitHubIssue(title, $"{crashLog}\n\nWheel: {SystemInfo.GetOSArchPair()} Version: v{Config.AppVersion}"); | ||
} | ||
// rename CrashLog | ||
File.Move(App.CrashLogFile, Path.Combine(Config.ConfigDir, $"crash.{DateTime.Now:yyyyMMddHHmmss}.solved.log")); | ||
}, DispatcherPriority.Background); | ||
} | ||
|
||
public static void CreateGitHubIssue(Exception e) | ||
{ | ||
CreateGitHubIssue(e.Message, e.StackTrace ?? ""); | ||
} | ||
|
||
public static void CreateGitHubIssue(string caption, string details) | ||
{ | ||
var title = $"[CRASH][{"v" + Config.AppVersion}] {caption}"; | ||
BrowserHelper.OpenBrowserAsync( | ||
$"https://github.com/qwqcode/SubRenamer/issues/new?title={HttpUtility.UrlEncode(title, Encoding.UTF8)}&body={HttpUtility.UrlEncode(caption + "\n\n```\n" + details + "\n```", Encoding.UTF8)}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace SubRenamer.Helper; | ||
|
||
public class SystemInfo | ||
{ | ||
public static string GetOSArchPair() | ||
{ | ||
return $"{GetOSName()}_{GetArchName()}"; | ||
} | ||
|
||
public static string GetOSName() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return "windows"; | ||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return "macos"; | ||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return "linux"; | ||
else return "unknown"; | ||
} | ||
|
||
public static string GetArchName() | ||
{ | ||
return RuntimeInformation.OSArchitecture switch | ||
{ | ||
Architecture.X64 => "amd64", | ||
Architecture.Arm64 => "arm64", | ||
_ => "unknown" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters