From 450e7c714cd9754f26cfd5778e3013ecc848ed00 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Mon, 15 May 2023 16:10:50 -0500 Subject: [PATCH] Unblock the UI when trying to update dn managed sites (#125) --- ios/Runner/DNUpdate.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ios/Runner/DNUpdate.swift b/ios/Runner/DNUpdate.swift index ebbfbbe..a6d1190 100644 --- a/ios/Runner/DNUpdate.swift +++ b/ios/Runner/DNUpdate.swift @@ -6,13 +6,17 @@ class DNUpdater { func updateAll(onUpdate: @escaping (Site) -> ()) { _ = SiteList{ (sites, _) -> () in - sites?.values.forEach { site in - if (site.connected == true) { - // The vpn service is in charge of updating the currently connected site - return + // NEVPN seems to force us onto the main thread and we are about to make network calls that + // could block for a while. Push ourselves onto another thread to avoid blocking the UI. + Task.detached(priority: .userInitiated) { + sites?.values.forEach { site in + if (site.connected == true) { + // The vpn service is in charge of updating the currently connected site + return + } + + self.updateSite(site: site, onUpdate: onUpdate) } - - self.updateSite(site: site, onUpdate: onUpdate) } } }