mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Make stopSync more aware of background usage. (#3501)
This commit is contained in:
parent
b9409e5310
commit
468afd8e87
@ -561,7 +561,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
|
|
||||||
showLoadingIndicator()
|
showLoadingIndicator()
|
||||||
|
|
||||||
stopSync()
|
stopSync(isBackgroundTask: false)
|
||||||
userSessionFlowCoordinator?.stop()
|
userSessionFlowCoordinator?.stop()
|
||||||
|
|
||||||
guard !isSoft else {
|
guard !isSoft else {
|
||||||
@ -748,7 +748,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
|
|
||||||
navigationRootCoordinator.setRootCoordinator(PlaceholderScreenCoordinator())
|
navigationRootCoordinator.setRootCoordinator(PlaceholderScreenCoordinator())
|
||||||
|
|
||||||
stopSync()
|
stopSync(isBackgroundTask: false)
|
||||||
userSessionFlowCoordinator?.stop()
|
userSessionFlowCoordinator?.stop()
|
||||||
|
|
||||||
let userID = userSession.clientProxy.userID
|
let userID = userSession.clientProxy.userID
|
||||||
@ -848,7 +848,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
|
|
||||||
// MARK: - Application State
|
// MARK: - Application State
|
||||||
|
|
||||||
private func stopSync() {
|
private func stopSync(isBackgroundTask: Bool) {
|
||||||
|
if isBackgroundTask, UIApplication.shared.applicationState == .active {
|
||||||
|
// Attempt to stop the background task sync loop cleanly, only if the app not already running
|
||||||
|
return
|
||||||
|
}
|
||||||
userSession?.clientProxy.stopSync()
|
userSession?.clientProxy.stopSync()
|
||||||
clientProxyObserver = nil
|
clientProxyObserver = nil
|
||||||
}
|
}
|
||||||
@ -911,7 +915,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func applicationWillTerminate() {
|
private func applicationWillTerminate() {
|
||||||
stopSync()
|
stopSync(isBackgroundTask: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
@ -930,7 +934,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
backgroundTask = appMediator.beginBackgroundTask { [weak self] in
|
backgroundTask = appMediator.beginBackgroundTask { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
stopSync()
|
stopSync(isBackgroundTask: true)
|
||||||
|
|
||||||
if let backgroundTask {
|
if let backgroundTask {
|
||||||
appMediator.endBackgroundTask(backgroundTask)
|
appMediator.endBackgroundTask(backgroundTask)
|
||||||
@ -988,10 +992,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
scheduleBackgroundAppRefresh()
|
scheduleBackgroundAppRefresh()
|
||||||
|
|
||||||
task.expirationHandler = { [weak self] in
|
task.expirationHandler = { [weak self] in
|
||||||
if UIApplication.shared.applicationState != .active {
|
self?.stopSync(isBackgroundTask: true)
|
||||||
// Attempt to stop the sync loop cleanly, only if the app not already running
|
|
||||||
self?.stopSync()
|
|
||||||
}
|
|
||||||
|
|
||||||
MXLog.info("Background app refresh task expired")
|
MXLog.info("Background app refresh task expired")
|
||||||
task.setTaskCompleted(success: true)
|
task.setTaskCompleted(success: true)
|
||||||
@ -1015,7 +1016,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
|
|
||||||
// Make sure we stop the sync loop, otherwise the ongoing request is immediately
|
// Make sure we stop the sync loop, otherwise the ongoing request is immediately
|
||||||
// handled the next time the app refreshes, which can trigger timeout failures.
|
// handled the next time the app refreshes, which can trigger timeout failures.
|
||||||
stopSync()
|
stopSync(isBackgroundTask: true)
|
||||||
backgroundRefreshSyncObserver?.cancel()
|
backgroundRefreshSyncObserver?.cancel()
|
||||||
|
|
||||||
task.setTaskCompleted(success: true)
|
task.setTaskCompleted(success: true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user