Skip to content
Open
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
36 changes: 35 additions & 1 deletion src/Files.App/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ private async Task<BitmapImage> GetShieldIcon()
return shieldIcon;
}

private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancellationToken)
private async Task LoadThumbnailAsync(ListedItem item, CancellationToken cancellationToken, bool scheduleTimerRetry = true)
{
var loadNonCachedThumbnail = false;
var thumbnailSize = LayoutSizeKindHelper.GetIconSize(folderSettings.LayoutMode);
Expand Down Expand Up @@ -1181,6 +1181,38 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
if (result is null)
{
item.NeedsDelayedThumbnailLoad = true;

if (scheduleTimerRetry)
{
var retryCts = new CancellationTokenSource();
if (thumbnailRetryDebounce.TryAdd(item.ItemPath, retryCts))
{
App.Logger.LogWarning("Thumbnail load failed [{Id}] '{Extension}'; scheduling 2s timer retry.", item.ItemPath.GetHashCode(), Path.GetExtension(item.ItemPath));

var retryToken = retryCts.Token;
_ = Task.Delay(2000, retryToken)
.ContinueWith(_ =>
{
if (thumbnailRetryDebounce.TryRemove(item.ItemPath, out var cts))
cts.Dispose();

App.Logger.LogInformation("Timer-based thumbnail retry firing [{Id}] '{Extension}'.", item.ItemPath.GetHashCode(), Path.GetExtension(item.ItemPath));

item.NeedsDelayedThumbnailLoad = false;
return LoadThumbnailAsync(item, retryToken, scheduleTimerRetry: false);
}, retryToken, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default)
.Unwrap();
}
else
{
App.Logger.LogWarning("Thumbnail load failed [{Id}] '{Extension}'; mod-retry already pending, skipping timer.", item.ItemPath.GetHashCode(), Path.GetExtension(item.ItemPath));
retryCts.Dispose();
}
}
else
{
App.Logger.LogWarning("Thumbnail load failed [{Id}] '{Extension}' on timer retry; awaiting next FILE_ACTION_MODIFIED.", item.ItemPath.GetHashCode(), Path.GetExtension(item.ItemPath));
}
}
else
{
Expand Down Expand Up @@ -2667,6 +2699,8 @@ private async Task UpdateFilesOrFoldersAsync(IEnumerable<string> paths, bool has
var item = filesAndFolders.ToList().FirstOrDefault(x => x.ItemPath.Equals(path, StringComparison.OrdinalIgnoreCase));
if (item is not null && item.NeedsDelayedThumbnailLoad)
{
App.Logger.LogInformation("FILE_ACTION_MODIFIED thumbnail retry triggered [{Id}] '{Extension}'.", path.GetHashCode(), Path.GetExtension(path));

if (thumbnailRetryDebounce.TryGetValue(path, out var existingCts))
{
existingCts.Cancel();
Expand Down
Loading