feat: new ErrorView design (#4500)

This commit is contained in:
MistEO
2023-04-27 10:06:36 +08:00
committed by GitHub
7 changed files with 186 additions and 157 deletions

View File

@@ -30,7 +30,7 @@ namespace MaaWpfGui
public void Hyperlink_Click(object sender, RoutedEventArgs e)
{
Hyperlink link = sender as Hyperlink;
if (!string.IsNullOrEmpty(link.NavigateUri.AbsoluteUri))
if (!string.IsNullOrEmpty(link?.NavigateUri?.AbsoluteUri))
{
Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri));
}

View File

@@ -38,23 +38,18 @@ namespace MaaWpfGui.Constants
public const string QQchannel = "https://pd.qq.com/s/4j1ju9z47";
public static string HelpUri
{
get
{
var language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage);
return $"https://maa.plus/docs/{_helpUrl[language]}";
}
}
public static string OverseasAdaptation
private static string language => ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage);
public static string HelpUri => $"https://maa.plus/docs/{_helpUrl[language]}";
public static string OverseasAdaptation => $"https://maa.plus/docs/{_overseasAdaptation[language]}";
public static string NewIssueUri => language switch
{
get
{
var language = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage);
return $"https://maa.plus/docs/{_overseasAdaptation[language]}";
}
}
"zh-cn" => "https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/new?assignees=&labels=bug&template=cn-bug-report.yaml",
_ => "https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/new?assignees=&labels=bug&template=en-bug-report.yaml",
};
private static readonly Dictionary<string, string> _overseasAdaptation = new Dictionary<string, string>
{

View File

@@ -178,7 +178,7 @@ namespace MaaWpfGui.Main
_logger.Fatal(e.Exception, "Unhandled exception");
}
var errorView = new ErrorView(e.Exception.Message, e.Exception.StackTrace, true);
var errorView = new ErrorView(e.Exception, true);
errorView.ShowDialog();
}
}

View File

@@ -440,19 +440,23 @@ The video resolution is required to be 16:9, and there are no interference facto
<!-- Logs -->
<!-- Copilot -->
<!-- AsstProxy -->
<system:String x:Key="ResourceBroken">The resource is damaged, please download the full package again</system:String>
<!-- ErrorView -->
<system:String x:Key="Error">Error</system:String>
<system:String x:Key="ErrorProlog">MAA has encountered an error</system:String>
<system:String x:Key="ErrorDetails">Details</system:String>
<system:String x:Key="ErrorSolution">Solution</system:String>
<system:String x:Key="ErrorSolutionCrash">Please refer to the documentation: FAQ - Crashes to solve.</system:String>
<system:String x:Key="ErrorSolutionReplaceADB">Please use administrator to open MAA</system:String>
<system:String x:Key="ErrorFeedbackLinkText">Create a GitHub issue</system:String>
<system:String x:Key="ErrorQqGroupLinkText">Join QQ Group</system:String>
<system:String x:Key="CopyErrorMessage">Copy error message</system:String>
<!-- AsstProxy -->
<system:String x:Key="ResourceBroken">The resource is damaged, please download the full package again</system:String>
<system:String x:Key="ReplaceADBNotExists">ADB File NOT exists</system:String>
<system:String x:Key="AdbDownloadFailedTitle">ADB Download Failed</system:String>
<system:String x:Key="AdbDownloadFailedDesc">Please do it manually (rename adb.exe and replace the adb file in the emulator)</system:String>
<system:String x:Key="SuccessfullyReplacedADB">Successfully Replaced ADB File</system:String>
<system:String x:Key="ErrorFeedbackLinkText">Create a GitHub issue</system:String>
<system:String x:Key="ErrorQqGroupLinkText">Join QQ Group</system:String>
<system:String x:Key="InitializationError">Initialization error!</system:String>
<system:String x:Key="ResolutionNotSupported">Emulator resolution not supported, please set at least 720P with 16:9 ratio</system:String>
<system:String x:Key="ResolutionAcquisitionFailure">fails to be obtain emulator resolution . Please restart computer or consider try other emulator</system:String>

