IDesktopThumbnails interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDesktopThumbnails

Thumbnails of files as the desktop's file manager shows them: the freedesktop.org thumbnail cache on Linux, the shell's thumbnail providers on Windows and Quick Look on macOS.

Remarks

A path is a fully qualified local path, supplied by trusted C# application code, never directly by a web client. The thumbnail is a PNG image, which a web view shows directly, for example as a data:image/png URL.

Outcomes common to every platform: a thumbnail is Success with a DesktopThumbnail; a file without one, such as a type no thumbnailer handles, a file whose thumbnailing failed or, on Linux, a desktop that runs no thumbnailer and has none cached, is Success with null; a path that does not exist is PlatformFailureCode.NotFound; access refused is PlatformFailureCode.PermissionDenied. An icon is never returned instead of a thumbnail.

Methods

GetThumbnailAsync

ValueTask<PlatformResult<DesktopThumbnail?>> GetThumbnailAsync(string path, int size, CancellationToken cancellationToken = default)

Gets a thumbnail of the file at path for display at size pixels.

Parameters

path

A fully qualified local path.

size

The largest edge to display, from 1 to DesktopThumbnails.MaximumSize pixels. The thumbnail keeps the file's aspect ratio and can differ in size: Linux returns the smallest cached size at least as large (128, 256, 512 or 1024 pixels), else the largest smaller one; Windows and macOS return at most size pixels, fewer for a small image. DesktopThumbnail.Width and DesktopThumbnail.Height report the image's own size; scale it to display.

cancellationToken

Cancels the request, also while a thumbnailer generates the thumbnail.

Exceptions

ArgumentException

path is empty, relative, contains NUL or names a root directory.

ArgumentOutOfRangeException

size is less than 1 or greater than DesktopThumbnails.MaximumSize.

GetThumbnailAsync

ValueTask<PlatformResult<DesktopThumbnail?>> GetThumbnailAsync(string path, int size, int scale, CancellationToken cancellationToken)

Gets a thumbnail of the file at path for display at size pixels on a display with scale device pixels per pixel, such as a window's device pixel ratio.

Parameters

path

A fully qualified local path.

size

The largest edge to display, from 1 to DesktopThumbnails.MaximumSize pixels at scale 1.

scale

The display scale, from 1 to DesktopThumbnails.MaximumScale; 2 asks for an image with twice the pixels along each edge. The request is size times scale device pixels, at most DesktopThumbnails.MaximumSize; the thumbnail is then sized as IDesktopThumbnails.GetThumbnailAsync describes, in device pixels.

cancellationToken

Cancels the request, also while a thumbnailer generates the thumbnail.

Exceptions

ArgumentException

path is empty, relative, contains NUL or names a root directory.

ArgumentOutOfRangeException

size or scale is outside its range.

Remarks

The token is required so that a call with three arguments, such as GetThumbnailAsync(path, 256, default), keeps binding to the overload without a scale. The default implementation asks IDesktopThumbnails.GetThumbnailAsync for the device-pixel size, which is what every Runic provider does.