macOS: show runtime configuration in tunnel manager

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2019-01-24 00:33:22 +01:00
parent 22625e8cc4
commit 2fe9f83ba5
1 changed files with 19 additions and 1 deletions

View File

@ -37,7 +37,8 @@ class TunnelDetailTableViewController: NSViewController {
let peerFields: [TunnelViewModel.PeerField] = [ let peerFields: [TunnelViewModel.PeerField] = [
.publicKey, .preSharedKey, .endpoint, .publicKey, .preSharedKey, .endpoint,
.allowedIPs, .persistentKeepAlive .allowedIPs, .persistentKeepAlive,
.rxBytes, .txBytes, .lastHandshakeTime
] ]
let tableView: NSTableView = { let tableView: NSTableView = {
@ -96,6 +97,8 @@ class TunnelDetailTableViewController: NSViewController {
statusObservationToken = tunnel.observe(\TunnelContainer.status) { [weak self] _, _ in statusObservationToken = tunnel.observe(\TunnelContainer.status) { [weak self] _, _ in
self?.updateStatus() self?.updateStatus()
} }
// TODO(roopc): call reloadRuntimeConfiguration() once per second
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
@ -196,6 +199,7 @@ class TunnelDetailTableViewController: NSViewController {
let shouldBeEnabled = (tunnel.status == .active || tunnel.status == .inactive) let shouldBeEnabled = (tunnel.status == .active || tunnel.status == .inactive)
statusCheckbox.state = shouldBeChecked ? .on : .off statusCheckbox.state = shouldBeChecked ? .on : .off
statusCheckbox.isEnabled = shouldBeEnabled statusCheckbox.isEnabled = shouldBeEnabled
reloadRuntimeConfiguration()
} }
@objc func handleEditTunnelAction() { @objc func handleEditTunnelAction() {
@ -228,6 +232,19 @@ class TunnelDetailTableViewController: NSViewController {
dismiss(tunnelEditVC) 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 { extension TunnelDetailTableViewController: NSTableViewDataSource {
@ -271,6 +288,7 @@ extension TunnelDetailTableViewController: TunnelEditViewControllerDelegate {
tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration) tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnel.tunnelConfiguration)
tableView.reloadData() tableView.reloadData()
self.tunnelEditVC = nil self.tunnelEditVC = nil
updateStatus()
} }
func tunnelEditingCancelled() { func tunnelEditingCancelled() {