From 4df2b7e6428d701df5db021b59e7758314ee18c0 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 24 Jan 2019 18:11:55 +0530 Subject: [PATCH] TunnelsTracker: Simplify using TunnelsManager.tunnelInOperation() --- .../WireGuard/UI/macOS/TunnelsTracker.swift | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift b/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift index 8df7789..69cc533 100644 --- a/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift +++ b/WireGuard/WireGuard/UI/macOS/TunnelsTracker.swift @@ -33,18 +33,7 @@ class TunnelsTracker { init(tunnelsManager: TunnelsManager) { self.tunnelsManager = tunnelsManager - - if let waitingTunnel = tunnelsManager.waitingTunnel() { - currentTunnel = waitingTunnel - } else { - for index in 0 ..< tunnelsManager.numberOfTunnels() { - let tunnel = tunnelsManager.tunnel(at: index) - if tunnel.status != .inactive { - currentTunnel = tunnel - break - } - } - } + currentTunnel = tunnelsManager.tunnelInOperation() for index in 0 ..< tunnelsManager.numberOfTunnels() { let tunnel = tunnelsManager.tunnel(at: index) @@ -61,11 +50,7 @@ class TunnelsTracker { guard let self = self else { return } if tunnel.status == .deactivating || tunnel.status == .inactive { if self.currentTunnel == tunnel { - if let waitingTunnel = self.tunnelsManager.waitingTunnel() { - self.currentTunnel = waitingTunnel - } else if tunnel.status == .inactive { - self.currentTunnel = nil - } + self.currentTunnel = self.tunnelsManager.tunnelInOperation() } } else { self.currentTunnel = tunnel