From 395e6fcddab5089b7c2db954a75df1a0ab1edd70 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sat, 3 Nov 2018 18:45:26 +0530 Subject: [PATCH] Revert "TunnelsManager: initialize observer on correct thread" Rather, we'll make sure we always call startObservingTunnelStatus from the main thread. This reverts commit d16a6a167c8217e81dd9111d1ad9e4ec6429ef3b. --- WireGuard/WireGuard/VPN/TunnelsManager.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index f38ca88..2aa415a 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -399,14 +399,13 @@ class TunnelContainer: NSObject { } private func startObservingTunnelStatus() { - DispatchQueue.main.async { [weak self] in - guard let s = self else { return } - if (s.statusObservationToken != nil) { return } - let connection = s.tunnelProvider.connection - s.statusObservationToken = NotificationCenter.default.addObserver( + if (statusObservationToken != nil) { return } + let connection = tunnelProvider.connection + statusObservationToken = NotificationCenter.default.addObserver( forName: .NEVPNStatusDidChange, object: connection, - queue: nil) { (_) in + queue: nil) { [weak self] (_) in + guard let s = self else { return } if ((s.status == .restarting) && (connection.status == .disconnected || connection.status == .disconnecting)) { // Don't change s.status when disconnecting for a restart if (connection.status == .disconnected) { @@ -422,7 +421,6 @@ class TunnelContainer: NSObject { if (s.status == .inactive) { s.stopObservingTunnelStatus() } - } } }