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

100 lines
3.0 KiB
Swift
Raw Normal View History

2018-10-15 20:34:41 +02:00
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
2018-10-15 20:58:15 +02:00
import SignalServiceKit
import SignalMessaging
@objc public class AppEnvironment : NSObject {
private static var _shared : AppEnvironment = AppEnvironment()
@objc
public class var shared : AppEnvironment {
get {
return _shared
}
set {
2018-10-15 20:34:41 +02:00
_shared = newValue
}
}
2018-10-15 20:58:15 +02:00
@objc
public var callMessageHandler : WebRTCCallMessageHandler
@objc
public var callService : CallService
@objc
public var outboundCallInitiator : OutboundCallInitiator
@objc
public var messageFetcherJob : MessageFetcherJob
@objc
public var notificationsManager : NotificationsManager
@objc
public var accountManager : AccountManager
@objc
public var callNotificationsAdapter : CallNotificationsAdapter
@objc
public init(callMessageHandler : WebRTCCallMessageHandler,
callService : CallService,
outboundCallInitiator : OutboundCallInitiator,
messageFetcherJob : MessageFetcherJob,
notificationsManager : NotificationsManager,
accountManager : AccountManager,
2018-10-15 21:11:20 +02:00
callNotificationsAdapter : CallNotificationsAdapter) {
2018-10-15 20:58:15 +02:00
self.callMessageHandler = callMessageHandler
self.callService = callService
self.outboundCallInitiator = outboundCallInitiator
self.messageFetcherJob = messageFetcherJob
self.notificationsManager = notificationsManager
self.accountManager = accountManager
self.callNotificationsAdapter = callNotificationsAdapter
super
.init()
SwiftSingletons.register(self)
setup()
2018-10-15 20:34:41 +02:00
}
2018-10-15 20:58:15 +02:00
2018-10-15 21:11:20 +02:00
private override init() {
2018-10-15 20:58:15 +02:00
let accountManager = AccountManager()
let notificationsManager = NotificationsManager()
let callNotificationsAdapter = CallNotificationsAdapter()
let callService = CallService()
let callMessageHandler = WebRTCCallMessageHandler()
let outboundCallInitiator = OutboundCallInitiator()
let messageFetcherJob = MessageFetcherJob()
self.callMessageHandler = callMessageHandler
self.callService = callService
self.outboundCallInitiator = outboundCallInitiator
self.messageFetcherJob = messageFetcherJob
self.notificationsManager = notificationsManager
self.accountManager = accountManager
self.callNotificationsAdapter = callNotificationsAdapter
super.init()
SwiftSingletons.register(self)
setup()
2018-10-15 20:34:41 +02:00
}
2018-10-15 20:58:15 +02:00
2018-10-15 21:11:20 +02:00
private 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.
2018-10-15 20:58:15 +02:00
SSKEnvironment.shared.notificationsManager = notificationsManager
SSKEnvironment.shared.callMessageHandler = callMessageHandler
2018-10-15 20:34:41 +02:00
}
}