Improve Application lifetime scheduling

We have noticed race conditions between deep link handling and client
resuming/sync starting which lead to timelines being created without being able
to access the underlying stores.

This patch switches to foreground/background app tracking in an attempt at a cheap
way to fix the underlying issue. Arguably this was the correct way to do it to
being with.
This commit is contained in:
Stefan Ceriu
2026-05-22 15:26:31 +03:00
parent 5c4d0666a9
commit 97d4a35af7
@@ -1106,6 +1106,16 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
selector: #selector(applicationWillResignActive),
name: UIApplication.willResignActiveNotification,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidEnterBackground),
name: UIApplication.didEnterBackgroundNotification,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(applicationWillEnterForeground),
name: UIApplication.willEnterForegroundNotification,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidBecomeActive),
name: UIApplication.didBecomeActiveNotification,
@@ -1128,17 +1138,23 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
@objc
private func applicationWillTerminate() {
MXLog.info("Application will terminate")
stopSync(isBackgroundTask: false)
}
@objc
private func applicationWillResignActive() {
MXLog.info("Application will resign active")
private func applicationDidEnterBackground() {
MXLog.info("Application did enter background")
scheduleDelayedSyncStop()
scheduleBackgroundAppRefresh()
}
@objc
private func applicationWillResignActive() {
MXLog.info("Application will resign active")
}
private func scheduleDelayedSyncStop() {
guard backgroundTask == nil else {
return
@@ -1157,12 +1173,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
}
@objc
private func applicationDidBecomeActive() {
MXLog.info("Application did become active")
private func applicationWillEnterForeground() {
MXLog.info("Application will enter foreground")
endActiveBackgroundTask()
startSync()
}
@objc
private func applicationDidBecomeActive() {
MXLog.info("Application did become active")
}
private func endActiveBackgroundTask() {
guard let backgroundTask else {
return