Skip to content

Commit 4790e02

Browse files
authored
Fix: Fixed DirectoryNotFoundException when pinning items to the start menu (#15865)
1 parent 8e4654d commit 4790e02

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/Files.App/Actions/Start/PinToStartAction.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ public async Task ExecuteAsync(object? parameter = null)
3737
{
3838
foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems)
3939
{
40-
IStorable storable = listedItem.IsFolder switch
40+
await SafetyExtensions.IgnoreExceptions(async () =>
4141
{
42-
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
43-
_ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath)
44-
};
45-
await StartMenuService.PinAsync(storable, listedItem.Name);
42+
IStorable storable = listedItem.IsFolder switch
43+
{
44+
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
45+
_ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath)
46+
};
47+
await StartMenuService.PinAsync(storable, listedItem.Name);
48+
});
4649
}
4750
}
4851
else if (context.ShellPage?.ShellViewModel?.CurrentFolder is not null)

src/Files.App/Actions/Start/UnpinFromStartAction.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ public async Task ExecuteAsync(object? parameter = null)
3333
{
3434
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
3535
{
36-
IStorable storable = listedItem.IsFolder switch
36+
await SafetyExtensions.IgnoreExceptions(async () =>
3737
{
38-
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
39-
_ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath)
40-
};
41-
await StartMenuService.UnpinAsync(storable);
38+
IStorable storable = listedItem.IsFolder switch
39+
{
40+
true => await StorageService.GetFolderAsync(listedItem.ItemPath),
41+
_ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath)
42+
};
43+
await StartMenuService.UnpinAsync(storable);
44+
});
4245
}
4346
}
4447
else

0 commit comments

Comments
 (0)