public interface IWindowPlatformServices : IPlatformCapabilities Native services owned by one application window.
Remarks
A host registers one instance per window scope, so a ViewModel can take this interface, or IFileDialogs, ITextClipboard, IDesktopClipboard or IDesktopFileLauncher directly, in its constructor. The services follow the window: before it opens they report PlatformUnavailableReason.OwnerUnavailable, and once it closes PlatformUnavailableReason.OwnerClosed. A host without a native owner reports every service unavailable instead of failing to resolve it.
Properties
Clipboard
ITextClipboard Clipboard { get; } The window's clipboard, used through the window's native thread.
Remarks
The clipboard of Runic's hosts is also an IDesktopClipboard, with HTML, RTF, images, files and a watch: services.Clipboard as IDesktopClipboard.
FileLauncher
IDesktopFileLauncher FileLauncher { get; } Hands local files and web, mail or Windows Settings URIs to native applications on behalf of the window.
MessageBoxes
IDesktopMessageBoxes MessageBoxes { get; } Native message boxes owned by the window (PlatformCapabilityIds.MessageBoxes).
Remarks
A box is modal to the window and closes with it. An implementation that does not override this member reports PlatformUnavailableReason.OwnerUnavailable, as hosts without a native owner, such as CS-WebUI, do.
Monitors
IDesktopMonitors Monitors { get; } The desktop's monitors, in the units of the window's position and size (PlatformCapabilityIds.Monitors).
Remarks
The monitors of the window's host; the list does not depend on the window. An implementation that does not override this member reports PlatformUnavailableReason.OwnerUnavailable.
Methods
AnnounceAsync
ValueTask<PlatformResult<PlatformUnit>> AnnounceAsync(string message, PlatformAnnouncementPriority priority = PlatformAnnouncementPriority.Polite, CancellationToken cancellationToken = default) Asks the screen reader to announce a message for the window, such as the result of an action.
Parameters
messageThe text to speak, in the window's language.
priorityPlatformAnnouncementPriority.Polite, the default, waits for what the screen reader is saying;PlatformAnnouncementPriority.Assertiveinterrupts it.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window's accessibility API accepted the announcement, or Unavailable: PlatformUnavailableReason.OwnerUnavailable before the window opens or on a host without a native owner, PlatformUnavailableReason.OwnerClosed once it closed, and PlatformUnavailableReason.BackendUnavailable when the window cannot announce.
Exceptions
ArgumentExceptionmessageis empty or white space.ArgumentNullExceptionmessageisnull.ArgumentOutOfRangeExceptionpriorityis not a defined value.
Remarks
The host-neutral counterpart of an ARIA live region: the host raises the announcement through the platform's accessibility API for the window, so it reaches the screen reader where a live region in the page does not. An implementation that does not override this member reports PlatformUnavailableReason.OwnerUnavailable.
SetBadgeAsync
ValueTask<PlatformResult<PlatformUnit>> SetBadgeAsync(DesktopBadge? badge, CancellationToken cancellationToken = default) Shows a badge on the window's taskbar button or the application's Dock icon (PlatformCapabilityIds.TaskbarBadge).
Parameters
badgeThe count or dot to show;
nullremoves the badge.cancellationTokenCancels before the request reaches the window.
Returns
Success once the desktop took the badge, also on a desktop that does not show one, such as GNOME without a dock extension, or Unavailable: PlatformUnavailableReason.OwnerUnavailable before the window opens or on a host without a native owner, PlatformUnavailableReason.OwnerClosed once it closed, and PlatformUnavailableReason.BackendUnavailable when the desktop has no badges.
Exceptions
ArgumentExceptionbadgehas a count below 1 or a description with a NUL character.
Remarks
Windows shows the badge on this window's taskbar button, drawn by Runic as an overlay icon with DesktopBadge.Description as its accessible text. macOS and Linux have one badge for the application: the most recent call of any window wins, and a window's badge goes when the window closes. On Linux the badge needs the application's ID, as for notifications. An implementation that does not override this member checks the argument and reports PlatformUnavailableReason.OwnerUnavailable.
SetProgressAsync
ValueTask<PlatformResult<PlatformUnit>> SetProgressAsync(DesktopProgress? progress, CancellationToken cancellationToken = default) Shows progress on the window's taskbar button or the application's Dock icon (PlatformCapabilityIds.TaskbarProgress).
Parameters
progressThe progress to show;
nullremoves it.cancellationTokenCancels before the request reaches the window.
Returns
The results of IWindowPlatformServices.SetBadgeAsync.
Exceptions
ArgumentExceptionprogresshas a value outside 0 to 1 or an undefined state.
Remarks
Windows fills this window's taskbar button, yellow for DesktopProgressState.Paused and red for DesktopProgressState.Error. macOS draws a bar on the Dock icon and Linux docks on their launcher, for the application as with badges. An implementation that does not override this member checks the argument and reports PlatformUnavailableReason.OwnerUnavailable.
ShowContextMenuAsync
ValueTask<PlatformResult<DesktopMenuItem?>> ShowContextMenuAsync(ImmutableArray<DesktopMenuEntry> items, DesktopContextMenuOptions? options = null, CancellationToken cancellationToken = default) Shows a native context menu for the window and returns the item the user chose.
Parameters
itemsThe menu's entries: the rules of
DesktopMenuItemandDesktopMenu, at most four nested submenus and 256 entries, and at least one entry. Command ids may repeat;DesktopMenu.Roleis ignored.optionsWhere the menu opens;
nullopens it at the pointer.cancellationTokenCloses the menu, which then throws
OperationCanceledException.
Returns
Success with the chosen item, one of items, or with null when the user dismissed the menu, a later context menu of the window replaced it, or it closed with the window. Unavailable: PlatformUnavailableReason.OwnerUnavailable before the window opens or on a host without a native owner, PlatformUnavailableReason.OwnerClosed once it closed, and PlatformUnavailableReason.BackendUnavailable when the window has no native context menus (PlatformCapabilityIds.ContextMenu).
Exceptions
ArgumentExceptionitemsis empty or breaks a menu rule, oroptionssets only one coordinate or one that is not a finite number.
Remarks
The menu is modal for the window. Disabled items and items of disabled submenus cannot be chosen; a shortcut is shown as a hint and not registered. The result is the item record, so the caller runs its command, for example with DesktopMenuItem.CommandParameter as the row the menu is for.
A page asks for the menu through an ordinary command, for example showRowMenu(key, x, y) from its contextmenu event, after calling preventDefault() so the web view's own menu stays closed. An implementation that does not override this member checks the arguments and reports PlatformUnavailableReason.OwnerUnavailable.
StartDragAsync
ValueTask<PlatformResult<DesktopDragEffects>> StartDragAsync(DesktopDragData data, CancellationToken cancellationToken = default) Starts a native drag of files, text or URIs out of the window, and returns the effect of the drop.
Parameters
dataWhat to drag; the rules of
DesktopDragData.cancellationTokenCancels before the drag starts; a running drag ends with the pointer.
Returns
Success with the effect the drop target chose, one of DesktopDragData.AllowedEffects, or DesktopDragEffects.None when the user cancelled the drag, dropped it where nothing accepted it, or no mouse button was held when the call arrived. Unavailable: PlatformUnavailableReason.OwnerUnavailable before the window opens or on a host without a native owner, PlatformUnavailableReason.OwnerClosed once it closed, and PlatformUnavailableReason.BackendUnavailable when the window cannot start drags (PlatformCapabilityIds.DragOut).
Exceptions
ArgumentExceptiondatabreaks a rule ofDesktopDragData.ArgumentNullExceptiondataisnull.
Remarks
Call it while the user holds the primary mouse button on the window: a page asks for the drag through an ordinary command from its dragstart event, after calling preventDefault() so the web view starts no drag of its own, and the ViewModel builds data from its own state, for example the files of the row the command names. The paths never come from the page.
DesktopDragEffects.Move means the target asked for a move: the files may already be gone, for example after an optimized move on Windows, so delete what remains. An implementation that does not override this member checks the arguments and reports PlatformUnavailableReason.OwnerUnavailable.