From 7ad94e419f8341291e2686b5809a428e04569609 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:06:21 -0400 Subject: [PATCH] Fix: Fixed DirectoryNotFoundException when pinning items to the start menu --- src/Files.App/Actions/Start/PinToStartAction.cs | 13 ++++++++----- src/Files.App/Actions/Start/UnpinFromStartAction.cs | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Files.App/Actions/Start/PinToStartAction.cs b/src/Files.App/Actions/Start/PinToStartAction.cs index 55f93e5f4e8d..ccecead66d62 100644 --- a/src/Files.App/Actions/Start/PinToStartAction.cs +++ b/src/Files.App/Actions/Start/PinToStartAction.cs @@ -37,12 +37,15 @@ public async Task ExecuteAsync(object? parameter = null) { foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems) { - IStorable storable = listedItem.IsFolder switch + await SafetyExtensions.IgnoreExceptions(async () => { - true => await StorageService.GetFolderAsync(listedItem.ItemPath), - _ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath) - }; - await StartMenuService.PinAsync(storable, listedItem.Name); + IStorable storable = listedItem.IsFolder switch + { + true => await StorageService.GetFolderAsync(listedItem.ItemPath), + _ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath) + }; + await StartMenuService.PinAsync(storable, listedItem.Name); + }); } } else if (context.ShellPage?.ShellViewModel?.CurrentFolder is not null) diff --git a/src/Files.App/Actions/Start/UnpinFromStartAction.cs b/src/Files.App/Actions/Start/UnpinFromStartAction.cs index 6598f4ade86a..2e8f0a13620a 100644 --- a/src/Files.App/Actions/Start/UnpinFromStartAction.cs +++ b/src/Files.App/Actions/Start/UnpinFromStartAction.cs @@ -33,12 +33,15 @@ public async Task ExecuteAsync(object? parameter = null) { foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems) { - IStorable storable = listedItem.IsFolder switch + await SafetyExtensions.IgnoreExceptions(async () => { - true => await StorageService.GetFolderAsync(listedItem.ItemPath), - _ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath) - }; - await StartMenuService.UnpinAsync(storable); + IStorable storable = listedItem.IsFolder switch + { + true => await StorageService.GetFolderAsync(listedItem.ItemPath), + _ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath) + }; + await StartMenuService.UnpinAsync(storable); + }); } } else