QL-Win / QuickLook

Bring macOS “Quick Look” feature to Windows

Home Page:http://pooi.moe/QuickLook/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async plugin interface

Cologler opened this issue · comments

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.

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.

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

var task = instance._animation.GetThumbnail(instance.ContextObject.PreferredSize);
if (task == null) return;
task.ContinueWith(_ => instance.Dispatcher.Invoke(() =>
{
if (instance._disposing)
return;
instance.Source = _.Result;
if (_.Result != null)
{
instance.DoZoomToFit?.Invoke(instance, new EventArgs());
instance.ImageLoaded?.Invoke(instance, new EventArgs());
}
instance.BeginAnimation(AnimationFrameIndexProperty, instance._animation?.Animator);
}));
task.Start();

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

_fileHandle = (Bitmap) Image.FromFile(path.LocalPath);