Skip to content

Commit

Permalink
Simplify how to we handle background task expirations.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Jan 10, 2025
1 parent fc719d9 commit 6d90673
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -965,30 +965,30 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
return
}

backgroundTask = appMediator.beginBackgroundTask { [weak self] in
guard let self else { return }

backgroundTask = appMediator.beginBackgroundTask {
MXLog.info("Background task is about to expire.")
stopSync(isBackgroundTask: true) { [weak self] in
guard let self, let backgroundTask else { return }

MXLog.info("Ending background task.")
appMediator.endBackgroundTask(backgroundTask)
self.backgroundTask = nil

self.stopSync(isBackgroundTask: true) {
self.endActiveBackgroundTask()
}
}
}

@objc
private func applicationDidBecomeActive() {
MXLog.info("Application did become active")

if let backgroundTask {
appMediator.endBackgroundTask(backgroundTask)
self.backgroundTask = nil
endActiveBackgroundTask()
startSync()
}

private func endActiveBackgroundTask() {
guard let backgroundTask else {
return
}

startSync()
MXLog.info("Ending background task.")
appMediator.endBackgroundTask(backgroundTask)
self.backgroundTask = nil
}

// MARK: Background app refresh
Expand Down

0 comments on commit 6d90673

Please sign in to comment.