IDesktopFileBookmarks interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDesktopFileBookmarks

Keeps access to files across launches: a sandboxed macOS application keeps the files the user opened or chose, as a recent-files list needs.

Remarks

On macOS a bookmark is a security-scoped bookmark inside the App Sandbox and an ordinary bookmark otherwise, which also follows a file the user moves or renames. Elsewhere a bookmark is the file's path. Store the bytes as they are; they are not portable between computers or users.

Methods

CreateAsync

ValueTask<PlatformResult<ImmutableArray<byte>>> CreateAsync(string path, CancellationToken cancellationToken = default)

Creates a bookmark for the file or directory at path, which the application can access now, such as one the user opened or chose.

Returns

The bookmark; PlatformFailureCode.NotFound for a missing item, and a failure such as PlatformFailureCode.PermissionDenied or PlatformFailureCode.IOError (macOS reports NSFileReadUnknownError) for one the sandbox does not let the application read.

Exceptions

ArgumentException

path is not fully qualified or contains NUL.

OpenDocumentAsync

ValueTask<PlatformResult<IDocumentFileLease>> OpenDocumentAsync(ImmutableArray<byte> bookmark, CancellationToken cancellationToken = default)

Resolves a bookmark from IDesktopFileBookmarks.CreateAsync or ISaveFileLease.CreateBookmarkAsync as a document the application reads and saves back to, such as an entry of a recent-files list.

Returns

The document; the failures of IDesktopFileBookmarks.ResolveAsync, and PlatformFailureCode.InvalidData for a bookmark of a directory.

Exceptions

ArgumentException

bookmark is default or empty.

Remarks

The lease keeps the bookmark's access until it is disposed; it belongs to no presentation. A path from a launch or a drop becomes a document through IDesktopFileBookmarks.CreateAsync and then this method. Inside the macOS App Sandbox the lease keeps the bookmark's security-scoped access started until it is disposed. The default implementation returns Unavailable with PlatformUnavailableReason.BackendUnavailable.

ResolveAsync

ValueTask<PlatformResult<IDesktopBookmarkAccess>> ResolveAsync(ImmutableArray<byte> bookmark, CancellationToken cancellationToken = default)

Resolves a bookmark from IDesktopFileBookmarks.CreateAsync and starts accessing its file until the access is disposed.

Returns

The access; PlatformFailureCode.NotFound when the item no longer exists (inside the macOS App Sandbox a security-scoped bookmark of a deleted item reports PlatformFailureCode.InvalidData), PlatformFailureCode.InvalidData for bytes that are not a bookmark, and PlatformFailureCode.PermissionDenied when the system refuses access. Treat any failure as a bookmark to forget.

Exceptions

ArgumentException

bookmark is default or empty.