mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[Peek] Fix race condition when setting preview (#26478)
This commit is contained in:
@@ -62,8 +62,12 @@ namespace Peek.FilePreviewer.Previewers
|
||||
|
||||
private IntPtr lowQualityThumbnail;
|
||||
|
||||
private ImageSource? lowQualityThumbnailPreview;
|
||||
|
||||
private IntPtr highQualityThumbnail;
|
||||
|
||||
private ImageSource? highQualityThumbnailPreview;
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
{
|
||||
return _supportedFileTypes.Contains(fileExt);
|
||||
@@ -110,6 +114,19 @@ namespace Peek.FilePreviewer.Previewers
|
||||
|
||||
await Task.WhenAll(LowQualityThumbnailTask, HighQualityThumbnailTask, FullQualityImageTask);
|
||||
|
||||
// If Preview is still null, FullQualityImage was not available. Preview the thumbnail instead.
|
||||
if (Preview == null)
|
||||
{
|
||||
if (highQualityThumbnailPreview != null)
|
||||
{
|
||||
Preview = highQualityThumbnailPreview;
|
||||
}
|
||||
else
|
||||
{
|
||||
Preview = lowQualityThumbnailPreview;
|
||||
}
|
||||
}
|
||||
|
||||
if (Preview == null && HasFailedLoadingPreview())
|
||||
{
|
||||
State = PreviewState.Error;
|
||||
@@ -179,7 +196,7 @@ namespace Peek.FilePreviewer.Previewers
|
||||
if (!IsFullImageLoaded && !IsHighQualityThumbnailLoaded)
|
||||
{
|
||||
var thumbnailBitmap = await BitmapHelper.GetBitmapFromHBitmapAsync(lowQualityThumbnail, IsPng(Item), cancellationToken);
|
||||
Preview = thumbnailBitmap;
|
||||
lowQualityThumbnailPreview = thumbnailBitmap;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -206,7 +223,7 @@ namespace Peek.FilePreviewer.Previewers
|
||||
if (!IsFullImageLoaded)
|
||||
{
|
||||
var thumbnailBitmap = await BitmapHelper.GetBitmapFromHBitmapAsync(highQualityThumbnail, IsPng(Item), cancellationToken);
|
||||
Preview = thumbnailBitmap;
|
||||
highQualityThumbnailPreview = thumbnailBitmap;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -270,6 +287,8 @@ namespace Peek.FilePreviewer.Previewers
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
lowQualityThumbnailPreview = null;
|
||||
highQualityThumbnailPreview = null;
|
||||
Preview = null;
|
||||
|
||||
if (lowQualityThumbnail != IntPtr.Zero)
|
||||
|
||||
Reference in New Issue
Block a user