e2384e143c
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
66 lines
2.3 KiB
Swift
66 lines
2.3 KiB
Swift
// SPDX-License-Identifier: MIT
|
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
|
|
|
import UIKit
|
|
import os.log
|
|
|
|
@UIApplicationMain
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
var window: UIWindow?
|
|
var mainVC: MainViewController?
|
|
|
|
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
|
|
|
|
let window = UIWindow(frame: UIScreen.main.bounds)
|
|
window.backgroundColor = .white
|
|
self.window = window
|
|
|
|
let mainVC = MainViewController()
|
|
window.rootViewController = mainVC
|
|
window.makeKeyAndVisible()
|
|
|
|
self.mainVC = mainVC
|
|
|
|
return true
|
|
}
|
|
|
|
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
|
mainVC?.tunnelsListVC?.importFromFile(url: url) {
|
|
_ = FileManager.deleteFile(at: url)
|
|
}
|
|
return true
|
|
}
|
|
|
|
func applicationDidBecomeActive(_ application: UIApplication) {
|
|
mainVC?.refreshTunnelConnectionStatuses()
|
|
}
|
|
}
|
|
|
|
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.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
|
|
}
|
|
}
|