From fe1a4ec1c2efa83418de2a3a1a7f119f53006c77 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Fri, 28 Jul 2023 23:15:56 +0900 Subject: [PATCH] Fix: Fixed freeze that occurred when right-clicking immediately after launching the app (#13094) --- src/Files.App/App.xaml.cs | 2 +- src/Files.App/Dialogs/AddItemDialog.xaml.cs | 2 +- .../Helpers/MenuFlyout/ContextFlyoutItemHelper.cs | 2 +- src/Files.App/Services/AddItemService.cs | 8 +++++--- src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs | 2 +- src/Files.Core/Services/IAddItemService.cs | 8 +++++++- .../Dialogs/AddItemDialog/AddItemDialogViewModel.cs | 3 +++ 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 3cbe4580998f..7ee24c2f837d 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -176,7 +176,7 @@ await Task.WhenAll( await Task.WhenAll( JumpListHelper.InitializeUpdatesAsync(), - addItemService.GetNewEntriesAsync(), + addItemService.InitializeAsync(), ContextMenu.WarmUpQueryContextMenuAsync() ); diff --git a/src/Files.App/Dialogs/AddItemDialog.xaml.cs b/src/Files.App/Dialogs/AddItemDialog.xaml.cs index 071a36cad64e..9071d1a605f7 100644 --- a/src/Files.App/Dialogs/AddItemDialog.xaml.cs +++ b/src/Files.App/Dialogs/AddItemDialog.xaml.cs @@ -37,7 +37,7 @@ private void ListView_ItemClick(object sender, ItemClickEventArgs e) private async void AddItemDialog_Loaded(object sender, RoutedEventArgs e) { - var itemTypes = await addItemService.GetNewEntriesAsync(); + var itemTypes = addItemService.GetEntries(); await ViewModel.AddItemsToList(itemTypes); // Focus on the list view so users can use keyboard navigation diff --git a/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs b/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs index ff5e447fa22a..aff373b7f986 100644 --- a/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs +++ b/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs @@ -583,7 +583,7 @@ public static List GetNewItemItems(BaseLayoutVie if (canCreateFileInPage) { - var cachedNewContextMenuEntries = addItemService.GetNewEntriesAsync().Result; + var cachedNewContextMenuEntries = addItemService.GetEntries(); cachedNewContextMenuEntries?.ForEach(i => { if (!string.IsNullOrEmpty(i.IconBase64)) diff --git a/src/Files.App/Services/AddItemService.cs b/src/Files.App/Services/AddItemService.cs index 54874c8daa38..8009cd47997d 100644 --- a/src/Files.App/Services/AddItemService.cs +++ b/src/Files.App/Services/AddItemService.cs @@ -8,11 +8,13 @@ internal sealed class AddItemService : IAddItemService { private List _cached; - public async Task> GetNewEntriesAsync() + public async Task InitializeAsync() { - if (_cached is null || _cached.Count == 0) - _cached = await ShellNewEntryExtensions.GetNewContextMenuEntries(); + _cached = await ShellNewEntryExtensions.GetNewContextMenuEntries(); + } + public List GetEntries() + { return _cached; } } diff --git a/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs b/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs index 0a0872e50fe3..828113c32c09 100644 --- a/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs +++ b/src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs @@ -67,7 +67,7 @@ private void NewEmptySpace_Opening(object sender, object e) shell.ForEach(x => NewEmptySpace.Items.Remove(x)); return; } - var cachedNewContextMenuEntries = addItemService.GetNewEntriesAsync().Result; + var cachedNewContextMenuEntries = addItemService.GetEntries(); if (cachedNewContextMenuEntries is null) return; if (!NewEmptySpace.Items.Any(x => (x.Tag as string) == "CreateNewFile")) diff --git a/src/Files.Core/Services/IAddItemService.cs b/src/Files.Core/Services/IAddItemService.cs index 3fc24ad6d89c..641fe862741b 100644 --- a/src/Files.Core/Services/IAddItemService.cs +++ b/src/Files.Core/Services/IAddItemService.cs @@ -8,10 +8,16 @@ namespace Files.Core.Services /// public interface IAddItemService { + /// + /// Initialize the service + /// + /// Task + Task InitializeAsync(); + /// /// Gets a list of the available item types /// /// List of the available item types - Task> GetNewEntriesAsync(); + List GetEntries(); } } diff --git a/src/Files.Core/ViewModels/Dialogs/AddItemDialog/AddItemDialogViewModel.cs b/src/Files.Core/ViewModels/Dialogs/AddItemDialog/AddItemDialogViewModel.cs index 6ca5d68daac5..d12d0e054609 100644 --- a/src/Files.Core/ViewModels/Dialogs/AddItemDialog/AddItemDialogViewModel.cs +++ b/src/Files.Core/ViewModels/Dialogs/AddItemDialog/AddItemDialogViewModel.cs @@ -68,6 +68,9 @@ public async Task AddItemsToList(IEnumerable itemTypes) } }); + if (itemTypes is null) + return; + foreach (var itemType in itemTypes) { IImageModel? imageModel = null;