Table of Contents

Class AvaloniaBrowserHost

Namespace
VpnHood.AppUi.Hosting.Avalonia.Browser
Assembly
VpnHood.AppUi.Hosting.Avalonia.Browser.dll

Provides the Avalonia UI in a browser: the page the app's web host hands a paired device, served by the app itself.

public static class AvaloniaBrowserHost
Inheritance
AvaloniaBrowserHost
Inherited Members

Remarks

Nothing of the app runs here: the API is dialed over HTTP at the address the page came from, with the token that address carries on the device or, on a paired phone, the browser's own cookie that carries the pairing; the UI's files are fetched from the same server, under /assets/, as they are asked for.

Methods

RunAsync<TUi>(string[], CancellationToken)

Runs the UI in the page: hands it the app's API over HTTP and its content from the server, then starts it.

public static Task RunAsync<TUi>(string[] args, CancellationToken cancellationToken) where TUi : Application, IAvaloniaUi, new()

Parameters

args string[]

The page's arguments: its address first, as main.js passes it; without one, http://localhost:9090/.

cancellationToken CancellationToken

The token to monitor for cancellation requests while the UI starts.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

TUi

The UI's application.

Remarks

The page must hold an element with the ID out, which the UI draws in. A canceled token stops the start until Avalonia starts; Avalonia's own start takes none.

Exceptions

InvalidOperationException

The UI's English words read as JSON null, or the host's own script is missing from its assembly.

JsonException

A file of the UI's content the UI needs cannot be read.

AssetNotFoundException

The UI's content has no file the UI needs.

UriFormatException

The page's address is not valid.

ApiException

The app failed with an exception of a type the transport does not rebuild, answered with an error it does not name, or answered with a body that cannot be read.

HttpRequestException

The app's web host could not be reached, or answered a request for content with a failure status other than 404.

OperationCanceledException

cancellationToken was canceled, or an HTTP request timed out.