IDesktopApplications interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDesktopApplications

Content types, the installed applications that open them, the user's default application for each, and their icons: the desktop's application database. It needs no window.

Remarks

Identifiers are the platform's own. On Linux an application is a desktop file ID, such as org.gnome.TextEditor.desktop, and a content type a MIME type, such as text/plain or x-scheme-handler/mailto, following the freedesktop.org Desktop Entry, Shared MIME-info, MIME Apps and Icon Theme specifications. On Windows an application is the path of its executable (a packaged application's AppUserModelID) and a content type a MIME type or an extension, such as .txt; on macOS an application is a bundle identifier and a content type a uniform type identifier, such as public.plain-text.

Inside Flatpak or Snap the host's applications and defaults are out of reach: the application methods report PlatformUnavailableReason.BackendUnavailable, while content types and icons come from the sandbox's own data. Without a provider every method reports Unavailable; see DesktopApplications.Unavailable.

Methods

GetApplicationsAsync

ValueTask<PlatformResult<ImmutableArray<DesktopApplicationInfo>>> GetApplicationsAsync(CancellationToken cancellationToken = default)

Lists the installed applications the desktop shows in application lists, by name.

GetApplicationsForAsync

ValueTask<PlatformResult<ImmutableArray<DesktopApplicationInfo>>> GetApplicationsForAsync(string contentType, CancellationToken cancellationToken = default)

Lists the applications that open contentType: the default first, then the others in the desktop's order of preference, including applications for the types it is an instance of.

Exceptions

ArgumentException

contentType is empty or contains NUL.

Remarks

A content type the platform cannot parse is PlatformFailureCode.InvalidData.

GetContentTypeAsync

ValueTask<PlatformResult<DesktopContentType>> GetContentTypeAsync(string path, DesktopContentDetection detection = DesktopContentDetection.NameAndContent, CancellationToken cancellationToken = default)

Determines the content type of the file at path.

Exceptions

ArgumentException

path is empty or contains NUL.

Remarks

DesktopContentDetection.NameOnly never touches the file and returns the most generic type, application/octet-stream on Linux, for a name it does not recognize. With DesktopContentDetection.NameAndContent a missing file is PlatformFailureCode.IOError and an unreadable one PlatformFailureCode.PermissionDenied.

GetDefaultApplicationAsync

ValueTask<PlatformResult<DesktopApplicationInfo?>> GetDefaultApplicationAsync(string contentType, CancellationToken cancellationToken = default)

Returns the application that opens contentType by default.

Returns

The application, or a successful null when no installed application opens the type.

Exceptions

ArgumentException

contentType is empty or contains NUL.

GetIconAsync

ValueTask<PlatformResult<DesktopIconData?>> GetIconAsync(DesktopIconRequest request, CancellationToken cancellationToken = default)

Looks up an icon in the desktop's icon theme and reads its image.

Returns

The icon, or a successful null when the theme has none for the request.

Remarks

An icon file larger than 4 MiB is PlatformFailureCode.TooLarge.

LaunchAsync

ValueTask<PlatformResult<PlatformUnit>> LaunchAsync(string applicationId, ImmutableArray<string> pathsOrUris, CancellationToken cancellationToken = default)

Starts the installed application applicationId, passing it pathsOrUris.

Parameters

applicationId

An installed application's identifier.

pathsOrUris

Fully qualified local paths and absolute URIs to open; may be empty. At most 1024.

cancellationToken

Cancels before the application starts.

Exceptions

ArgumentException

The identifier is empty or contains NUL, or an item is neither a fully qualified path nor an absolute URI.

Remarks

Success means the application was started or asked to open the items, not that it opened them. The application is never a command line: only an installed application the desktop knows can be started, and each item reaches it as one argument, never through a shell. An application that cannot take what it is given, such as a web URI for an application that opens only local files, is PlatformFailureCode.InvalidData.

On Linux an application that runs in a terminal (Terminal=true) is PlatformUnavailableReason.BackendUnavailable.

SetDefaultApplicationAsync

ValueTask<PlatformResult<PlatformUnit>> SetDefaultApplicationAsync(string contentType, string applicationId, CancellationToken cancellationToken = default)

Makes applicationId the user's default application for contentType.

Exceptions

ArgumentException

An argument is empty or contains NUL.

Remarks

An application that is not installed or does not open the type is PlatformFailureCode.InvalidData, and nothing changes. macOS may ask the user to confirm the change, and the request waits for the answer; a refusal is PlatformFailureCode.UserDismissed. Windows lets only the user choose defaults: the request is PlatformFailureCode.PermissionDenied, with a diagnostic that points to Settings (ms-settings:defaultapps).