Class VhApp
- Namespace
- VpnHood.AppUi.Common
- Assembly
- VpnHood.AppUi.Common.dll
Provides what the UI's pages read off the app, and the one way they reach it: the app's API, in process or over HTTP from a paired browser.
public static class VhApp
- Inheritance
-
VhApp
- Inherited Members
Remarks
The pages read plain values held here, the features, the state, the settings and the profiles, never the app itself, so the same pages run on the device and in a browser. The state is read again every second by the home's clock and after every action; the rest when the state says the configuration moved or a page saved; the account when the state says it changed.
Properties
Account
Gets the signed-in person's account, as last read, or null.
public static Account? Account { get; }
Property Value
Remarks
It is read at start, after this UI's sign-in, sign-out or purchase, and when the state says it changed; never polled.
Api
Gets the app's API.
public static VpnHoodApi Api { get; }
Property Value
Exceptions
- InvalidOperationException
The UI has not been given the app's API (Init(VpnHoodApi, CancellationToken)).
AvailableCultureInfos
Gets the languages the app offers, as last read.
public static IReadOnlyList<UiCultureInfo> AvailableCultureInfos { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
CanGoPremium
Gets a value indicating whether premium can be bought or had by a code for the current VPN profile.
public static bool CanGoPremium { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
CanImportAccessCode
Gets a value indicating whether a premium code can be typed for the current VPN profile.
public static bool CanImportAccessCode { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
CanTryPremium
Gets a value indicating whether the current VPN profile offers a premium trial.
public static bool CanTryPremium { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
CanViewAccessCode
Gets a value indicating whether the current VPN profile's premium code may be shown.
public static bool CanViewAccessCode { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
CurrentVpnProfileInfo
Gets the VPN profile the app is set to, whole, from the last configuration read, or null.
public static VpnProfileInfo? CurrentVpnProfileInfo { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
Descriptor
Gets the app's descriptor, as last read.
public static AppDescriptor Descriptor { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
HasPasswordSignIn
Gets a value indicating whether the password sign-in is offered.
public static bool HasPasswordSignIn { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
HasSignInChoice
Gets a value indicating whether the person chooses how to sign in: several methods, or the password's first.
public static bool HasSignInChoice { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
Intents
Gets what the UI may ask of the device, as last read.
public static DeviceIntentFeatures Intents { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsAnonymousTrackerSupported
Gets a value indicating whether the app supports reporting anonymous usage: the whole answer, as this head has no web analytics of its own.
public static bool IsAnonymousTrackerSupported { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsConfigured
Gets a value indicating whether the head has configured the UI (Configure(IReadOnlyList<string>, CancellationToken)).
public static bool IsConfigured { get; }
Property Value
IsInit
Gets a value indicating whether the UI has the app's API.
public static bool IsInit { get; }
Property Value
IsPremiumByAccount
Gets a value indicating whether the premium comes from the account's subscription.
public static bool IsPremiumByAccount { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsPremiumSupported
Gets a value indicating whether the build has a premium tier; without one, it is the full app.
public static bool IsPremiumSupported { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsPremiumUser
Gets a value indicating whether the current VPN profile is premium.
public static bool IsPremiumUser { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsRemote
Gets a value indicating whether this UI is the remote: served by the app to a browser on another device.
public static bool IsRemote { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsSingleProfileMode
Gets a value indicating whether the app takes no access keys, so its profiles are the ones it was built with.
public static bool IsSingleProfileMode { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsStarlinkToolsEnabled
Gets a value indicating whether the Starlink tools are on: the debug command /starlink is set, on Android or in a debug build.
public static bool IsStarlinkToolsEnabled { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsTvRemote
Gets a value indicating whether this UI is a browser driving a TV, so a wait for what the TV's own screen asks says to go on there.
public static bool IsTvRemote { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsTvUi
Gets a value indicating whether the UI takes the TV layout: the device is a TV, and this UI is not the remote.
public static bool IsTvUi { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
PrimaryProviderId
Gets the first sign-in method that is not the password's, or null.
public static string? PrimaryProviderId { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
State
Gets the app's state, as last read.
public static AppState State { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
UserSettings
Gets the person's settings, as last read.
public static UserSettings UserSettings { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
VpnProfileId
Gets the current VPN profile's ID: the state's, else the settings'.
public static Guid? VpnProfileId { get; }
Property Value
- Guid?
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
VpnProfileInfos
Gets the VPN profiles, as last read.
public static IReadOnlyList<VpnProfileInfo> VpnProfileInfos { get; }
Property Value
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
Methods
ActiveProtocol(AppState)
Gets the protocol in use: the session's while connected, else the settings'.
public static ChannelProtocol ActiveProtocol(AppState state)
Parameters
stateAppStateThe app's state.
Returns
- ChannelProtocol
The protocol.
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
Configure(IReadOnlyList<string>, CancellationToken)
Tells the app which languages the UI has words for, and gives it the UI's words for its own text: the head's second step, once the UI can say which languages it has.
public static Task Configure(IReadOnlyList<string> availableCultures, CancellationToken cancellationToken)
Parameters
availableCulturesIReadOnlyList<string>The languages the UI has words for.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
From then on, the app gets the UI's words again whenever the UI's language changes.
Exceptions
- OperationCanceledException
cancellationTokenwas 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, answered with an error it does not name, or answered with a body that cannot be read.
- InvalidOperationException
The UI has not been given the app's API (Init(VpnHoodApi, CancellationToken)), or the words have not been loaded (InitAsync(IAssetProvider, CancellationToken)).
FindVpnProfileInfo(Guid?)
Finds a VPN profile in the last configuration read.
public static VpnProfileInfo? FindVpnProfileInfo(Guid? vpnProfileId)
Parameters
Returns
- VpnProfileInfo
The profile, or null where there is none.
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
Init(VpnHoodApi, CancellationToken)
Gives the UI the app's API, and reads the app's information through it: the head's first step, before Avalonia starts, as the features read decide the theme.
public static Task Init(VpnHoodApi api, CancellationToken cancellationToken)
Parameters
apiVpnHoodApiThe app's API.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
In process the read completes at once.
Exceptions
- OperationCanceledException
cancellationTokenwas 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, answered with an error it does not name, or answered with a body that cannot be read.
IsConnected()
Gets whether the last state read is connected: connected or unstable.
public static bool IsConnected()
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsConnected(AppState)
Gets whether a state is connected: connected or unstable.
public static bool IsConnected(AppState state)
Parameters
stateAppStateThe app's state.
Returns
IsCustomEndpointActive(AppState)
Gets whether the current VPN profile connects to server addresses the person gave.
public static bool IsCustomEndpointActive(AppState state)
Parameters
stateAppStateThe app's state.
Returns
IsDnsCustomized(AppState)
Gets whether the DNS is customized: the device's private DNS names a provider, or the settings use the adapter's DNS where custom DNS is allowed.
public static bool IsDnsCustomized(AppState state)
Parameters
stateAppStateThe app's state.
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsLocalNetworkAvailable(AppState)
Gets whether the local network can be reached: while disconnected, or where the session allows it.
public static bool IsLocalNetworkAvailable(AppState state)
Parameters
stateAppStateThe app's state.
Returns
IsLocationAutoSelected(string?)
Gets whether a server location is the automatic one, or /*.
public static bool IsLocationAutoSelected(string? serverLocation)
Parameters
Returns
IsNotificationEnabled(AppState)
Gets whether the app's notifications are enabled.
public static bool IsNotificationEnabled(AppState state)
Parameters
stateAppStateThe app's state.
Returns
IsPremiumFeature(AppFeature)
Gets whether the build's premium tier sells a feature.
public static bool IsPremiumFeature(AppFeature feature)
Parameters
featureAppFeatureThe feature.
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsPremiumFeatureAllowed(AppFeature)
Gets whether a feature is allowed: always without a premium tier or for a feature the tier does not sell, else for a premium profile.
public static bool IsPremiumFeatureAllowed(AppFeature feature)
Parameters
featureAppFeatureThe feature.
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsPrivateDnsActive(AppState)
Gets whether the device's private DNS is active.
public static bool IsPrivateDnsActive(AppState state)
Parameters
stateAppStateThe app's state.
Returns
IsPrivateDnsCustomized(AppState)
Gets whether the device's private DNS names a provider of its own.
public static bool IsPrivateDnsCustomized(AppState state)
Parameters
stateAppStateThe app's state.
Returns
IsProtocolEnabled(AppState, ChannelProtocol)
Gets whether a protocol can be chosen: the session's protocols while there is a session, else the build's.
public static bool IsProtocolEnabled(AppState state, ChannelProtocol protocol)
Parameters
stateAppStateThe app's state.
protocolChannelProtocolThe protocol.
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsShowProtocol(ChannelProtocol)
Gets whether the build offers a protocol.
public static bool IsShowProtocol(ChannelProtocol protocol)
Parameters
protocolChannelProtocolThe protocol.
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
IsTcpForwardingSwitchOn(AppState)
Gets the TCP forwarding switch as the person sees it: on or off where the server or the split by domain forces it, else the setting.
public static bool IsTcpForwardingSwitchOn(AppState state)
Parameters
stateAppStateThe app's state.
Returns
Remarks
It is never the session's status, which a save does not wait for.
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
LoadAccount(bool, CancellationToken)
Reads the account, after a refresh from the account backend where asked.
public static Task LoadAccount(bool withRefresh, CancellationToken cancellationToken)
Parameters
withRefreshbooltrue to refresh it from the account backend first; a failed refresh is ignored, and the read that follows may still fail.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
An older read that answers after a newer one is not shown.
Exceptions
- OperationCanceledException
cancellationTokenwas 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, answered with an error it does not name, or answered with a body that cannot be read.
- NotSupportedException
A premium code waits to be uploaded, and the account backend keeps no codes on the account.
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)), or the account's read found no current VPN profile, or several and none selected.
ReloadInfo(CancellationToken)
Reads the app's information again, with its state.
public static Task ReloadInfo(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- OperationCanceledException
cancellationTokenwas 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, answered with an error it does not name, or answered with a body that cannot be read.
- InvalidOperationException
The UI has not been given the app's API (Init(VpnHoodApi, CancellationToken)).
ReloadState(CancellationToken)
Reads the app's state again; where the configuration moved, the information too; and where the account changed, the account.
public static Task ReloadState(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
A failed account read is logged and tried again after a pause; the state still shows.
Exceptions
- OperationCanceledException
cancellationTokenwas 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, answered with an error it does not name, or answered with a body that cannot be read.
- InvalidOperationException
The UI has not been given the app's API (Init(VpnHoodApi, CancellationToken)).
SaveUserSettings(UserSettings, CancellationToken)
Saves the person's settings, and reads the information again, as the app applies them and may correct a value.
public static Task SaveUserSettings(UserSettings userSettings, CancellationToken cancellationToken)
Parameters
userSettingsUserSettingsThe settings: the object read here and changed.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Exceptions
- OperationCanceledException
cancellationTokenwas 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, answered with an error it does not name, or answered with a body that cannot be read.
- InvalidOperationException
The UI has not been given the app's API (Init(VpnHoodApi, CancellationToken)).
ShowCrown(bool)
Gets whether to show the crown on something: where it is premium, and the profile is not.
public static bool ShowCrown(bool isPremium)
Parameters
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).
ShowCrown(AppFeature)
Gets whether to show the crown on a feature: where the tier sells it, and the profile is not premium.
public static bool ShowCrown(AppFeature feature)
Parameters
featureAppFeatureThe feature.
Returns
Exceptions
- InvalidOperationException
The app's information has not been read (Init(VpnHoodApi, CancellationToken)).