Table of Contents

Class AvaloniaUiHosting

Namespace
VpnHood.AppUi.Hosting.Avalonia
Assembly
VpnHood.AppUi.Hosting.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 told which languages the UI has words for.

public static class AvaloniaUiHosting
Inheritance
AvaloniaUiHosting
Inherited Members

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(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

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(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(VpnHoodApi api, CancellationToken cancellationToken)

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.

Exceptions

InvalidOperationException

api is null.

OperationCanceledException

Over HTTP, 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.

PrepareAsync<TUi>(IAssetProvider?, CancellationToken)

Prepares the UI's content and its theme's colours, and tells the app which languages the UI has words for: 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(VpnHoodApi, CancellationToken) has not completed, so the UI has no app information 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

api or uiAssetProvider is null.