Skip to content

Refactor: Improve icon loading in FolderSearch #17358

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
31 changes: 16 additions & 15 deletions src/Files.App/Utils/Storage/Search/FolderSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,24 @@ private ListedItem GetListedItemAsync(string itemPath, WIN32_FIND_DATA findData)

if (listedItem is not null && MaxItemCount > 0) // Only load icon for searchbox suggestions
{
_ = FileThumbnailHelper.GetIconAsync(
listedItem.ItemPath,
Constants.ShellIconSizes.Small,
isFolder,
IconOptions.ReturnIconOnly | IconOptions.UseCurrentScale)
.ContinueWith((t) =>
_ = FilesystemTasks.Wrap(async () =>
{
var iconData = await FileThumbnailHelper.GetIconAsync(
listedItem.ItemPath,
Constants.ShellIconSizes.Small,
isFolder,
IconOptions.ReturnIconOnly | IconOptions.UseCurrentScale);

if (iconData is not null)
{
if (t.IsCompletedSuccessfully && t.Result is not null)
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
_ = FilesystemTasks.Wrap(() => MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
var bitmapImage = await t.Result.ToBitmapAsync();
if (bitmapImage is not null)
listedItem.FileImage = bitmapImage;
}, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low));
}
});
var bitmapImage = await iconData.ToBitmapAsync();
if (bitmapImage is not null)
listedItem.FileImage = bitmapImage;
}, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
}
});
}

return listedItem;
Expand Down
Loading