From 0ccf13eae484e081844d8737e2170a80b56dbcb3 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Mon, 11 Dec 2023 00:28:16 +0900 Subject: [PATCH] Fix: Fixed NullReferenceException in LaunchPreviewPopupAction (#14211) --- .../Content/PreviewPopup/LaunchPreviewPopupAction.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Files.App/Actions/Content/PreviewPopup/LaunchPreviewPopupAction.cs b/src/Files.App/Actions/Content/PreviewPopup/LaunchPreviewPopupAction.cs index b67615e1c23e..48c89d1186b1 100644 --- a/src/Files.App/Actions/Content/PreviewPopup/LaunchPreviewPopupAction.cs +++ b/src/Files.App/Actions/Content/PreviewPopup/LaunchPreviewPopupAction.cs @@ -37,7 +37,9 @@ public async Task ExecuteAsync() if (provider is null) return; - await provider.TogglePreviewPopupAsync(context.SelectedItem!.ItemPath); + var itemPath = context.SelectedItem?.ItemPath; + if (itemPath is not null) + await provider.TogglePreviewPopupAsync(itemPath); } private async Task SwitchPopupPreviewAsync() @@ -48,17 +50,19 @@ private async Task SwitchPopupPreviewAsync() if (provider is null) return; - await provider.SwitchPreviewAsync(context.SelectedItem!.ItemPath); + var itemPath = context.SelectedItem?.ItemPath; + if (itemPath is not null) + await provider.SwitchPreviewAsync(itemPath); } } - public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) + public async void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(IContentPageContext.SelectedItems): OnPropertyChanged(nameof(IsExecutable)); - var _ = SwitchPopupPreviewAsync(); + await SwitchPopupPreviewAsync(); break; } }