Skip to content

Fix: Handle exceptions when opening files from IFileActivatedEventArgs #17356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2025
Merged
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
44 changes: 30 additions & 14 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,39 @@ 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());
else
Win32Helper.BringToForegroundEx(new(WindowHandle));
}
break;

Expand Down
Loading