From 4a840d5e06697eb6ee46bc3c5fff781750c3e174 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:45:10 -0400 Subject: [PATCH] Code Quality: Follow up for Fixed DirectoryNotFoundException when pinning items --- src/Files.App/Actions/Start/PinToStartAction.cs | 14 +++++++------- .../Actions/Start/UnpinFromStartAction.cs | 13 +++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Files.App/Actions/Start/PinToStartAction.cs b/src/Files.App/Actions/Start/PinToStartAction.cs index ccecead66d62..300da3aba687 100644 --- a/src/Files.App/Actions/Start/PinToStartAction.cs +++ b/src/Files.App/Actions/Start/PinToStartAction.cs @@ -1,9 +1,6 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. -using CommunityToolkit.Mvvm.DependencyInjection; -using Files.Core.Storage; - namespace Files.App.Actions { internal sealed class PinToStartAction : IAction @@ -45,15 +42,18 @@ await SafetyExtensions.IgnoreExceptions(async () => _ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath) }; await StartMenuService.PinAsync(storable, listedItem.Name); - }); + }); } } else if (context.ShellPage?.ShellViewModel?.CurrentFolder is not null) { - var currentFolder = context.ShellPage.ShellViewModel.CurrentFolder; - var folder = await StorageService.GetFolderAsync(currentFolder.ItemPath); + await SafetyExtensions.IgnoreExceptions(async () => + { + var currentFolder = context.ShellPage.ShellViewModel.CurrentFolder; + var folder = await StorageService.GetFolderAsync(currentFolder.ItemPath); - await StartMenuService.PinAsync(folder, currentFolder.Name); + await StartMenuService.PinAsync(folder, currentFolder.Name); + }); } } } diff --git a/src/Files.App/Actions/Start/UnpinFromStartAction.cs b/src/Files.App/Actions/Start/UnpinFromStartAction.cs index 2e8f0a13620a..1e3adf24950e 100644 --- a/src/Files.App/Actions/Start/UnpinFromStartAction.cs +++ b/src/Files.App/Actions/Start/UnpinFromStartAction.cs @@ -1,8 +1,6 @@ // Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. -using Files.Core.Storage; - namespace Files.App.Actions { internal sealed class UnpinFromStartAction : IAction @@ -41,15 +39,18 @@ await SafetyExtensions.IgnoreExceptions(async () => _ => await StorageService.GetFileAsync((listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath) }; await StartMenuService.UnpinAsync(storable); - }); + }); } } else { - var currentFolder = context.ShellPage.ShellViewModel.CurrentFolder; - var folder = await StorageService.GetFolderAsync(currentFolder.ItemPath); + await SafetyExtensions.IgnoreExceptions(async () => + { + var currentFolder = context.ShellPage.ShellViewModel.CurrentFolder; + var folder = await StorageService.GetFolderAsync(currentFolder.ItemPath); - await StartMenuService.UnpinAsync(folder); + await StartMenuService.UnpinAsync(folder); + }); } } }