aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-21 21:59:43 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-21 21:59:43 -0600
commit9098cd1161be1c6e7175fdf48128faed6a4438f5 (patch)
tree6be9055a0c05620ee7be3bbd0e875b9a0560a715 /WireGuard/WireGuard/UI/iOS
parentLocalize remaining strings in network extension (diff)
downloadwireguard-apple-9098cd1161be1c6e7175fdf48128faed6a4438f5.tar.xz
wireguard-apple-9098cd1161be1c6e7175fdf48128faed6a4438f5.zip
Removing a tunnel from iOS's settings is now immediately reflected in app
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS')
-rw-r--r--WireGuard/WireGuard/UI/iOS/AppDelegate.swift7
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift2
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift26
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift9
4 files changed, 29 insertions, 15 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
index 428f732..9c3aa9f 100644
--- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
@@ -10,8 +10,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var mainVC: MainViewController?
- func application(_ application: UIApplication,
- willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
+ func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
let window = UIWindow(frame: UIScreen.main.bounds)
@@ -50,9 +49,7 @@ extension AppDelegate {
return true
}
- func application(_ application: UIApplication,
- viewControllerWithRestorationIdentifierPath identifierComponents: [String],
- coder: NSCoder) -> UIViewController? {
+ func application(_ application: UIApplication, viewControllerWithRestorationIdentifierPath identifierComponents: [String], coder: NSCoder) -> UIViewController? {
guard let vcIdentifier = identifierComponents.last else { return nil }
if vcIdentifier.hasPrefix("TunnelDetailVC:") {
let tunnelName = String(vcIdentifier.suffix(vcIdentifier.count - "TunnelDetailVC:".count))
diff --git a/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift b/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift
index 294964a..7ab3965 100644
--- a/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift
@@ -72,7 +72,7 @@ class TunnelListCell: UITableViewCell {
statusSwitch.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
}
-
+
@objc func switchToggled() {
onSwitchToggled?(statusSwitch.isOn)
}
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
index 1e480b9..2798127 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
@@ -7,8 +7,8 @@ class MainViewController: UISplitViewController {
var tunnelsManager: TunnelsManager?
var onTunnelsManagerReady: ((TunnelsManager) -> Void)?
-
var tunnelsListVC: TunnelsListTableViewController?
+ private var foregroundObservationToken: AnyObject?
init() {
let detailVC = UIViewController()
@@ -57,7 +57,31 @@ class MainViewController: UISplitViewController {
self.onTunnelsManagerReady?(tunnelsManager)
self.onTunnelsManagerReady = nil
}
+
+ foregroundObservationToken = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: OperationQueue.main) { [weak self] _ in
+ guard let self = self else { return }
+ self.tunnelsManager?.reload { [weak self] hasChanges in
+ guard let self = self, let tunnelsManager = self.tunnelsManager, hasChanges else { return }
+
+ self.tunnelsListVC?.setTunnelsManager(tunnelsManager: tunnelsManager)
+
+ if self.isCollapsed {
+ (self.viewControllers[0] as? UINavigationController)?.popViewController(animated: false)
+ } else {
+ let detailVC = UIViewController()
+ detailVC.view.backgroundColor = .white
+ let detailNC = UINavigationController(rootViewController: detailVC)
+ self.showDetailViewController(detailNC, sender: self)
+ }
+
+ if let presentedNavController = self.presentedViewController as? UINavigationController, presentedNavController.viewControllers.first is TunnelEditTableViewController {
+ self.presentedViewController?.dismiss(animated: false, completion: nil)
+ }
+ }
+
+ }
}
+
}
extension MainViewController: TunnelsManagerActivationDelegate {
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
index 187f7fd..2912e07 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift
@@ -3,8 +3,6 @@
import UIKit
-// MARK: TunnelDetailTableViewController
-
class TunnelDetailTableViewController: UITableViewController {
private enum Section {
@@ -44,11 +42,6 @@ class TunnelDetailTableViewController: UITableViewController {
fatalError("init(coder:) has not been implemented")
}
- deinit {
- onDemandStatusObservationToken = nil
- statusObservationToken = nil
- }
-
override func viewDidLoad() {
super.viewDidLoad()
title = tunnelViewModel.interfaceData[.name]
@@ -250,7 +243,7 @@ extension TunnelDetailTableViewController {
return
}
}
- if self.splitViewController?.isCollapsed ?? true {
+ if self.splitViewController?.isCollapsed != false {
self.navigationController?.navigationController?.popToRootViewController(animated: true)
} else {
let detailVC = UIViewController()