Skip to content

Commit 681b2d3

Browse files
yaira2hishitetsu
andauthored
Fix: Fixed issue where placeholders used the thumbnail instead of the icon (#14607)
Co-authored-by: hishitetsu <[email protected]>
1 parent 30aa166 commit 681b2d3

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/Files.App/Data/Models/ItemViewModel.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.ViewModels.Previews;
54
using Files.Core.Services.SizeProvider;
65
using Files.Shared.Helpers;
76
using LibGit2Sharp;
@@ -909,9 +908,9 @@ public async Task GetDefaultItemIconsAsync(uint size)
909908
if (currentDefaultIconSize == size)
910909
return;
911910

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

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

948947
if (!iconInfo.isIconCached)
949948
{
950-
// Display icon while trying to load cached thumbnail
949+
// Assign a placeholder icon while trying to get a cached thumbnail
951950
if (iconInfo.IconData is not null)
952951
{
953952
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
@@ -970,18 +969,29 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
970969
{
971970
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
972971
{
972+
// Assign the thumbnail/icon to the listed item
973973
item.FileImage = await iconInfo.IconData.ToBitmapAsync();
974-
if (!string.IsNullOrEmpty(item.FileExtension) &&
975-
!item.IsShortcut && !item.IsExecutable &&
976-
!ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()))
974+
975+
// Add the file icon to the DefaultIcons list
976+
if
977+
(
978+
!DefaultIcons.ContainsKey(item.FileExtension.ToLowerInvariant()) &&
979+
!string.IsNullOrEmpty(item.FileExtension) &&
980+
!item.IsShortcut &&
981+
!item.IsExecutable
982+
)
977983
{
978-
DefaultIcons.AddIfNotPresent(item.FileExtension.ToLowerInvariant(), item.FileImage);
984+
var fileIcon = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, false, true);
985+
var bitmapImage = await fileIcon.IconData.ToBitmapAsync();
986+
DefaultIcons.TryAdd(item.FileExtension.ToLowerInvariant(), bitmapImage);
979987
}
988+
980989
}, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
981990
}
982991

983992
if (iconInfo.OverlayData is not null)
984993
{
994+
// Assign the icon overlay to the listed item
985995
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
986996
{
987997
item.IconOverlay = await iconInfo.OverlayData.ToBitmapAsync();
@@ -993,7 +1003,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
9931003
{
9941004
var getIconOnly = UserSettingsService.FoldersSettingsService.ShowThumbnails == false || thumbnailSize < 80;
9951005
var iconInfo = await FileThumbnailHelper.LoadIconAndOverlayAsync(item.ItemPath, thumbnailSize, true, getIconOnly);
996-
1006+
9971007
if (iconInfo.IconData is not null)
9981008
{
9991009
await dispatcherQueue.EnqueueOrInvokeAsync(async () =>

src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedE
129129
else
130130
SelectedItem = null;
131131

132-
var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive;
133-
if (shouldUpdatePreview == true)
134-
_ = UpdateSelectedItemPreviewAsync();
132+
if (!App.AppModel.IsMainWindowClosed)
133+
{
134+
var shouldUpdatePreview = ((MainWindow.Instance.Content as Frame)?.Content as MainPage)?.ViewModel.ShouldPreviewPaneBeActive;
135+
if (shouldUpdatePreview == true)
136+
_ = UpdateSelectedItemPreviewAsync();
137+
}
135138
break;
136139
}
137140
}

0 commit comments

Comments
 (0)