Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed freeze when right-clicking immediately after launching the app #13094

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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