View File

@@ -442,19 +442,23 @@
<!-- 日志 -->
<!-- 自动战斗 -->
<!-- AsstProxy -->
<system:String x:Key="ResourceBroken">资源损坏,请重新下载完整安装包</system:String>
<!-- ErrorView -->
<system:String x:Key="Error">错误</system:String>
<system:String x:Key="ErrorProlog">MAA 遇到了问题</system:String>
<system:String x:Key="ErrorDetails">详细信息</system:String>
<system:String x:Key="ErrorSolution">解决方案</system:String>
<system:String x:Key="ErrorSolutionCrash">请参考文档:常见问题 - 闪退 进行操作</system:String>
<system:String x:Key="ErrorSolutionReplaceADB">请使用管理员权限打开 MAA 进行操作</system:String>
<system:String x:Key="ErrorFeedbackLinkText">创建 GitHub issue</system:String>
<system:String x:Key="ErrorQqGroupLinkText">加入QQ群反馈问题</system:String>
<system:String x:Key="CopyErrorMessage">复制错误信息</system:String>
<!-- AsstProxy -->
<system:String x:Key="ResourceBroken">资源损坏,请重新下载完整安装包</system:String>
<system:String x:Key="ReplaceADBNotExists">ADB 路径不存在</system:String>
<system:String x:Key="AdbDownloadFailedTitle">ADB 下载失败</system:String>
<system:String x:Key="AdbDownloadFailedDesc">请手动进行操作(将 adb.exe 重命名后替换上方模拟器自带 adb 即可)</system:String>
<system:String x:Key="SuccessfullyReplacedADB">成功替换 ADB 文件</system:String>
<system:String x:Key="ErrorFeedbackLinkText">创建 GitHub issue</system:String>
<system:String x:Key="ErrorQqGroupLinkText">加入QQ群反馈问题</system:String>
<system:String x:Key="InitializationError">初始化错误!</system:String>
<system:String x:Key="ResolutionNotSupported">模拟器分辨率不支持,请设置为 720p 或更高,且为 16:9 比例</system:String>
<system:String x:Key="ResolutionAcquisitionFailure">模拟器分辨率获取失败,建议重启电脑,或更换模拟器后再次尝试</system:String>

View File

