Skip to content

Commit

Permalink
Fix: Fixed freeze that occurred when right-clicking immediately after…
Browse files Browse the repository at this point in the history
… launching the app (#13094)
  • Loading branch information
hishitetsu authored Jul 28, 2023
1 parent 2e36593 commit fe1a4ec
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ await Task.WhenAll(

await Task.WhenAll(
JumpListHelper.InitializeUpdatesAsync(),
addItemService.GetNewEntriesAsync(),
addItemService.InitializeAsync(),
ContextMenu.WarmUpQueryContextMenuAsync()
);

Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Dialogs/AddItemDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetNewItemItems(BaseLayoutVie

if (canCreateFileInPage)
{
var cachedNewContextMenuEntries = addItemService.GetNewEntriesAsync().Result;
var cachedNewContextMenuEntries = addItemService.GetEntries();
cachedNewContextMenuEntries?.ForEach(i =>
{
if (!string.IsNullOrEmpty(i.IconBase64))
Expand Down
8 changes: 5 additions & 3 deletions src/Files.App/Services/AddItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ internal sealed class AddItemService : IAddItemService
{
private List<ShellNewEntry> _cached;

public async Task<List<ShellNewEntry>> GetNewEntriesAsync()
public async Task InitializeAsync()
{
if (_cached is null || _cached.Count == 0)
_cached = await ShellNewEntryExtensions.GetNewContextMenuEntries();
_cached = await ShellNewEntryExtensions.GetNewContextMenuEntries();
}

public List<ShellNewEntry> GetEntries()
{
return _cached;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/UserControls/InnerNavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
8 changes: 7 additions & 1 deletion src/Files.Core/Services/IAddItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ namespace Files.Core.Services
/// </summary>
public interface IAddItemService
{
/// <summary>
/// Initialize the service
/// </summary>
/// <returns>Task</returns>
Task InitializeAsync();

/// <summary>
/// Gets a list of the available item types
/// </summary>
/// <returns>List of the available item types</returns>
Task<List<ShellNewEntry>> GetNewEntriesAsync();
List<ShellNewEntry> GetEntries();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public async Task AddItemsToList(IEnumerable<ShellNewEntry> itemTypes)
}
});

if (itemTypes is null)
return;

foreach (var itemType in itemTypes)
{
IImageModel? imageModel = null;
Expand Down

0 comments on commit fe1a4ec

Please sign in to comment.