Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Oct 8, 2024
1 parent d1cee5f commit cf7188a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public App(IServiceProvider serviceProvider)
logger = serviceProvider.GetRequiredService<ILogger<App>>();
this.serviceProvider = serviceProvider;

serviceProvider.GetRequiredService<ExceptionRecorder>().Record(this);
ExceptionHandlingSupport.Initialize(serviceProvider, this);
}

public new void Exit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ namespace Snap.Hutao.Core.ExceptionService;

[ConstructorGenerated]
[Injection(InjectAs.Singleton)]
internal sealed partial class ExceptionRecorder
internal sealed partial class ExceptionHandlingSupport
{
private readonly ILogger<ExceptionRecorder> logger;
private readonly ILogger<ExceptionHandlingSupport> logger;
private readonly IServiceProvider serviceProvider;

public void Record(Application app)
public static void Initialize(IServiceProvider serviceProvider, Application app)
{
serviceProvider.GetRequiredService<ExceptionHandlingSupport>().Attach(app);
}

private void Attach(Application app)
{
app.UnhandledException += OnAppUnhandledException;
ConfigureDebugSettings(app);
Expand Down
9 changes: 9 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3347,6 +3347,15 @@
<data name="ViewWikiWeaponHeader" xml:space="preserve">
<value>武器资料</value>
</data>
<data name="ViewWindowExceptionDescription" xml:space="preserve">
<value>请截图此窗口,在反馈中心内找到适合的反馈途径,并反馈至开发组</value>
</data>
<data name="ViewWindowExceptionHeader" xml:space="preserve">
<value>遇到了无法恢复的致命错误</value>
</data>
<data name="ViewWindowExceptionTitle" xml:space="preserve">
<value>我们遇到了一点问题</value>
</data>
<data name="ViewWindowScriptingExecute" xml:space="preserve">
<value>执行</value>
</data>
Expand Down
4 changes: 2 additions & 2 deletions src/Snap.Hutao/Snap.Hutao/UI/Shell/NotifyIconController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public NotifyIconController(IServiceProvider serviceProvider)
string iconPath = InstalledLocation.GetAbsolutePath("Assets/Logo.ico");

icon = new(iconPath);
id = Unsafe.As<byte, Guid>(ref MemoryMarshal.GetArrayDataReference(MD5.HashData(Encoding.UTF8.GetBytes(iconPath))));
id = MemoryMarshal.AsRef<Guid>(MD5.HashData(Encoding.UTF8.GetBytes(iconPath)).AsSpan());

xamlHostWindow = new(serviceProvider);
xamlHostWindow.MoveAndResize(default);
Expand Down Expand Up @@ -91,7 +91,7 @@ private void OnContextMenuRequested(NotifyIconMessageWindow window, PointUInt16
{
return;
}

xamlHostWindow.ShowFlyoutAt(lazyMenu.Value, new Windows.Foundation.Point(point.X, point.Y), GetRect());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Margin="12,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
Text="我们遇到了一点问题"/>
Text="{shuxm:ResourceString Name=ViewWindowExceptionTitle}"/>
</Grid>
<Grid
Grid.Row="1"
Expand All @@ -33,8 +33,8 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Text="Snap Hutao 遇到了无法恢复的致命错误。"/>
<TextBlock Text="请截图此窗口并反馈至开发组。"/>
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}" Text="{shuxm:ResourceString Name=ViewWindowExceptionHeader}"/>
<TextBlock Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}" Text="{shuxm:ResourceString Name=ViewWindowExceptionDescription}"/>
</StackPanel>
<Border Grid.Row="1" Style="{ThemeResource BorderCardStyle}">
<ScrollViewer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ namespace Snap.Hutao.UI.Xaml.View.Window;

internal sealed partial class ExceptionWindow : Microsoft.UI.Xaml.Window
{
private const string WindowsVersionPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
private const string MajorKey = "CurrentMajorVersionNumber";
private const string MinorKey = "CurrentMinorVersionNumber";
private const string BuildKey = "CurrentBuildNumber";
private const string RevisionKey = "UBR";

private readonly Exception exception;

public ExceptionWindow(Exception exception)
Expand All @@ -31,12 +25,6 @@ public ExceptionWindow(Exception exception)
InitializeComponent();
this.exception = exception;

if (AppWindow.Presenter is OverlappedPresenter presenter)
{
presenter.IsResizable = false;
presenter.IsMaximizable = false;
}

AppWindow.Title = "Snap Hutao Exception Report";

AppWindowTitleBar titleBar = AppWindow.TitleBar;
Expand All @@ -56,22 +44,31 @@ public string FormattedException
{
get
{
using RegistryKey? key = Registry.LocalMachine.OpenSubKey(WindowsVersionPath);
ArgumentNullException.ThrowIfNull(key);
object? major = key.GetValue(MajorKey);
object? minor = key.GetValue(MinorKey);
object? build = key.GetValue(BuildKey);
object? revision = key.GetValue(RevisionKey);
string windowsVersion = $"Windows {major}.{minor}.{build}.{revision}";

return $"""
{windowsVersion}
System Architecture: {RuntimeInformation.OSArchitecture}
Process Architecture: {RuntimeInformation.ProcessArchitecture}
Framework: {RuntimeInformation.FrameworkDescription}

{ExceptionFormat.Format(exception)}
""";
using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
{
string windowsVersion;
if (key is not null)
{
object? major = key.GetValue("CurrentMajorVersionNumber");
object? minor = key.GetValue("CurrentMinorVersionNumber");
object? build = key.GetValue("CurrentBuildNumber");
object? revision = key.GetValue("UBR");
windowsVersion = $"Windows {major}.{minor}.{build}.{revision}";
}
else
{
windowsVersion = "Windows Version Unknown";
}

return $"""
{windowsVersion}
System Architecture: {RuntimeInformation.OSArchitecture}
Process Architecture: {RuntimeInformation.ProcessArchitecture}
Framework: {RuntimeInformation.FrameworkDescription}

{ExceptionFormat.Format(exception)}
""";
}
}
}

Expand Down

0 comments on commit cf7188a

Please sign in to comment.