@@ -1,5 +1,6 @@
<hc:Window
x:Class="MaaWpfGui.Views.UI.ErrorView"
x:Name="ErrorViewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -10,140 +11,107 @@
xmlns:constants="clr-namespace:MaaWpfGui.Constants"
xmlns:styles="clr-namespace:MaaWpfGui.Styles"
xmlns:controls="clr-namespace:MaaWpfGui.Styles.Controls"
Title="{DynamicResource UnknownErrorOccurs}"
Width="628"
Height="475"
Background="{DynamicResource ErrorViewBackgroundBrush}"
ResizeMode="NoResize"
Title="{DynamicResource Error}"
Width="600"
Height="480"
MinHeight="200"
MinWidth="400"
ResizeMode="CanResize"
Topmost="True"
WindowStartupLocation="CenterScreen"
WindowStyle="SingleBorderWindow"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<controls:TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="75,20,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontWeight="Bold"
Text="{DynamicResource Error}" />
<TextBox
x:Name="Error"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="455"
MaxHeight="40"
Margin="100,45,0,0"
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{DynamicResource ErrorViewBackgroundBrush}"
BorderThickness="0"
Text="{DynamicResource UnknownErrorOccurs}"
TextWrapping="Wrap" />
<RichTextBox x:Name="RichTextBox" Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" BorderThickness="0" IsReadOnly="True" hc:BorderElement.CornerRadius="0" Padding="12, 16, 4, 8">
<RichTextBox.Resources>
<!-- This will give us a LARGER scroll bar -->
<Style TargetType="ScrollViewer">
<Setter Property="hc:ScrollViewerAttach.AutoHide" Value="False"/>
</Style>
</RichTextBox.Resources>
<FlowDocument>
<Section>
<Paragraph>
<Run Text="{DynamicResource ErrorProlog}" FontWeight="Bold"/>
</Paragraph>
<Paragraph Margin="8,0,0,0">
<Run x:Name="Error" Text="{Binding ExceptionMessage, ElementName=ErrorViewWindow, Mode=OneWay}"/>
</Paragraph>
</Section>
<Section>
<Paragraph>
<Run Text="{DynamicResource ErrorSolution}" FontWeight="Bold"/>
</Paragraph>
<Paragraph Margin="8,0,0,0">
<Run x:Name="ErrorSolution" Text="{Binding PossibleSolution, ElementName=ErrorViewWindow, Mode=OneWay}"/>
</Paragraph>
</Section>
<Section>
<Paragraph>
<Run Text="{DynamicResource ErrorDetails}" FontWeight="Bold"/>
</Paragraph>
<Paragraph Margin="8,0,0,0">
<Run x:Name="ErrorDetails" Text="{Binding ExceptionDetails, ElementName=ErrorViewWindow, Mode=OneWay}"/>
</Paragraph>
</Section>
<controls:TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="75,95,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontWeight="Bold"
Text="{DynamicResource ErrorSolution}" />
<TextBox
x:Name="ErrorSolution"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="455"
MaxHeight="150"
Margin="100,120,0,0"
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{DynamicResource ErrorViewBackgroundBrush}"
BorderThickness="0"
Text="{DynamicResource UnknownErrorOccurs}"
TextWrapping="Wrap" />
</FlowDocument>
</RichTextBox>
<controls:TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="75,170,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontWeight="Bold"
Text="{DynamicResource ErrorDetails}" />
<TextBox
x:Name="ErrorDetails"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="455"
MaxHeight="150"
Margin="100,195,0,0"
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{DynamicResource ErrorViewBackgroundBrush}"
BorderThickness="0"
Text="{DynamicResource UnknownErrorOccurs}"
TextWrapping="Wrap" />
<Border Background="{DynamicResource ErrorViewBackgroundBrush}" Grid.Row="1" Padding="12, 0">
<Grid MinHeight="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:TextBlock>
<Hyperlink Name="CopyErrorMessage" Click="CopyErrorMessage_Click">
<Run Text="{DynamicResource CopyErrorMessage}"/>
</Hyperlink>
<hc:Poptip.Instance>
<hc:Poptip x:Name="CopiedTip" hc:Poptip.HitMode="None" Content="{DynamicResource CopiedToClipboard}" />
</hc:Poptip.Instance>
</controls:TextBlock>
<WrapPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right">
<WrapPanel.Resources>
<Style TargetType="controls:TextBlock">
<Setter Property="Margin" Value="12, 0, 0, 0"/>
</Style>
</WrapPanel.Resources>
<controls:TextBlock>
<Hyperlink
Name="LinkToFAQ"
Click="Hyperlink_OnClick"
NavigateUri="{Binding Source={x:Static constants:MaaUrls.HelpUri}}">
<Run Text="{DynamicResource Help}" />
</Hyperlink>
</controls:TextBlock>
<controls:TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Width="129"
Height="23"
Margin="465,350,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Hyperlink
Name="LinkToFAQ"
Click="Hyperlink_OnClick"
FontSize="10.667"
NavigateUri="{Binding Source={x:Static constants:MaaUrls.HelpUri}}">
<Run Text="{DynamicResource Help}" />
</Hyperlink>
</controls:TextBlock>
<controls:TextBlock>
<Hyperlink
Name="LinkToCreateGitHubIssue"
Click="Hyperlink_OnClick"
NavigateUri="{Binding Source={x:Static constants:MaaUrls.NewIssueUri}}">
<Run Text="{DynamicResource ErrorFeedbackLinkText}" />
</Hyperlink>
</controls:TextBlock>
<controls:TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Width="129"
Height="23"
Margin="465,375,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Hyperlink
Name="LinkToCreateGitHubIssue"
Click="Hyperlink_OnClick"
FontSize="10.667"
NavigateUri="{Binding Source={x:Static constants:MaaUrls.GitHubIssues}}">
<Run Text="{DynamicResource ErrorFeedbackLinkText}" />
</Hyperlink>
</controls:TextBlock>
<controls:TextBlock
x:Name="ErrorQqGroupLink"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="71"
Margin="465,400,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontSize="10.667">
<Hyperlink
Name="LinkToJoinQqGroup"
Click="Hyperlink_OnClick"
FontSize="10.667"
NavigateUri="{Binding Source={x:Static constants:MaaUrls.QqGroups}}">
<Run Text="{DynamicResource ErrorQqGroupLinkText}" />
</Hyperlink>
</controls:TextBlock>
<controls:TextBlock x:Name="ErrorQqGroupLink">
<Hyperlink
Name="LinkToJoinQqGroup"
Click="Hyperlink_OnClick"
NavigateUri="{Binding Source={x:Static constants:MaaUrls.QqGroups}}">
<Run Text="{DynamicResource ErrorQqGroupLinkText}" />
</Hyperlink>
</controls:TextBlock>
</WrapPanel>
</Grid>
</Border>
</Grid>
</hc:Window>

