wireguard-apple/WireGuard/AppDelegate.swift

58 lines
1.8 KiB
Swift
Raw Normal View History

2018-05-23 19:49:10 +00:00
//
// Copyright © 2018 WireGuard LLC. All rights reserved.
2018-05-23 19:49:10 +00:00
//
import UIKit
2018-08-31 21:06:40 +00:00
import os.log
2018-05-23 19:49:10 +00:00
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var appCoordinator: AppCoordinator!
2018-10-02 16:12:30 +00:00
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2018-05-23 19:49:10 +00:00
self.window = UIWindow(frame: UIScreen.main.bounds)
appCoordinator = AppCoordinator(window: self.window!)
appCoordinator.start()
appCoordinator.checkAndCleanConfigs()
2018-05-23 19:49:10 +00:00
return true
}
2018-08-31 21:06:40 +00:00
2018-10-02 16:12:30 +00:00
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
2018-08-31 21:06:40 +00:00
defer {
do {
try FileManager.default.removeItem(at: url)
} catch {
os_log("Failed to remove item from Inbox: %{public}@", log: Log.general, type: .error, url.absoluteString)
}
}
2018-09-02 22:08:34 +00:00
if url.pathExtension == "conf" {
do {
try appCoordinator.importConfig(config: url)
} catch {
os_log("Unable to import config: %{public}@", log: Log.general, type: .error, url.absoluteString)
return false
}
return true
} else if url.pathExtension == "zip" {
do {
try appCoordinator.importConfigs(configZip: url)
} catch {
os_log("Unable to import config: %{public}@", log: Log.general, type: .error, url.absoluteString)
return false
}
return true
2018-08-31 21:06:40 +00:00
}
2018-09-02 22:08:34 +00:00
return false
2018-08-31 21:06:40 +00:00
}
func applicationWillEnterForeground(_ application: UIApplication) {
appCoordinator.checkAndCleanConfigs()
}
2018-05-23 19:49:10 +00:00
}