diff options
author | Roopesh Chander <roop@roopc.net> | 2018-12-07 19:05:04 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-12-07 19:05:08 +0530 |
commit | 105eca7adcaa41f54228da53e237316e61f08c98 (patch) | |
tree | 84747d6faa72aced77dafb03aab79b641f8c2d64 /WireGuard/WireGuard/UI/iOS/AppDelegate.swift | |
parent | Main VC: No need to refresh statuses if the tunnelsManager isn't initialized yet (diff) | |
download | wireguard-apple-105eca7adcaa41f54228da53e237316e61f08c98.tar.xz wireguard-apple-105eca7adcaa41f54228da53e237316e61f08c98.zip |
State restoration: Restore tunnel detail view
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/AppDelegate.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/AppDelegate.swift | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift index 3b414dd..3116f7a 100644 --- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift @@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var mainVC: MainViewController? func application(_ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let window = UIWindow(frame: UIScreen.main.bounds) window.backgroundColor = UIColor.white @@ -36,3 +36,38 @@ class AppDelegate: UIResponder, UIApplicationDelegate { mainVC?.refreshTunnelConnectionStatuses() } } + +// MARK: State restoration + +extension AppDelegate { + func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { + return true + } + + func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool { + return true + } + + func application(_ application: UIApplication, + viewControllerWithRestorationIdentifierPath identifierComponents: [String], + coder: NSCoder) -> UIViewController? { + guard let vcIdentifier = identifierComponents.last else { return nil } + if (vcIdentifier == "MainVC") { + return MainViewController() + } else if (vcIdentifier == "TunnelsListVC") { + return TunnelsListTableViewController() + } else if (vcIdentifier.hasPrefix("TunnelDetailVC:")) { + let tunnelName = String(vcIdentifier.suffix(vcIdentifier.count - "TunnelDetailVC:".count)) + if let tunnelsManager = mainVC?.tunnelsManager { + if let tunnel = tunnelsManager.tunnel(named: tunnelName) { + return TunnelDetailTableViewController(tunnelsManager: tunnelsManager, tunnel: tunnel) + } + } else { + // Show it when tunnelsManager is available + mainVC?.showTunnelDetailForTunnel(named: tunnelName, animated: false) + } + + } + return nil + } +} |