aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/AppDelegate.swift
blob: bf9573ec630223ac0e93d853897aa53d141d937f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
//  AppDelegate.swift
//  WireGuard
//
//  Created by Jeroen Leenarts on 23-05-18.
//  Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All rights reserved.
//

import UIKit
import os.log

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var appCoordinator: AppCoordinator!

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.appCoordinator = AppCoordinator(window: self.window!)
        self.appCoordinator.start()

        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
        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)
            }
        }
        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
        }
        return false

    }
}