aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Coordinators/AppCoordinator+TunnelInfoTableViewControllerDelegate.swift
blob: aa6f3f2a4cbc53b12a8d406b0db63a8e0c3af745 (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
//
//  Copyright © 2018 WireGuard LLC. All rights reserved.
//

import Foundation
import NetworkExtension

extension AppCoordinator: TunnelInfoTableViewControllerDelegate {
    func connect(tunnel: Tunnel, tunnelInfoTableViewController: TunnelInfoTableViewController) {
        connect(tunnel: tunnel)
    }

    func disconnect(tunnel: Tunnel, tunnelInfoTableViewController: TunnelInfoTableViewController) {
        disconnect(tunnel: tunnel)
    }

    func status(for tunnel: Tunnel, tunnelInfoTableViewController: TunnelInfoTableViewController) -> NEVPNStatus {
        let session = self.providerManager(for: tunnel)?.connection as? NETunnelProviderSession
        return session?.status ?? .invalid
    }

    func configure(tunnel: Tunnel, tunnelInfoTableViewController: TunnelInfoTableViewController) {
        let editContext = persistentContainer.newBackgroundContext()
        var backgroundTunnel: Tunnel?
        editContext.performAndWait {
            backgroundTunnel = editContext.object(with: tunnel.objectID) as? Tunnel
        }

        showTunnelConfigurationViewController(tunnel: backgroundTunnel, context: editContext)
    }

}