From 5a3c4ad2f52ae122d75f0f21bd158f8294729bc9 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 28 Sep 2026 19:01:54 +0300 Subject: [PATCH] Make the background app refresh task live in its own extension as well --- .../Sources/Application/AppCoordinator.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index e553de111..78ef90213 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -34,6 +34,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg /// Common background task to continue long-running tasks in the background. private var backgroundTask: UIBackgroundTaskIdentifier? + private var backgroundRefreshSyncObserver: AnyCancellable? + private var userSessionMigrationsOldVersion: Version? private var userSession: UserSessionProtocol? { didSet { @@ -1239,10 +1241,12 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg appMediator.endBackgroundTask(backgroundTask) self.backgroundTask = nil } - - // MARK: Background app refresh - - private func registerBackgroundAppRefresh() { +} + +// MARK: Background app refresh + +private extension AppCoordinator { + func registerBackgroundAppRefresh() { let result = BGTaskScheduler.shared.register(forTaskWithIdentifier: appSettings.backgroundAppRefreshTaskIdentifier, using: .main) { [weak self] task in guard let task = task as? BGAppRefreshTask else { MXLog.error("Invalid background app refresh configuration") @@ -1257,7 +1261,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg MXLog.info("Register background app refresh with result: \(result)") } - private func scheduleBackgroundAppRefresh() { + func scheduleBackgroundAppRefresh() { let request = BGAppRefreshTaskRequest(identifier: appSettings.backgroundAppRefreshTaskIdentifier) // We have other background tasks that keep the app alive @@ -1271,8 +1275,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg } } - private var backgroundRefreshSyncObserver: AnyCancellable? - private func handleBackgroundAppRefresh(_ task: BGAppRefreshTask) async { + func handleBackgroundAppRefresh(_ task: BGAppRefreshTask) async { MXLog.info("Started background app refresh") // This is important for the app to keep refreshing in the background