]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
macOS: show runtime configuration in tunnel manager
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 23 Jan 2019 23:33:22 +0000 (00:33 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 24 Jan 2019 00:37:57 +0000 (01:37 +0100)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift

index 6c3a0e98f702d680731cc3ab6ef2022ba49176b8..6a9aff1693d2001c44f8b15c25b9a8d9e1a87939 100644 (file)
@@ -37,7 +37,8 @@ class TunnelDetailTableViewController: NSViewController {
 
     let peerFields: [TunnelViewModel.PeerField] = [
         .publicKey, .preSharedKey, .endpoint,
-        .allowedIPs, .persistentKeepAlive
+        .allowedIPs, .persistentKeepAlive,
+        .rxBytes, .txBytes, .lastHandshakeTime
     ]
 
     let tableView: NSTableView = {
@@ -96,6 +97,8 @@ class TunnelDetailTableViewController: NSViewController {
         statusObservationToken = tunnel.observe(\TunnelContainer.status) { [weak self] _, _ in
             self?.updateStatus()
         }
+
+        // TODO(roopc): call reloadRuntimeConfiguration() once per second
     }
 
     required init?(coder: NSCoder) {
@@ -196,6 +199,7 @@ class TunnelDetailTableViewController: NSViewController {
         let shouldBeEnabled = (tunnel.status == .active || tunnel.status == .inactive)
         statusCheckbox.state = shouldBeChecked ? .on : .off
         statusCheckbox.isEnabled = shouldBeEnabled
+        reloadRuntimeConfiguration()
     }
 
     @objc func handleEditTunnelAction() {
@@ -228,6 +232,19 @@ class TunnelDetailTableViewController: NSViewController {
             dismiss(tunnelEditVC)
         }
     }
+
+    private func reloadRuntimeConfiguration() {
+        tunnel.getRuntimeTunnelConfiguration(completionHandler: {
+            guard let tunnelConfiguration = $0 else { return }
+            if tunnelConfiguration == self.tunnel.tunnelConfiguration {
+                return
+            }
+            self.tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnelConfiguration)
+            // TODO(roopc): make this not loose scroll position
+            self.tableView.reloadData()
+            self.tunnelEditVC = nil
+        })
+    }
 }
 
 extension TunnelDetailTableViewController: NSTableViewDataSource {
@@ -271,6 +288,7 @@ extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
         tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
         tableView.reloadData()
         self.tunnelEditVC = nil
+        updateStatus()
     }
 
     func tunnelEditingCancelled() {