IDesktopFileLauncher interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDesktopFileLauncher

Native file and URI handoff. Paths and URIs are supplied by trusted C# application code, never directly by a web client.

Methods

LaunchAsync

ValueTask<PlatformResult<PlatformUnit>> LaunchAsync(string path, DesktopFileOperation operation = DesktopFileOperation.Open, CancellationToken cancellationToken = default)

The caller must retain any sandbox/security-scoped access until the operation completes.

Remarks

Success acknowledges native handling, not that another application opened the file. Windows Open With can report success even when dismissed; UserDismissed is returned only when the native API distinguishes dismissal. Windows and macOS Open returns PermissionDenied for programs, scripts, installers and shortcuts instead of running them; Linux applies the desktop portal's policy. The Windows and macOS block lists are best effort: do not Open files from untrusted sources, such as downloads or names a page supplies; Reveal them or let the user ChooseApplication instead. Windows rejects UNC, device and alternate-stream paths.

LaunchUriAsync

ValueTask<PlatformResult<PlatformUnit>> LaunchUriAsync(Uri uri, CancellationToken cancellationToken = default)

Opens an absolute http, https, mailto or ms-settings URI in the user's default handler, such as the default browser, the mail client or, for ms-settings, the Windows Settings app.

Parameters

uri

The URI. Relative URIs, paths (an absolute path is a file: URI) and every other scheme are rejected before anything native runs, so a launch never executes a program; open local files with IDesktopFileLauncher.LaunchAsync.

cancellationToken

Cancels before the request reaches the desktop.

Exceptions

ArgumentNullException

uri is null.

ArgumentException

uri is relative, a path, not an http, https, mailto or ms-settings URI, an ms-settings URI outside the page rule, or a mailto URI that names an attachment (attach, attachment).

Remarks

Success acknowledges that the desktop accepted the URI, not that an application showed it. Linux asks the desktop portal (OpenURI), which may let the user choose an application and reports PlatformFailureCode.UserDismissed when they cancel; Windows uses the shell's URL association; macOS uses NSWorkspace. Without a registered handler, for example no mail client for mailto, the desktop may offer to find an application (Windows 11 does, and reports success), or the result is PlatformUnavailableReason.BackendUnavailable or a failure, depending on the platform. An ms-settings URI must be exactly ms-settings: and a page of 1 to 64 letters, digits or hyphens, such as ms-settings:display, with no path, query, fragment or escapes; pages ending in -action, which act instead of showing a page, are refused. Only Windows opens it; Linux and macOS validate it the same way and return PlatformUnavailableReason.BackendUnavailable without a native call.