From c44b04cf4a50c315a3c8c8a171c26587d147cb3b Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Tue, 13 Oct 2026 20:45:14 +0200 Subject: [PATCH] fix(ios): keep a crawl running when the app leaves the screen Without a background task iOS suspends the app at once and drops its connections, so a glance at another app failed a minutes-long crawl. --- ios/ProtonStream/App/AppModel.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/ProtonStream/App/AppModel.swift b/ios/ProtonStream/App/AppModel.swift index f31e5de..559670c 100644 --- a/ios/ProtonStream/App/AppModel.swift +++ b/ios/ProtonStream/App/AppModel.swift @@ -152,10 +152,16 @@ final class AppModel { } /// Crawl one share, or all with nil, with the banner offering Stop meanwhile. + /// + /// Held under a background task: a crawl takes minutes, and without one + /// iOS suspends the app the moment it leaves the screen and tears down its + /// connections, so a glance at another app failed the crawl. private func crawlShares(_ id: String?) async throws { crawlsRunning += 1 crawling = true + let task = BackgroundTask(name: "crawl") defer { + task.end() crawlsRunning -= 1 crawling = crawlsRunning > 0 }