IDesktopWindowHost interface

Namespace Runic.Desktop · Runic.Desktop 0.7.0-preview.5

public interface IDesktopWindowHost : IAsyncDisposable

Inherits or implements IAsyncDisposable.

Hosts one Desktop surface in a platform-native window.

Remarks

Runic Desktop creates one host per opened window, calls its members from arbitrary threads, and disposes it after it closes. Implementations marshal native work to the thread that owns the window.

Properties

Capabilities

DesktopWindowCapabilities Capabilities { get; }

Gets operations supported by the native window.

IsOpen

bool IsOpen { get; }

Gets whether the native window is open.

NativeHandle

nint NativeHandle { get; }

Gets the platform-native top-level window handle, or zero when the window is not open.

SupportsCloseConfirmation

bool SupportsCloseConfirmation { get; }

Whether user close requests invoke the configured CloseRequested callback instead of closing.

SupportsDocumentStartScript

bool SupportsDocumentStartScript { get; }

Whether the host runs DesktopWindowHostOptions.DocumentStartScript in every frame's document before its page scripts. The surface then withholds session credentials from fetchable scripts.

Methods

BeginMoveAsync

ValueTask BeginMoveAsync(CancellationToken cancellationToken = default)

Starts a user-driven native move of the window, as when the page drags a frameless window.

Parameters

cancellationToken

Cancels the operation.

Returns

A task that completes when the move has started.

Remarks

Runic Desktop ignores a faulted task, so a host that cannot move the window may return a task faulted with NotSupportedException. Do not throw synchronously: that ends the session's receive loop.

CloseAsync

ValueTask CloseAsync(CancellationToken cancellationToken = default)

Closes the native window without invoking DesktopWindowHostOptions.CloseRequested.

Parameters

cancellationToken

Cancels waiting for the window to close.

Returns

A task that completes when the window has closed.

FocusAsync

ValueTask FocusAsync(CancellationToken cancellationToken = default)

Activates the window and gives it keyboard focus.

Parameters

cancellationToken

Cancels the operation.

Returns

A task that completes when the window has been focused.

MinimizeAsync

ValueTask MinimizeAsync(CancellationToken cancellationToken = default)

Minimizes the window.

Parameters

cancellationToken

Cancels the operation.

Returns

A task that completes when the window has been minimized.

MoveAsync

ValueTask MoveAsync(uint x, uint y, CancellationToken cancellationToken = default)

Moves the window to a screen position.

Parameters

x

The new horizontal position in pixels.

y

The new vertical position in pixels.

cancellationToken

Cancels the operation.

Returns

A task that completes when the window has been moved.

ValueTask NavigateAsync(Uri url, CancellationToken cancellationToken = default)

Navigates the open window's WebView to url.

Parameters

url

The URL to load.

cancellationToken

Cancels the navigation request.

Returns

A task that completes when navigation has started.

OpenAsync

ValueTask OpenAsync(Uri url, DesktopWindowHostOptions options, CancellationToken cancellationToken = default)

Creates and shows the native window and navigates its WebView to url.

Parameters

url

The surface URL to present.

options

The initial window state.

cancellationToken

Cancels opening.

Returns

A task that completes when the window exists and navigation has started.

Remarks

A failed or cancelled open must release any native resources it created; Runic Desktop then disposes the host.

ResizeAsync

ValueTask ResizeAsync(uint width, uint height, CancellationToken cancellationToken = default)

Resizes the window.

Parameters

width

The new width in pixels.

height

The new height in pixels.

cancellationToken

Cancels the operation.

Returns

A task that completes when the window has been resized.

SetVisibleAsync

ValueTask SetVisibleAsync(bool visible, CancellationToken cancellationToken = default)

Shows or hides the window without closing it.

Parameters

visible

true to show the window; false to hide it.

cancellationToken

Cancels the operation.

Returns

A task that completes when the visibility has changed.

ToggleMaximizedAsync

ValueTask ToggleMaximizedAsync(CancellationToken cancellationToken = default)

Maximizes the window, or restores it when it is already maximized.

Parameters

cancellationToken

Cancels the operation.

Returns

A task that completes when the window state has changed.

Events

Closed

event EventHandler? Closed

Occurs once after the native window has closed, whether the user or IDesktopWindowHost.CloseAsync closed it.

Remarks

It may be raised on the window's owning thread; Runic Desktop then disposes the host.