public interface IDesktopWindowHost : 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
cancellationTokenCancels 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
cancellationTokenCancels 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
cancellationTokenCancels the operation.
Returns
A task that completes when the window has been focused.
MinimizeAsync
ValueTask MinimizeAsync(CancellationToken cancellationToken = default) Minimizes the window.
Parameters
cancellationTokenCancels 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
xThe new horizontal position in pixels.
yThe new vertical position in pixels.
cancellationTokenCancels the operation.
Returns
A task that completes when the window has been moved.
NavigateAsync
ValueTask NavigateAsync(Uri url, CancellationToken cancellationToken = default) Navigates the open window's WebView to url.
Parameters
urlThe URL to load.
cancellationTokenCancels 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
urlThe surface URL to present.
optionsThe initial window state.
cancellationTokenCancels 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
widthThe new width in pixels.
heightThe new height in pixels.
cancellationTokenCancels 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
visibletrueto show the window;falseto hide it.cancellationTokenCancels 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
cancellationTokenCancels 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.