Table of Contents

Class AvaloniaDesktopHost

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

Provides an Avalonia UI in a window on a desktop, with the app's icon in the desktop's tray where the host allows one.

public static class AvaloniaDesktopHost
Inheritance
AvaloniaDesktopHost
Inherited Members

Remarks

While the run uses a tray and the desktop shows tray icons, closing the window only hides it: the tray's Open and a second launch bring it back, and the run ends with the tray's Exit or the host's shutdown. Otherwise closing the window ends the run, unless the run is to keep going while the app in this process is connected: the window then hides while the app's VPN can be disconnected, a connect under way included, and the run ends once it cannot, unless a launch shows the window first. On Windows the window's taskbar button carries the connection's badge too. The run takes the calling thread as the UI thread.

Methods

Run<TUi>(string[], VpnHoodApi, IAssetProvider?, bool, bool, IDesktopShell?, bool, CancellationToken)

Runs the window over the app's API until the run ends, on the calling thread.

public static void Run<TUi>(string[] args, VpnHoodApi api, IAssetProvider? uiAssetProvider, bool useTray, bool keepRunningWhileConnected, IDesktopShell? shell, bool startHidden, CancellationToken cancellationToken) where TUi : Application, IAvaloniaUi, new()

Parameters

args string[]

The command-line arguments Avalonia's lifetime gets.

api VpnHoodApi

The app's API, over HTTP against an app in another process, or the app's own in this one.

uiAssetProvider IAssetProvider

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

useTray bool

true to put the app's icon in the desktop's tray.

keepRunningWhileConnected bool

true to hide the window, rather than end the run, while the app's VPN can be disconnected.

shell IDesktopShell

The desktop's shell, or null.

startHidden bool

true to start in the tray, the window kept back until it is asked for.

cancellationToken CancellationToken

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

Type Parameters

TUi

The UI's application.

Remarks

A run that starts in the tray waits up to 30 seconds for the desktop to show tray icons, as a sign-in may start before its panel, and ends at once where none show, unless a launch asks for the window first. A canceled token ends the run only while it starts; to have a cancel end the running window too, run it through AvaloniaDesktopUi<TUi>. The window takes the shape its UI states, fitted to its screen, with its title bar in the UI's colour where the UI names one and the platform lets it be set.

Exceptions

InvalidOperationException

uiAssetProvider is null, or the UI made no main window or is not a VpnHoodAvaloniaAppBase.

OperationCanceledException

cancellationToken was canceled before the window's loop started.