From 0a3daece633262ed4efed026334196c8e6770b54 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Wed, 30 Jul 2025 01:19:21 +0000 Subject: [PATCH 1/2] Fix: Handle exceptions when opening files from IFileActivatedEventArgs --- src/Files.App/MainWindow.xaml.cs | 42 +++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 6dcfc8b56310..1de1b219962c 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -160,23 +160,37 @@ public async Task InitializeApplicationAsync(object activatedEventArgs) break; case IFileActivatedEventArgs fileArgs: - var index = 0; - if (rootFrame.Content is null || rootFrame.Content is SplashScreenPage || !MainPageViewModel.AppInstances.Any()) + try { - // When the navigation stack isn't restored navigate to the first page, - // configuring the new page by passing required information as a navigation parameter - rootFrame.Navigate(typeof(MainPage), fileArgs.Files.First().Path, new SuppressNavigationTransitionInfo()); - index = 1; - } - else - { - // Bring to foreground (#14730) - Win32Helper.BringToForegroundEx(new(WindowHandle)); - } + if (fileArgs.Files is null || fileArgs.Files.Count == 0) + { + break; + } + + var index = 0; + if (rootFrame.Content is null || rootFrame.Content is SplashScreenPage || !MainPageViewModel.AppInstances.Any()) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation parameter + rootFrame.Navigate(typeof(MainPage), fileArgs.Files.First().Path, new SuppressNavigationTransitionInfo()); + index = 1; + } + else + { + // Bring to foreground (#14730) + Win32Helper.BringToForegroundEx(new(WindowHandle)); + } - for (; index < fileArgs.Files.Count; index++) + for (; index < fileArgs.Files.Count; index++) + { + await NavigationHelpers.AddNewTabByPathAsync(typeof(ShellPanesPage), fileArgs.Files[index].Path, true); + } + } + catch (Exception ex) { - await NavigationHelpers.AddNewTabByPathAsync(typeof(ShellPanesPage), fileArgs.Files[index].Path, true); + App.Logger.LogWarning(ex, "Failed to open files."); + if (rootFrame.Content is null || rootFrame.Content is SplashScreenPage || !MainPageViewModel.AppInstances.Any()) + rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); } break; From 5d04b9735498d5f04f378816ed70d16de8b5acaf Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Thu, 31 Jul 2025 10:29:05 -0400 Subject: [PATCH 2/2] Update src/Files.App/MainWindow.xaml.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com> --- src/Files.App/MainWindow.xaml.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs index 1de1b219962c..3d0ffc2a36b9 100644 --- a/src/Files.App/MainWindow.xaml.cs +++ b/src/Files.App/MainWindow.xaml.cs @@ -191,6 +191,8 @@ public async Task InitializeApplicationAsync(object activatedEventArgs) App.Logger.LogWarning(ex, "Failed to open files."); if (rootFrame.Content is null || rootFrame.Content is SplashScreenPage || !MainPageViewModel.AppInstances.Any()) rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo()); + else + Win32Helper.BringToForegroundEx(new(WindowHandle)); } break;