aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Coordinators/AppCoordinator.swift
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-16 22:05:22 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-16 22:05:22 +0200
commit603953a8b878961545c03dae51c089c558f50131 (patch)
treeb0230d6daa28946a925c849e62c968cfab2b9d7b /WireGuard/Coordinators/AppCoordinator.swift
parentAdd on demand rule. (diff)
downloadwireguard-apple-603953a8b878961545c03dae51c089c558f50131.tar.xz
wireguard-apple-603953a8b878961545c03dae51c089c558f50131.zip
If the selected tunnel is not "enabled", make it enabled.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/Coordinators/AppCoordinator.swift19
1 files changed, 14 insertions, 5 deletions
diff --git a/WireGuard/Coordinators/AppCoordinator.swift b/WireGuard/Coordinators/AppCoordinator.swift
index f49819a..75657f0 100644
--- a/WireGuard/Coordinators/AppCoordinator.swift
+++ b/WireGuard/Coordinators/AppCoordinator.swift
@@ -166,11 +166,20 @@ extension AppCoordinator: TunnelsTableViewControllerDelegate {
// Should the manager be enabled?
let manager = providerManager(for: tunnel)
- let session = manager?.connection as! NETunnelProviderSession //swiftlint:disable:this force_cast
- do {
- try session.startTunnel()
- } catch let error {
- os_log("error starting tunnel: %{public}@", log: Log.general, type: .error, error.localizedDescription)
+ manager?.isEnabled = true
+ manager?.saveToPreferences { (error) in
+ if let error = error {
+ os_log("error saving preferences: %{public}@", log: Log.general, type: .error, error.localizedDescription)
+ return
+ }
+ os_log("saved preferences", log: Log.general, type: .info)
+
+ let session = manager?.connection as! NETunnelProviderSession //swiftlint:disable:this force_cast
+ do {
+ try session.startTunnel()
+ } catch let error {
+ os_log("error starting tunnel: %{public}@", log: Log.general, type: .error, error.localizedDescription)
+ }
}
}