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 issue where placeholders used the thumbnail instead of the icon #14607

Merged
merged 3 commits into from
Feb 1, 2024
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
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 &&
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
!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
Loading