QL-Win / QuickLook

Bring macOS “Quick Look” feature to Windows
http://pooi.moe/QuickLook/
GNU General Public License v3.0
17.38k stars 1.09k forks source link

Async plugin interface #1371

Open Cologler opened 11 months ago

Cologler commented 11 months ago

Currently, previewing a big file is not cancellable. QuickLook may crash if I jump too fast.

Add the new async plugin interface with CancellationToken, which allows the user to cancel the current operator.

xupefei commented 11 months ago

The real problem is not all third-party components support cancel. For example you see the TextViewer can be cancelled, but the ImageViewer can't. In this case it's because the ImageViewer does not provide a way to stop loading an image.

Another problem we have is the UI thread. WPF limits visual elements to run in the UI thread, will will effectively block the whole application.

If you have a better idea please let me know. I ran out of idea.

Cologler commented 11 months ago

It looks like the ImageViewer was loading the image in an async task:

https://github.com/QL-Win/QuickLook/blob/1d566c942d85bc2c2a60f1d231826420d3053298/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/AnimatedImage.cs#L115-L133

Cologler commented 11 months ago

Replace Image.FromFile to Image.FromStream and replace BitmapImage.UriSource to BitmapImage.StreamSource should allow us to cancel the IO operator:

https://github.com/QL-Win/QuickLook/blob/1d566c942d85bc2c2a60f1d231826420d3053298/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/GifProvider.cs#L45

https://github.com/QL-Win/QuickLook/blob/1d566c942d85bc2c2a60f1d231826420d3053298/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/NativeProvider.cs#L59