1
1
// Copyright (c) 2023 Files Community
2
2
// Licensed under the MIT License. See the LICENSE.
3
3
4
- using Files . App . ViewModels . Previews ;
5
4
using Files . Core . Services . SizeProvider ;
6
5
using Files . Shared . Helpers ;
7
6
using LibGit2Sharp ;
@@ -909,9 +908,9 @@ public async Task GetDefaultItemIconsAsync(uint size)
909
908
if ( currentDefaultIconSize == size )
910
909
return ;
911
910
912
- // TODO: Add more than just the folder icon
913
911
DefaultIcons . Clear ( ) ;
914
912
913
+ // TODO: Add more than just the folder icon
915
914
using StorageItemThumbnail icon = await FilesystemTasks . Wrap ( ( ) => StorageItemIconHelpers . GetIconForItemType ( size , IconPersistenceOptions . Persist ) ) ;
916
915
if ( icon is not null )
917
916
{
@@ -947,7 +946,7 @@ private async Task LoadItemThumbnailAsync(ListedItem item, uint thumbnailSize =
947
946
948
947
if ( ! iconInfo . isIconCached )
949
948
{
950
- // Display icon while trying to load cached thumbnail
949
+ // Assign a placeholder icon while trying to get a cached thumbnail
951
950
if ( iconInfo . IconData is not null )
952
951
{
953
952
await dispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
@@ -970,18 +969,29 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
970
969
{
971
970
await dispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
972
971
{
972
+ // Assign the thumbnail/icon to the listed item
973
973
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
+ )
977
983
{
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 ) ;
979
987
}
988
+
980
989
} , Microsoft . UI . Dispatching . DispatcherQueuePriority . Low ) ;
981
990
}
982
991
983
992
if ( iconInfo . OverlayData is not null )
984
993
{
994
+ // Assign the icon overlay to the listed item
985
995
await dispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
986
996
{
987
997
item . IconOverlay = await iconInfo . OverlayData . ToBitmapAsync ( ) ;
@@ -993,7 +1003,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
993
1003
{
994
1004
var getIconOnly = UserSettingsService . FoldersSettingsService . ShowThumbnails == false || thumbnailSize < 80 ;
995
1005
var iconInfo = await FileThumbnailHelper . LoadIconAndOverlayAsync ( item . ItemPath , thumbnailSize , true , getIconOnly ) ;
996
-
1006
+
997
1007
if ( iconInfo . IconData is not null )
998
1008
{
999
1009
await dispatcherQueue . EnqueueOrInvokeAsync ( async ( ) =>
0 commit comments