mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 15:45:11 +00:00
Cleanup following the AppMediator introduction (#2723)
- stop using multiple background task, the appCoordinator sync one is enough for the whole app - move the AppMeditor to the MainActor - expose the WindowManager through the AppMediator - hide sensitive WindowManager API behind a different protocol - remove the now unnecessary `BackgroundTaskService`
This commit is contained in:
@@ -18,44 +18,11 @@ import UIKit
|
||||
|
||||
extension AppMediatorMock {
|
||||
static var `default`: AppMediatorProtocol {
|
||||
AppMediatorMock(withState: .active,
|
||||
backgroundTimeRemaining: 10,
|
||||
allowTasks: true)
|
||||
}
|
||||
|
||||
static var mockBroken: AppMediatorProtocol {
|
||||
AppMediatorMock(withState: .inactive,
|
||||
backgroundTimeRemaining: 0,
|
||||
allowTasks: false)
|
||||
}
|
||||
|
||||
static var mockAboutToSuspend: AppMediatorProtocol {
|
||||
AppMediatorMock(withState: .background,
|
||||
backgroundTimeRemaining: 2,
|
||||
allowTasks: false)
|
||||
}
|
||||
|
||||
private static var bgTaskIdentifier = 0
|
||||
|
||||
convenience init(withState applicationState: UIApplication.State,
|
||||
backgroundTimeRemaining: TimeInterval,
|
||||
allowTasks: Bool) {
|
||||
self.init()
|
||||
let mock = AppMediatorMock()
|
||||
|
||||
underlyingAppState = applicationState
|
||||
underlyingBackgroundTimeRemaining = backgroundTimeRemaining
|
||||
mock.underlyingAppState = .active
|
||||
mock.underlyingWindowManager = WindowManagerMock()
|
||||
|
||||
beginBackgroundTaskWithNameExpirationHandlerClosure = { _, handler in
|
||||
guard allowTasks else {
|
||||
return .invalid
|
||||
}
|
||||
Self.bgTaskIdentifier += 1
|
||||
|
||||
let identifier = UIBackgroundTaskIdentifier(rawValue: Self.bgTaskIdentifier)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||
handler?()
|
||||
}
|
||||
return identifier
|
||||
}
|
||||
return mock
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user