Skip to content

Commit

Permalink
修复主界面安全模式的问题
Browse files Browse the repository at this point in the history
更新错误处理逻辑
  • Loading branch information
JamXi233 committed Jun 6, 2023
1 parent 146be83 commit efbc1ab
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SRTools/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async void Init()
TerminalMode.HideConsole();
break;
}
Task.Run(() => getNotify.Get()).Wait();
try { Task.Run(() => getNotify.Get()).Wait(); } catch { }
if (localSettings.Values["Config_TerminalMode"] != null)
{
int Mode = (int)localSettings.Values["Config_TerminalMode"];
Expand Down
2 changes: 1 addition & 1 deletion SRTools/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
</StackPanel>

</Grid>
<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" />
<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" VerticalAlignment="Bottom" />
</Grid>

</Window>
1 change: 1 addition & 0 deletions SRTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public MainWindow()

private void InitializeAppData()
{
Windows.ApplicationModel.Core.CoreApplication.UnhandledErrorDetected += OnUnhandledErrorDetected;
//应用数据检查开始
ApplicationDataContainer keyContainer = GetOrCreateContainer(KeyPath);
LocalSettingsData defaultValues = new LocalSettingsData("1", "Null", "Null", "Null");
Expand Down
1 change: 1 addition & 0 deletions SRTools/Views/AboutView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@
</StackPanel>

</Grid>
<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" />
</Grid>
</Page>
15 changes: 15 additions & 0 deletions SRTools/Views/AboutView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public sealed partial class AboutView : Page

public AboutView()
{
Windows.ApplicationModel.Core.CoreApplication.UnhandledErrorDetected += OnUnhandledErrorDetected;
InitializeComponent();
Logging.Write("Switch to AboutView", 0);
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
Expand Down Expand Up @@ -539,5 +540,19 @@ private void Debug_Panic_Click(object sender, RoutedEventArgs e)
{
throw new Exception("异常处理测试");
}

private void OnUnhandledErrorDetected(object sender, Windows.ApplicationModel.Core.UnhandledErrorDetectedEventArgs e)
{
try
{
e.UnhandledError.Propagate();
}
catch (Exception ex)
{
infoBar.IsOpen = true;
infoBar.Title = "灾难性错误";
infoBar.Message = ex.Message;
}
}
}
}
2 changes: 1 addition & 1 deletion SRTools/Views/GachaView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
<SymbolIconSource Symbol="Admin" />
</TeachingTip.IconSource>
</TeachingTip>

<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" />
</Grid>
</Page>
14 changes: 14 additions & 0 deletions SRTools/Views/GachaView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public sealed partial class GachaView : Page
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
public GachaView()
{
Windows.ApplicationModel.Core.CoreApplication.UnhandledErrorDetected += OnUnhandledErrorDetected;
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();

// 创建定时器,并设置回调函数和时间间隔
Expand Down Expand Up @@ -283,6 +284,19 @@ private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelec
}
}

private void OnUnhandledErrorDetected(object sender, Windows.ApplicationModel.Core.UnhandledErrorDetectedEventArgs e)
{
try
{
e.UnhandledError.Propagate();
}
catch (Exception ex)
{
infoBar.IsOpen = true;
infoBar.Title = "灾难性错误";
infoBar.Message = ex.Message;
}
}

private void Window_Closed(object sender, EventArgs e)
{
Expand Down
1 change: 1 addition & 0 deletions SRTools/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private void OnUnhandledErrorDetected(object sender, Windows.ApplicationModel.Co
}
catch (Exception ex)
{
loadRing.Visibility = Visibility.Collapsed;
infoBar.IsOpen = true;
infoBar.Title = "灾难性错误";
infoBar.Message = ex.Message;
Expand Down
2 changes: 1 addition & 1 deletion SRTools/Views/StartGameView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<SymbolIconSource Symbol="Help" />
</TeachingTip.IconSource>
</TeachingTip>

<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" />
</Grid>

</Page>
15 changes: 15 additions & 0 deletions SRTools/Views/StartGameView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public sealed partial class StartGameView : Page

public StartGameView()
{
Windows.ApplicationModel.Core.CoreApplication.UnhandledErrorDetected += OnUnhandledErrorDetected;
this.InitializeComponent();
Logging.Write("Switch to StartGameView",0);
// 获取UI线程的DispatcherQueue
Expand Down Expand Up @@ -234,5 +235,19 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
dispatcherTimer_Launcher.Stop();
Logging.Write("Timer Stopped", 0);
}

private void OnUnhandledErrorDetected(object sender, Windows.ApplicationModel.Core.UnhandledErrorDetectedEventArgs e)
{
try
{
e.UnhandledError.Propagate();
}
catch (Exception ex)
{
infoBar.IsOpen = true;
infoBar.Title = "灾难性错误";
infoBar.Message = ex.Message;
}
}
}
}

0 comments on commit efbc1ab

Please sign in to comment.