mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Application: pass AppDelegate in initializer, instead of using singleton
This commit is contained in:
committed by
Stefan Ceriu
parent
ee0539f260
commit
718e01f3bc
@@ -25,7 +25,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
|||||||
private let navigationRootCoordinator: NavigationRootCoordinator
|
private let navigationRootCoordinator: NavigationRootCoordinator
|
||||||
private let userSessionStore: UserSessionStoreProtocol
|
private let userSessionStore: UserSessionStoreProtocol
|
||||||
private let appSettings: AppSettings
|
private let appSettings: AppSettings
|
||||||
|
private let appDelegate: AppDelegate
|
||||||
|
|
||||||
/// 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: BackgroundTaskProtocol?
|
private var backgroundTask: BackgroundTaskProtocol?
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
|||||||
private let appRouteURLParser: AppRouteURLParser
|
private let appRouteURLParser: AppRouteURLParser
|
||||||
@Consumable private var storedAppRoute: AppRoute?
|
@Consumable private var storedAppRoute: AppRoute?
|
||||||
|
|
||||||
init() {
|
init(appDelegate: AppDelegate) {
|
||||||
Self.setupEnvironmentVariables()
|
Self.setupEnvironmentVariables()
|
||||||
|
|
||||||
let appSettings = AppSettings()
|
let appSettings = AppSettings()
|
||||||
@@ -74,6 +75,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
|||||||
AppSettings.reset()
|
AppSettings.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.appDelegate = appDelegate
|
||||||
self.appSettings = appSettings
|
self.appSettings = appSettings
|
||||||
appRouteURLParser = AppRouteURLParser(appSettings: appSettings)
|
appRouteURLParser = AppRouteURLParser(appSettings: appSettings)
|
||||||
|
|
||||||
@@ -493,20 +495,16 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
|||||||
notificationManager.setUserSession(userSession)
|
notificationManager.setUserSession(userSession)
|
||||||
notificationManager.requestAuthorization()
|
notificationManager.requestAuthorization()
|
||||||
|
|
||||||
if let appDelegate = AppDelegate.shared {
|
appDelegateObserver = appDelegate.callbacks
|
||||||
appDelegateObserver = appDelegate.callbacks
|
.receive(on: DispatchQueue.main)
|
||||||
.receive(on: DispatchQueue.main)
|
.sink { [weak self] callback in
|
||||||
.sink { [weak self] callback in
|
switch callback {
|
||||||
switch callback {
|
case .registeredNotifications(let deviceToken):
|
||||||
case .registeredNotifications(let deviceToken):
|
Task { await self?.notificationManager.register(with: deviceToken) }
|
||||||
Task { await self?.notificationManager.register(with: deviceToken) }
|
case .failedToRegisteredNotifications(let error):
|
||||||
case .failedToRegisteredNotifications(let error):
|
self?.notificationManager.registrationFailed(with: error)
|
||||||
self?.notificationManager.registrationFailed(with: error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
MXLog.error("Couldn't register to AppDelegate callbacks")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func observeUserSessionChanges() {
|
private func observeUserSessionChanges() {
|
||||||
|
|||||||
@@ -24,12 +24,9 @@ enum AppDelegateCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||||
private(set) static var shared: AppDelegate!
|
|
||||||
let callbacks = PassthroughSubject<AppDelegateCallback, Never>()
|
let callbacks = PassthroughSubject<AppDelegateCallback, Never>()
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||||
// worst singleton ever
|
|
||||||
Self.shared = self
|
|
||||||
NSTextAttachment.registerViewProviderClass(PillAttachmentViewProvider.self, forFileType: InfoPlistReader.main.pillsUTType)
|
NSTextAttachment.registerViewProviderClass(PillAttachmentViewProvider.self, forFileType: InfoPlistReader.main.pillsUTType)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import SwiftUI
|
|||||||
struct Application: App {
|
struct Application: App {
|
||||||
@UIApplicationDelegateAdaptor(AppDelegate.self) private var applicationDelegate
|
@UIApplicationDelegateAdaptor(AppDelegate.self) private var applicationDelegate
|
||||||
@Environment(\.openURL) private var openURL
|
@Environment(\.openURL) private var openURL
|
||||||
private let appCoordinator: AppCoordinatorProtocol
|
private var appCoordinator: AppCoordinatorProtocol!
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if ProcessInfo.isRunningUITests {
|
if ProcessInfo.isRunningUITests {
|
||||||
@@ -28,7 +28,7 @@ struct Application: App {
|
|||||||
} else if ProcessInfo.isRunningUnitTests {
|
} else if ProcessInfo.isRunningUnitTests {
|
||||||
appCoordinator = UnitTestsAppCoordinator()
|
appCoordinator = UnitTestsAppCoordinator()
|
||||||
} else {
|
} else {
|
||||||
appCoordinator = AppCoordinator()
|
appCoordinator = AppCoordinator(appDelegate: applicationDelegate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ struct Application: App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var shouldHideStatusBar: Bool {
|
private var shouldHideStatusBar: Bool {
|
||||||
ProcessInfo.isRunningUITests
|
ProcessInfo.isRunningUITests
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user