aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-31 14:43:37 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-31 16:48:51 +0530
commit70ac48ceba82639b22469f5cab91d01527ae0e45 (patch)
tree84c5443a893e1753f8a060ea9678e530d10a8987 /WireGuard
parentLogger: Convert do-catch to try? (diff)
downloadwireguard-apple-70ac48ceba82639b22469f5cab91d01527ae0e45.tar.xz
wireguard-apple-70ac48ceba82639b22469f5cab91d01527ae0e45.zip
macOS: Tunnel detail: Reload runtime config every second
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift30
1 files changed, 24 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
index 6a9aff16..489e868c 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
@@ -86,6 +86,7 @@ class TunnelDetailTableViewController: NSViewController {
private var tableViewModelRows = [TableViewModelRow]()
private var statusObservationToken: AnyObject?
private var tunnelEditVC: TunnelEditViewController?
+ private var reloadRuntimeConfigurationTimer: Timer?
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer) {
self.tunnelsManager = tunnelsManager
@@ -97,8 +98,6 @@ class TunnelDetailTableViewController: NSViewController {
statusObservationToken = tunnel.observe(\TunnelContainer.status) { [weak self] _, _ in
self?.updateStatus()
}
-
- // TODO(roopc): call reloadRuntimeConfiguration() once per second
}
required init?(coder: NSCoder) {
@@ -199,7 +198,11 @@ class TunnelDetailTableViewController: NSViewController {
let shouldBeEnabled = (tunnel.status == .active || tunnel.status == .inactive)
statusCheckbox.state = shouldBeChecked ? .on : .off
statusCheckbox.isEnabled = shouldBeEnabled
- reloadRuntimeConfiguration()
+ if tunnel.status == .active {
+ startUpdatingRuntimeConfiguration()
+ } else if tunnel.status == .inactive {
+ stopUpdatingRuntimeConfiguration()
+ }
}
@objc func handleEditTunnelAction() {
@@ -231,20 +234,35 @@ class TunnelDetailTableViewController: NSViewController {
if let tunnelEditVC = tunnelEditVC {
dismiss(tunnelEditVC)
}
+ stopUpdatingRuntimeConfiguration()
}
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
})
}
+
+ func startUpdatingRuntimeConfiguration() {
+ reloadRuntimeConfiguration()
+ reloadRuntimeConfigurationTimer?.invalidate()
+ let reloadTimer = Timer(timeInterval: 1 /* second */, repeats: true) { [weak self] _ in
+ self?.reloadRuntimeConfiguration()
+ }
+ reloadRuntimeConfigurationTimer = reloadTimer
+ RunLoop.main.add(reloadTimer, forMode: .default)
+ }
+
+ func stopUpdatingRuntimeConfiguration() {
+ reloadRuntimeConfiguration()
+ reloadRuntimeConfigurationTimer?.invalidate()
+ reloadRuntimeConfigurationTimer = nil
+ }
+
}
extension TunnelDetailTableViewController: NSTableViewDataSource {