public void HandleScreenChanged(bool active) { lock (m_clientSync) { if (m_client == null) { return; } if (active) { if (m_clientPaused) { m_clientPaused = false; LogsManager.Instance.Debug("Client has been paused, trying resume VPN..."); if (m_client.Resume()) { LogsManager.Instance.Debug("Client resumed"); } else { LogsManager.Instance.Error("Client resume failed"); } } } else { if (settingsManager.SystemPauseVpnWhenScreenIsOff) { LogsManager.Instance.Debug("Battery saver is on, trying to pause VPN..."); if (m_client.Pause("screen_off")) { m_clientPaused = true; LogsManager.Instance.Debug("Client paused"); } else { LogsManager.Instance.Debug("Client pause failed"); } } } } }
public VPN.Status HandleScreenChanged(bool active) { if (vpnClientStatus == VPN.Status.LOCKED) { return(vpnClientStatus); } lock (clientSync) { if (openVPNClient == null) { return(vpnClientStatus); } if (active) { if (vpnClientStatus == VPN.Status.PAUSED) { EddieLogger.Info("Screen is now on, trying to resume VPN"); NativeMethods.EddieLibraryResult result = openVPNClient.Resume(); if (result.code == NativeMethods.ResultCode.SUCCESS) { EddieLogger.Info("Successfully resumed VPN"); vpnClientStatus = VPN.Status.CONNECTED; } else { EddieLogger.Error(string.Format("Failed to resume VPN. {0}", result.description)); vpnClientStatus = VPN.Status.UNKNOWN; } } } else { if (settingsManager.SystemPauseVpnWhenScreenIsOff) { EddieLogger.Info("Screen is now off, trying to pause VPN"); NativeMethods.EddieLibraryResult result = openVPNClient.Pause("Screen is off"); if (result.code == NativeMethods.ResultCode.SUCCESS) { EddieLogger.Info("Successfully paused VPN"); vpnClientStatus = VPN.Status.PAUSED; } else { EddieLogger.Error(string.Format("Failed to pause VPN. {0}", result.description)); vpnClientStatus = VPN.Status.NOT_CONNECTED; } } } } UpdateNotification(vpnClientStatus); return(vpnClientStatus); }