Table of Contents

Class AvaloniaUiHosting

Namespace
VpnHood.AppHosting.Avalonia
Assembly
VpnHood.AppHosting.Avalonia.dll

Provides the Avalonia UI's start, for every host: the app's API handed to the UI, then the UI's content, its words and its fonts, and the app configured for the UI.

public static class AvaloniaUiHosting
Inheritance
AvaloniaUiHosting

Remarks

A desktop window, an iOS scene and a browser page run it whole (StartAsync<TUi>(VpnHoodApi, IAssetProvider?, CancellationToken)). Android runs it in two halves: the API from the process's application, before Avalonia initializes, as the features it reads decide the theme (InitAsync<TUi>(VpnHoodApi, CancellationToken)); the rest from the activity, before it makes the view (PrepareAsync<TUi>(IAssetProvider?, CancellationToken)). An in-process host may wait for it on the calling thread, a UI thread included, where the UI's own content preparation does not need that thread to complete. The host's lifetime and its UI context stay the host's.

Properties

AppName

Gets the app's name, as the app's information gave it when the UI was started.

public static string AppName { get; }

Property Value

string

Exceptions

InvalidOperationException

The UI has not been started (InitAsync<TUi>(VpnHoodApi, CancellationToken)).

CopyText

Gets or sets how a browser page on plain http puts text on the clipboard, where the browser gives Avalonia's own way none; the browser host names it, and it is null anywhere else.

public static Action<string>? CopyText { get; set; }

Property Value

Action<string>

DownloadText

Gets or sets how a text file, by its name and its text, is handed to the person through a browser page's downloads, so it lands on the device in their hand; the browser host names it, and it is null anywhere else.

public static Action<string, string>? DownloadText { get; set; }

Property Value

Action<string, string>

Shell

Gets or sets the system's ways for links and the clipboard where Avalonia's own are refused, as in a sandboxed app, which a desktop host names before the UI starts; or null for Avalonia's own.

public static IDesktopShell? Shell { get; set; }

Property Value

IDesktopShell

Methods

InitAsync<TUi>(VpnHoodApi, CancellationToken)

Hands the UI the app's API, and reads the app's information: the first half of StartAsync<TUi>(VpnHoodApi, IAssetProvider?, CancellationToken).

public static Task InitAsync<TUi>(VpnHoodApi api, CancellationToken cancellationToken) where TUi : IAvaloniaUi

Parameters

api VpnHoodApi

The app's API: the app's own in process, or the same six interfaces over HTTP from a browser page.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

TUi

The UI's application.

Exceptions

OperationCanceledException

cancellationToken was canceled, or, over HTTP, a request timed out.

HttpRequestException

Over HTTP, the app could not be reached.

ApiException

Over HTTP, the app failed with an exception of a type the transport does not rebuild, or answered with an error it does not name.

PrepareAsync<TUi>(IAssetProvider?, CancellationToken)

Prepares the UI's content and its theme's colours, then has the UI configure the app for it: the second half of StartAsync<TUi>(VpnHoodApi, IAssetProvider?, CancellationToken).

public static Task PrepareAsync<TUi>(IAssetProvider? uiAssetProvider, CancellationToken cancellationToken) where TUi : IAvaloniaUi

Parameters

uiAssetProvider IAssetProvider

The UI's content store, which the UI reads its pictures and its words from.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

TUi

The UI's application.

Exceptions

OperationCanceledException

cancellationToken was canceled.

ApiException

Over HTTP, the app failed with an exception of a type the transport does not rebuild, or answered with an error it does not name.

InvalidOperationException

uiAssetProvider is null, or InitAsync<TUi>(VpnHoodApi, CancellationToken) has not completed, so the UI has no app yet.

StartAsync<TUi>(VpnHoodApi, IAssetProvider?, CancellationToken)

Starts the UI whole: hands it the app's API, then prepares its content.

public static Task StartAsync<TUi>(VpnHoodApi api, IAssetProvider? uiAssetProvider, CancellationToken cancellationToken) where TUi : IAvaloniaUi

Parameters

api VpnHoodApi

The app's API: the app's own in process, or the same six interfaces over HTTP from a browser page.

uiAssetProvider IAssetProvider

The UI's content store, which the UI reads its pictures and its words from.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

TUi

The UI's application.

Exceptions

OperationCanceledException

cancellationToken was canceled.

ApiException

Over HTTP, the app failed with an exception of a type the transport does not rebuild, or answered with an error it does not name.

InvalidOperationException

uiAssetProvider is null.