Compare commits

..

1 Commits

Author SHA1 Message Date
Muyuan Li (from Dev Box)
12e9ee42ca fix(Settings): handle null Exception in Frame_NavigationFailed to prevent NullReferenceException
When NavigationFailedEventArgs.Exception is null, the original code threw a
NullReferenceException instead of a meaningful error. Use null-coalescing to
throw an InvalidOperationException with context about the failed page.
2026-04-29 17:56:18 +08:00
2 changed files with 3 additions and 10 deletions

View File

@@ -655,15 +655,7 @@ public sealed partial class MainWindow : WindowEx,
// Once we're done, uncloak to avoid all animations
Uncloak();
// Use StealForeground to reliably bring the window to the foreground.
// A plain SetForegroundWindow call can fail when the process does not
// hold the foreground lock (e.g. when summoned via Quick Access or a
// named-event trigger while another app is in the foreground).
// StealForeground uses AttachThreadInput to temporarily borrow the
// foreground thread's input context, which gives us permission to call
// SetForegroundWindow regardless of which process currently owns the
// foreground.
StealForeground();
PInvoke.SetForegroundWindow(hwnd);
PInvoke.SetActiveWindow(hwnd);
// Push our window to the top of the Z-order and make it the topmost, so that it appears above all other windows.

View File

@@ -135,7 +135,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw e.Exception;
throw e.Exception ?? new InvalidOperationException(
$"Navigation to {e.SourcePageType?.FullName ?? "unknown page"} failed.");
}
private void Frame_Navigated(object sender, NavigationEventArgs e)