Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/settings-ui/QuickAccess.UI/QuickAccessXAML/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using ManagedCommon;
using Microsoft.UI.Xaml;

namespace Microsoft.PowerToys.QuickAccess;
Expand All @@ -14,14 +15,26 @@ public partial class App : Application
public App()
{
InitializeComponent();
UnhandledException += App_UnhandledException;
}

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var launchContext = QuickAccessLaunchContext.Parse(Environment.GetCommandLineArgs());
_window = new MainWindow(launchContext);
_window.Closed += OnWindowClosed;
_window.Activate();
try
{
var launchContext = QuickAccessLaunchContext.Parse(Environment.GetCommandLineArgs());
_window = new MainWindow(launchContext);
_window.Closed += OnWindowClosed;
_window.Activate();
}
catch (Exception ex)
{
// Failing here means the flyout host could not be constructed. Log and exit cleanly
// rather than letting the throw bubble out into a stowed XAML failure that crashes
// the runner-owned launcher.
Logger.LogError("QuickAccess: failed to launch flyout host.", ex);
Exit();
}
}

private static void OnWindowClosed(object sender, WindowEventArgs args)
Expand All @@ -33,4 +46,13 @@ private static void OnWindowClosed(object sender, WindowEventArgs args)

_window = null;
}

private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
// QuickAccess is a transient launcher flyout owned by the runner. An unhandled XAML
// exception here would otherwise be stowed and FailFast the process; mark the event
// handled so the next summon can recover. The error is still recorded for diagnostics.
Logger.LogError("QuickAccess: unhandled XAML exception.", e.Exception);
e.Handled = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using ManagedCommon;
using Microsoft.PowerToys.QuickAccess.Services;
using Microsoft.PowerToys.QuickAccess.ViewModels;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Navigation;

namespace Microsoft.PowerToys.QuickAccess.Flyout;

Expand All @@ -22,6 +24,7 @@ public sealed partial class ShellPage : Page
public ShellPage()
{
InitializeComponent();
ContentFrame.NavigationFailed += ContentFrame_NavigationFailed;
}

public void Initialize(IQuickAccessCoordinator coordinator, LauncherViewModel launcherViewModel, AllAppsViewModel allAppsViewModel)
Expand Down Expand Up @@ -65,4 +68,13 @@ internal void RefreshIfAppsList()
appsListPage.ViewModel?.RefreshSettings();
}
}

private static void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
// A page constructor or XAML load failure here would otherwise bubble out of the
// Frame and crash the launcher. Log the failure and mark it handled so the flyout
// can remain available; the next summon will retry navigation.
Logger.LogError($"QuickAccess: navigation to '{e.SourcePageType?.FullName}' failed.", e.Exception);
e.Handled = true;
}
}
Loading