aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/WireGuard')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift8
1 files changed, 7 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index 29d486a7..3120f7d7 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -340,7 +340,13 @@ class TunnelsManager {
func startObservingTunnelConfigurations() {
configurationsObservationToken = NotificationCenter.default.addObserver(forName: .NEVPNConfigurationChange, object: nil, queue: OperationQueue.main) { [weak self] _ in
- self?.reload()
+ DispatchQueue.main.async { [weak self] in
+ // We schedule reload() in a subsequent runloop to ensure that the completion handler of loadAllFromPreferences
+ // (reload() calls loadAllFromPreferences) is called after the completion handler of the saveToPreferences or
+ // removeFromPreferences call, if any, that caused this notification to fire. This notification can also fire
+ // as a result of a tunnel getting added or removed outside of the app.
+ self?.reload()
+ }
}
}