session-ios/Signal/src/environment/AppEnvironment.swift
Michael Kirk 1bfe691895 In app notifications for iOS10+
Extract shared notification presention/response

Implement adapters which use that logic for modern UNUserNotification and
legacy UINotifications
2019-02-01 17:44:13 -07:00

84 lines
2.1 KiB
Swift

//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
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 {
guard CurrentAppContext().isRunningTests else {
owsFailDebug("Can only switch environments in tests.")
return
}
_shared = newValue
}
}
@objc
public var callMessageHandler: WebRTCCallMessageHandler
@objc
public var callService: CallService
@objc
public var outboundCallInitiator: OutboundCallInitiator
@objc
public var messageFetcherJob: MessageFetcherJob
@objc
public var accountManager: AccountManager
@objc
public var notificationPresenter: NotificationPresenter
@objc
public var pushRegistrationManager: PushRegistrationManager
@objc
public var sessionResetJobQueue: SessionResetJobQueue
@objc
public var backup: OWSBackup
@objc
public var backupLazyRestore: BackupLazyRestore
private override init() {
self.callMessageHandler = WebRTCCallMessageHandler()
self.callService = CallService()
self.outboundCallInitiator = OutboundCallInitiator()
self.messageFetcherJob = MessageFetcherJob()
self.accountManager = AccountManager()
self.notificationPresenter = NotificationPresenter()
self.pushRegistrationManager = PushRegistrationManager()
self.sessionResetJobQueue = SessionResetJobQueue()
self.backup = OWSBackup()
self.backupLazyRestore = BackupLazyRestore()
super.init()
SwiftSingletons.register(self)
}
@objc
public func setup() {
callService.createCallUIAdapter()
// Hang certain singletons on SSKEnvironment too.
SSKEnvironment.shared.notificationsManager = notificationPresenter
SSKEnvironment.shared.callMessageHandler = callMessageHandler
}
}