Class AvaloniaDesktopHost
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
argsstring[]The command-line arguments Avalonia's lifetime gets.
apiVpnHoodApiThe app's API, over HTTP against an app in another process, or the app's own in this one.
uiAssetProviderIAssetProviderThe UI's content store, which the UI reads its pictures and its words from.
useTraybooltrue to put the app's icon in the desktop's tray.
keepRunningWhileConnectedbooltrue to hide the window, rather than end the run, while the app's VPN can be disconnected.
shellIDesktopShellThe desktop's shell, or null.
startHiddenbooltrue to start in the tray, the window kept back until it is asked for.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests while the run starts.
Type Parameters
TUiThe 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
uiAssetProvideris null, or the UI made no main window or is not a VpnHoodAvaloniaAppBase.- OperationCanceledException
cancellationTokenwas canceled before the window's loop started.