Make the background app refresh task live in its own extension as well

This commit is contained in:
Stefan Ceriu
2026-09-28 19:01:54 +03:00
parent 49481f9af7
commit 5a3c4ad2f5
@@ -34,6 +34,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
/// Common background task to continue long-running tasks in the background. /// Common background task to continue long-running tasks in the background.
private var backgroundTask: UIBackgroundTaskIdentifier? private var backgroundTask: UIBackgroundTaskIdentifier?
private var backgroundRefreshSyncObserver: AnyCancellable?
private var userSessionMigrationsOldVersion: Version? private var userSessionMigrationsOldVersion: Version?
private var userSession: UserSessionProtocol? { private var userSession: UserSessionProtocol? {
didSet { didSet {
@@ -1239,10 +1241,12 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appMediator.endBackgroundTask(backgroundTask) appMediator.endBackgroundTask(backgroundTask)
self.backgroundTask = nil self.backgroundTask = nil
} }
}
// MARK: Background app refresh
// MARK: Background app refresh
private func registerBackgroundAppRefresh() {
private extension AppCoordinator {
func registerBackgroundAppRefresh() {
let result = BGTaskScheduler.shared.register(forTaskWithIdentifier: appSettings.backgroundAppRefreshTaskIdentifier, using: .main) { [weak self] task in let result = BGTaskScheduler.shared.register(forTaskWithIdentifier: appSettings.backgroundAppRefreshTaskIdentifier, using: .main) { [weak self] task in
guard let task = task as? BGAppRefreshTask else { guard let task = task as? BGAppRefreshTask else {
MXLog.error("Invalid background app refresh configuration") MXLog.error("Invalid background app refresh configuration")
@@ -1257,7 +1261,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
MXLog.info("Register background app refresh with result: \(result)") MXLog.info("Register background app refresh with result: \(result)")
} }
private func scheduleBackgroundAppRefresh() { func scheduleBackgroundAppRefresh() {
let request = BGAppRefreshTaskRequest(identifier: appSettings.backgroundAppRefreshTaskIdentifier) let request = BGAppRefreshTaskRequest(identifier: appSettings.backgroundAppRefreshTaskIdentifier)
// We have other background tasks that keep the app alive // We have other background tasks that keep the app alive
@@ -1271,8 +1275,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
} }
} }
private var backgroundRefreshSyncObserver: AnyCancellable? func handleBackgroundAppRefresh(_ task: BGAppRefreshTask) async {
private func handleBackgroundAppRefresh(_ task: BGAppRefreshTask) async {
MXLog.info("Started background app refresh") MXLog.info("Started background app refresh")
// This is important for the app to keep refreshing in the background // This is important for the app to keep refreshing in the background