Skip to content

Commit

Permalink
Fix: Fixed issue where placeholders used the thumbnail instead of the…
Browse files Browse the repository at this point in the history
… icon (#14607)

Co-authored-by: hishitetsu <[email protected]>
  • Loading branch information
yaira2 and hishitetsu authored Feb 1, 2024
1 parent 30aa166 commit 681b2d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
26 changes: 18 additions & 8 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.ViewModels.Previews;
using Files.Core.Services.SizeProvider;
using Files.Shared.Helpers;
using LibGit2Sharp;
Expand Down Expand Up @@ -909,9 +908,9 @@ public async Task GetDefaultItemIconsAsync(uint size)
if (currentDefaultIconSize == size)
return;

// TODO: Add more than just the folder icon
DefaultIcons.Clear();

// TODO: Add more than just the folder icon
using StorageItemThumbnail icon = await FilesystemTasks.Wrap(() => StorageItemIconHelpers.GetIconForItemType(size, IconPersistenceOptions.Persist));
if (icon is not null)
{
Expand Down Expand Up @@ -947,7 +946,7 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =

if (!iconInfo.isIconCached)
{
// Display icon while trying to load cached thumbnail
// Assign a placeholder icon while trying to get a cached thumbnail
if (iconInfo.IconData is not null)
{
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
Expand All @@ -970,18 +969,29 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
// Assign the thumbnail/icon to the listed item
item.FileImage = await iconInfo.IconData.ToBitmapAsync();
if (!string.IsNullOrEmpty(item.FileExtension) &&
!item.IsShortcut && !item.IsExecutable &&
!ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()))

// Add the file icon to the DefaultIcons list
if
(
!DefaultIcons.ContainsKey(item.FileExtension.ToLowerInvariant()) &&
!string.IsNullOrEmpty(item.FileExtension) &&
!item.IsShortcut &&
!item.IsExecutable
)
{
DefaultIcons.AddIfNotPresent(item.FileExtension.ToLowerInvariant(), item.FileImage);
var fileIcon = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, true);
var bitmapImage = await fileIcon.IconData.ToBitmapAsync();
DefaultIcons.TryAdd(item.FileExtension.ToLowerInvariant(), bitmapImage);
}

}, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
}

if (iconInfo.OverlayData is not null)
{
// Assign the icon overlay to the listed item
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
item.IconOverlay = await iconInfo.OverlayData.ToBitmapAsync();
Expand All @@ -993,7 +1003,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
var getIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 80;
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, true, getIconOnly);

if (iconInfo.IconData is not null)
{
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
Expand Down
9 changes: 6 additions & 3 deletions src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedE
else
SelectedItem = null;

var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive;
if (shouldUpdatePreview == true)
_ = UpdateSelectedItemPreviewAsync();
if (!App.AppModel.IsMainWindowClosed)
{
var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive;
if (shouldUpdatePreview == true)
_ = UpdateSelectedItemPreviewAsync();
}
break;
}
}
Expand Down

0 comments on commit 681b2d3

Please sign in to comment.