private void UpdateConnectionStateIntegratedUI(Models.ConnectionState newStatus) { if (newStatus == Models.ConnectionState.Connecting || newStatus == Models.ConnectionState.Disconnecting || Manager.MainWindowViewModel.IsServerSwitching) { Manager.MainWindowViewModel.IsConnectionTransitioning = true; } else if (newStatus == Models.ConnectionState.Unprotected || newStatus == Models.ConnectionState.Protected) { Manager.MainWindowViewModel.IsConnectionTransitioning = false; } if (Manager.MainWindowViewModel.IsServerSwitching && (newStatus == Models.ConnectionState.Protected || newStatus == Models.ConnectionState.Unprotected)) { // Virtual delay for server switching UI display time Task.Delay(TimeSpan.FromSeconds(1.5)).Wait(); Manager.MainWindowViewModel.IsServerSwitching = false; // Show server switch Windows notification if (newStatus == Models.ConnectionState.Protected) { Manager.TrayIcon.ShowNotification(Manager.TranslationService.GetString("windows-notification-vpn-switch-title", UI.Resources.Localization.TranslationService.Args("currentServer", Manager.MainWindowViewModel.SwitchingServerFrom, new[] { "switchServer", Manager.MainWindowViewModel.SwitchingServerTo })), Manager.TranslationService.GetString("windows-notification-vpn-switch-content"), NotificationArea.ToastIconType.Switched); } } }
private void UpdateNetworkUI(Models.ConnectionState newStatus, Models.ConnectionStability newStability) { // Check for a captive portal if the settings option is enabled if (Manager.Settings.Network.CaptivePortalAlert) { // Attempt to resolve the captive portal detection host Manager.CaptivePortalDetector.ResolveCaptivePortalDetectionHost(); // Make sure to try and detect captive portals if connection stability is unstable/no signal if (newStability == Models.ConnectionStability.NoSignal || newStability == Models.ConnectionStability.Unstable) { // Initiate captive portal check if not already detected for the current network address if (!Manager.CaptivePortalDetector.CaptivePortalDetected && !string.IsNullOrEmpty(Manager.Settings.Network.CaptivePortalDetectionIp)) { Manager.Tunnel.DetectCaptivePortal(); } } // If captive portal is detected for the current network, monitor internet connection to determine if user has logged in to the captive portal or changed networks if (Manager.CaptivePortalDetector.CaptivePortalDetected && newStatus == Models.ConnectionState.Unprotected) { if (!Manager.CaptivePortalDetector.MonitoringInternetConnection && !Manager.CaptivePortalDetector.CaptivePortalLoggedIn) { Manager.CaptivePortalDetector.MonitorInternetConnectivity(); } } else if (Manager.CaptivePortalDetector.MonitoringInternetConnection) { Manager.CaptivePortalDetector.StopMonitorInternetConnectivity(); } } }
/// <summary> /// Wait until the connection state has changed, with an appropriate timeout. /// </summary> /// <param name="wantedState">State to wait for before returning.</param> /// <param name="timeout">Timeout before waiting will cease.</param> private void WaitForConnectionStateChange(Models.ConnectionState wantedState, TimeSpan timeout) { var completedTask = Task.WhenAny(Task.Run(() => { while (Manager.ConnectionStatusUpdater.LastConnectionStatus.Status != wantedState) { Task.Delay(TimeSpan.FromSeconds(1)); } }), Task.Delay(timeout)); if (Manager.ConnectionStatusUpdater.LastConnectionStatus.Status != wantedState) { throw new TimeoutException("Connection status did not change."); } }
private void UpdateConnectionStateUI(Models.ConnectionState newStatus) { var previousStatus = viewModel.Status; if (previousStatus != newStatus) { viewModel.Status = newStatus; // Also make sure to not pop up a "disconnected" notification if the initial connection fails if ( (newStatus == Models.ConnectionState.Protected || newStatus == Models.ConnectionState.Unprotected) && !(previousStatus == Models.ConnectionState.Connecting && newStatus == Models.ConnectionState.Unprotected) ) { if (newStatus == Models.ConnectionState.Protected) { Manager.IPInfoUpdater.StartThread(); Manager.TrayIcon.ShowNotification(Manager.TranslationService.GetString("windows-notification-vpn-on-title"), Manager.TranslationService.GetString("windows-notification-vpn-on-content"), NotificationArea.ToastIconType.Connected); } } if (newStatus == Models.ConnectionState.Unprotected) { if (previousStatus != Models.ConnectionState.Connecting) { Manager.IPInfoUpdater.StopThread(); } EnforceMinTransitionTime(minDisconnectingTime); viewModel.TunnelStatus = Models.ConnectionState.Unprotected; Manager.TrayIcon.ShowNotification(Manager.TranslationService.GetString("windows-notification-vpn-off-title"), Manager.TranslationService.GetString("windows-notification-vpn-off-content"), NotificationArea.ToastIconType.Disconnected); // Force poll account details to ensure that the user's current device hasn't been removed Manager.AccountInfoUpdater.ForcePollAccountInfo(); } else if (newStatus == Models.ConnectionState.Protected) { EnforceMinTransitionTime(minConnectingTime); viewModel.TunnelStatus = Models.ConnectionState.Protected; } } UpdateConnectionStateIntegratedUI(newStatus); }
private void UpdateTrayUI(Models.ConnectionState status, Models.ConnectionStability stability) { if (status != Models.ConnectionState.Protected) { Manager.TrayIcon.SetDisconnected(); return; } if (stability == Models.ConnectionStability.NoSignal) { Manager.TrayIcon.SetUnstable(); return; } else if (stability == Models.ConnectionStability.Unstable) { Manager.TrayIcon.SetIdle(); return; } Manager.TrayIcon.SetConnected(); }
/// <summary> /// Setter for <see cref="VpnStatusProperty"/>. /// </summary> /// <param name="d"><see cref="DependencyObject"/>.</param> /// <param name="value"><see cref="DependencyProperty"/> value.</param> public static void SetVpnStatus(DependencyObject d, Models.ConnectionState value) { d.SetValue(VpnStatusProperty, value); }