session-ios/Signal/src/environment/AppEnvironment.swift

88 lines
2.2 KiB
Swift
Raw Normal View History

2018-10-15 20:34:41 +02:00
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
2018-10-15 20:34:41 +02:00
//
import Foundation
2018-10-15 20:58:15 +02:00
import SignalServiceKit
import SignalMessaging
2018-10-15 21:51:43 +02:00
@objc public class AppEnvironment: NSObject {
private static var _shared: AppEnvironment = AppEnvironment()
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public class var shared: AppEnvironment {
2018-10-15 20:58:15 +02:00
get {
return _shared
}
set {
2018-10-15 21:51:43 +02:00
guard CurrentAppContext().isRunningTests else {
owsFailDebug("Can only switch environments in tests.")
return
}
2018-10-15 20:34:41 +02:00
_shared = newValue
}
}
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public var callMessageHandler: WebRTCCallMessageHandler
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public var callService: CallService
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public var outboundCallInitiator: OutboundCallInitiator
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public var messageFetcherJob: MessageFetcherJob
@objc
public var accountManager: AccountManager
2018-10-15 20:58:15 +02:00
@objc
public var notificationsAdapter: NotificationsAdapter
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
@objc
2018-10-15 21:51:43 +02:00
public var pushRegistrationManager: PushRegistrationManager
2018-10-15 20:58:15 +02:00
@objc
2018-10-16 17:47:54 +02:00
public var pushManager: PushManager
2018-10-15 21:51:43 +02:00
@objc
public var sessionResetJobQueue: SessionResetJobQueue
2018-11-19 15:36:18 +01:00
@objc
public var backup: OWSBackup
2018-11-29 18:09:18 +01:00
@objc
public var backupLazyRestore: BackupLazyRestore
2018-10-15 21:11:20 +02:00
private override init() {
2018-10-16 17:47:54 +02:00
self.callMessageHandler = WebRTCCallMessageHandler()
self.callService = CallService()
self.outboundCallInitiator = OutboundCallInitiator()
self.messageFetcherJob = MessageFetcherJob()
self.accountManager = AccountManager()
self.notificationsAdapter = NotificationsAdapter()
2018-10-16 17:47:54 +02:00
self.pushRegistrationManager = PushRegistrationManager()
self.pushManager = PushManager()
self.sessionResetJobQueue = SessionResetJobQueue()
2018-11-21 18:25:24 +01:00
self.backup = OWSBackup()
2018-11-29 18:09:18 +01:00
self.backupLazyRestore = BackupLazyRestore()
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
super.init()
2018-10-15 21:51:43 +02:00
2018-10-15 20:58:15 +02:00
SwiftSingletons.register(self)
2018-10-15 20:34:41 +02:00
}
2018-10-15 21:51:43 +02:00
@objc
public func setup() {
2018-10-15 20:58:15 +02:00
callService.createCallUIAdapter()
2018-10-15 20:34:41 +02:00
// Hang certain singletons on SSKEnvironment too.
SSKEnvironment.shared.notificationsManager = notificationsAdapter
2018-10-15 20:58:15 +02:00
SSKEnvironment.shared.callMessageHandler = callMessageHandler
2018-10-15 20:34:41 +02:00
}
}