View File

@@ -12,9 +12,14 @@
// </copyright>
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
@@ -23,29 +28,56 @@ namespace MaaWpfGui.Views.UI
/// <summary>
/// ErrorView.xaml 的交互逻辑
/// </summary>
public partial class ErrorView
public partial class ErrorView : INotifyPropertyChanged
{
protected bool ShouldExit { get; set; }
public string ExceptionMessage { get; set; }
public string PossibleSolution { get; set; }
public string ExceptionDetails { get; set; }
public ErrorView()
{
InitializeComponent();
}
public ErrorView(string error, string details, bool shouldExit)
public ErrorView(Exception exc, bool shouldExit)
{
InitializeComponent();
Title = error;
Error.Text = error;
ErrorDetails.Text = details;
ErrorSolution.Text = GetSolution(error, details);
var exc0 = exc;
var errorb = new StringBuilder();
while (true)
{
errorb.Append(exc.Message);
exc = exc.InnerException;
if (exc != null)
{
errorb.AppendLine();
}
else
{
break;
}
}
var error = errorb.ToString();
var details = exc0.ToString();
ExceptionMessage = error;
ExceptionDetails = details;
PossibleSolution = GetSolution(error, details);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ExceptionMessage)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PossibleSolution)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ExceptionDetails)));
ShouldExit = shouldExit;
var isZhCn = ConfigurationHelper.GetValue(ConfigurationKeys.Localization, LocalizationHelper.DefaultLanguage) == "zh-cn";
ErrorQqGroupLink.Visibility = isZhCn ? Visibility.Visible : Visibility.Hidden;
ErrorQqGroupLink.Visibility = isZhCn ? Visibility.Visible : Visibility.Collapsed;
}
public event PropertyChangedEventHandler PropertyChanged;
private string GetSolution(string error, string details)
{
if (details.Contains("AsstGetVersion()") || details.Contains("DllNotFoundException") || details.Contains("lambda_method"))
@@ -75,5 +107,31 @@ namespace MaaWpfGui.Views.UI
{
Process.Start(((Hyperlink)sender).NavigateUri.AbsoluteUri);
}
private void CopyToClipboard()
{
var range = new TextRange(RichTextBox.Document.ContentStart, RichTextBox.Document.ContentEnd);
var data = new DataObject();
data.SetText(range.Text);
if (range.CanSave(DataFormats.Rtf))
{
var ms = new MemoryStream();
range.Save(ms, DataFormats.Rtf);
var arr = ms.ToArray();
// Save to RTF doesn't write non-ascii characters (implementation-defined behavior?)
data.SetData(DataFormats.Rtf, Encoding.UTF8.GetString(arr));
}
Clipboard.SetDataObject(data, true);
}
private async void CopyErrorMessage_Click(object sender, RoutedEventArgs e)
{
CopyToClipboard();
CopiedTip.IsOpen = true;
await Task.Delay(3000);
CopiedTip.IsOpen = false;
}
}
}