diff options
author | Roopesh Chander <roop@roopc.net> | 2018-10-27 18:30:07 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-10-27 19:07:16 +0530 |
commit | a3e912a21ff18ce570d60e59216fb53ceeafb0d2 (patch) | |
tree | 0f90a3d78c11aa169749e1521e6b8f37d6919673 /WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift | |
parent | Xcode: Disable bitcode (diff) | |
download | wireguard-apple-a3e912a21ff18ce570d60e59216fb53ceeafb0d2.tar.xz wireguard-apple-a3e912a21ff18ce570d60e59216fb53ceeafb0d2.zip |
VPN: Better error and status handling
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift index c24828b..a041789 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift @@ -156,26 +156,12 @@ extension TunnelDetailTableViewController { cell.isSwitchInteractionEnabled = false guard let s = self else { return } if (isOn) { - s.tunnelsManager.activate(tunnel: s.tunnel) { [weak s] isActivated in - if (!isActivated) { - DispatchQueue.main.async { - cell.setSwitchStatus(isOn: false) - } - s?.showErrorAlert(title: "Could not activate", - message: "Could not activate the tunnel because of an internal error") - } - cell.isSwitchInteractionEnabled = true + s.tunnelsManager.startActivation(of: s.tunnel) { error in + print("Error while activating: \(String(describing: error))") } } else { - s.tunnelsManager.deactivate(tunnel: s.tunnel) { [weak s] isDeactivated in - cell.isSwitchInteractionEnabled = true - if (!isDeactivated) { - DispatchQueue.main.async { - cell.setSwitchStatus(isOn: true) - } - s?.showErrorAlert(title: "Could not deactivate", - message: "Could not deactivate the tunnel because of an internal error") - } + s.tunnelsManager.startDeactivation(of: s.tunnel) { error in + print("Error while deactivating: \(String(describing: error))") } } } @@ -251,10 +237,6 @@ class TunnelDetailTableViewStatusCell: UITableViewCell { var onSwitchToggled: ((Bool) -> Void)? = nil private var isOnSwitchToggledHandlerEnabled: Bool = true - func setSwitchStatus(isOn: Bool) { - statusSwitch.isOn = isOn - } - let statusSwitch: UISwitch private var statusObservervationToken: AnyObject? = nil @@ -289,13 +271,15 @@ class TunnelDetailTableViewStatusCell: UITableViewCell { text = "Deactivating" case .reasserting: text = "Reactivating" - case .waitingForOtherDeactivation: - text = "Waiting" case .resolvingEndpointDomains: text = "Resolving domains" } textLabel?.text = text - setSwitchStatus(isOn: !(status == .deactivating || status == .inactive)) + DispatchQueue.main.async { [weak statusSwitch] in + guard let statusSwitch = statusSwitch else { return } + statusSwitch.isOn = !(status == .deactivating || status == .inactive) + statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active || status == .resolvingEndpointDomains) + } textLabel?.textColor = (status == .active || status == .inactive) ? UIColor.black : UIColor.gray } |