add:崩溃后操作

This commit is contained in:
CJK_mkp
2025-06-12 10:13:47 +08:00
parent 661fd21626
commit 0e5b31a8e4
6 changed files with 3744 additions and 3612 deletions
+24
View File
@@ -27,11 +27,28 @@ namespace Ink_Canvas
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
}
// 增加字段保存崩溃后操作设置
public static CrashActionType CrashAction = CrashActionType.SilentRestart;
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
Ink_Canvas.MainWindow.ShowNewMessage("抱歉,出现未预期的异常,可能导致 InkCanvasForClass 运行不稳定。\n建议保存墨迹后重启应用。", true);
LogHelper.NewLog(e.Exception.ToString());
e.Handled = true;
// 新增:根据设置自动处理崩溃
if (CrashAction == CrashActionType.SilentRestart)
{
try
{
// 静默重启:启动新进程并退出当前进程
string exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
System.Diagnostics.Process.Start(exePath);
}
catch { }
Environment.Exit(1);
}
// CrashActionType.NoAction 时不做处理
}
private TaskbarIcon _taskbar;
@@ -75,5 +92,12 @@ namespace Ink_Canvas
}
catch { }
}
// 新增:用于设置崩溃后操作类型
public enum CrashActionType
{
SilentRestart,
NoAction
}
}
}
+19
View File
@@ -361,6 +361,25 @@
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
</GroupBox>
<!-- 新增:崩溃后操作设置 -->
<GroupBox>
<GroupBox.Header>
<TextBlock Margin="0,12,0,0" Text="崩溃后操作" FontWeight="Bold" Foreground="#fafafa"
FontSize="26" />
</GroupBox.Header>
<ui:SimpleStackPanel Spacing="6">
<TextBlock Text="请选择软件发生未处理异常时的自动操作:" Foreground="#a1a1aa" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,4,0,0">
<RadioButton x:Name="RadioCrashSilentRestart" GroupName="CrashAction"
Content="静默重启软件" FontSize="14" Margin="0,0,24,0"
Checked="RadioCrashAction_Checked"/>
<RadioButton x:Name="RadioCrashNoAction" GroupName="CrashAction"
Content="无操作" FontSize="14"
Checked="RadioCrashAction_Checked"/>
</StackPanel>
<TextBlock Text="# 静默重启:崩溃后自动重启软件,无提示。无操作:崩溃后仅记录日志,不自动重启。" Foreground="#a1a1aa" />
</ui:SimpleStackPanel>
</GroupBox>
<GroupBox>
<GroupBox.Header>
<TextBlock Margin="0,12,0,0" Text="手势" FontWeight="Bold" Foreground="#fafafa"
+21
View File
@@ -214,6 +214,12 @@ namespace Ink_Canvas {
{
FoldFloatingBar_MouseUp(null, null);
}
// 恢复崩溃后操作设置
if (App.CrashAction == App.CrashActionType.SilentRestart)
RadioCrashSilentRestart.IsChecked = true;
else
RadioCrashNoAction.IsChecked = true;
}
private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e) {
@@ -321,6 +327,21 @@ namespace Ink_Canvas {
}
}
// 新增:崩溃后操作设置按钮事件
private void RadioCrashAction_Checked(object sender, RoutedEventArgs e)
{
if (RadioCrashSilentRestart != null && RadioCrashSilentRestart.IsChecked == true)
{
App.CrashAction = App.CrashActionType.SilentRestart;
}
else if (RadioCrashNoAction != null && RadioCrashNoAction.IsChecked == true)
{
App.CrashAction = App.CrashActionType.NoAction;
}
// 可选:保存到配置文件
// SaveSettingsToFile();
}
#endregion Definations and Loading
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff