Create AppEnvironment.

pull/1/head
Matthew Chen 7 years ago
parent d7e52367ff
commit 0b4ed1175d

@ -623,7 +623,7 @@ static NSTimeInterval launchStartedAt;
// "Background App Refresh" will not be able to obtain an APN token. Enabling those settings does not // "Background App Refresh" will not be able to obtain an APN token. Enabling those settings does not
// restart the app, so we check every activation for users who haven't yet registered. // restart the app, so we check every activation for users who haven't yet registered.
__unused AnyPromise *promise = __unused AnyPromise *promise =
[OWSSyncPushTokensJob runWithAccountManager:SignalApp.sharedApp.accountManager [OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager
preferences:Environment.shared.preferences]; preferences:Environment.shared.preferences];
} }
@ -766,10 +766,10 @@ static NSTimeInterval launchStartedAt;
// * It can be received if the user taps the "video" button for a contact in the // * It can be received if the user taps the "video" button for a contact in the
// contacts app. If so, the correct response is to try to initiate a new call // contacts app. If so, the correct response is to try to initiate a new call
// to that user - unless there already is another call in progress. // to that user - unless there already is another call in progress.
if (SignalApp.sharedApp.callService.call != nil) { if (AppEnvironment.shared.callService.call != nil) {
if ([phoneNumber isEqualToString:SignalApp.sharedApp.callService.call.remotePhoneNumber]) { if ([phoneNumber isEqualToString:AppEnvironment.shared.callService.call.remotePhoneNumber]) {
OWSLogWarn(@"trying to upgrade ongoing call to video."); OWSLogWarn(@"trying to upgrade ongoing call to video.");
[SignalApp.sharedApp.callService handleCallKitStartVideo]; [AppEnvironment.shared.callService handleCallKitStartVideo];
return; return;
} else { } else {
OWSLogWarn(@"ignoring INStartVideoCallIntent due to ongoing WebRTC call with another party."); OWSLogWarn(@"ignoring INStartVideoCallIntent due to ongoing WebRTC call with another party.");
@ -777,7 +777,7 @@ static NSTimeInterval launchStartedAt;
} }
} }
OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; OutboundCallInitiator *outboundCallInitiator = AppEnvironment.shared.outboundCallInitiator;
OWSAssertDebug(outboundCallInitiator); OWSAssertDebug(outboundCallInitiator);
[outboundCallInitiator initiateCallWithHandle:phoneNumber]; [outboundCallInitiator initiateCallWithHandle:phoneNumber];
}]; }];
@ -815,12 +815,12 @@ static NSTimeInterval launchStartedAt;
} }
} }
if (SignalApp.sharedApp.callService.call != nil) { if (AppEnvironment.shared.callService.call != nil) {
OWSLogWarn(@"ignoring INStartAudioCallIntent due to ongoing WebRTC call."); OWSLogWarn(@"ignoring INStartAudioCallIntent due to ongoing WebRTC call.");
return; return;
} }
OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; OutboundCallInitiator *outboundCallInitiator = AppEnvironment.shared.outboundCallInitiator;
OWSAssertDebug(outboundCallInitiator); OWSAssertDebug(outboundCallInitiator);
[outboundCallInitiator initiateCallWithHandle:phoneNumber]; [outboundCallInitiator initiateCallWithHandle:phoneNumber];
}]; }];
@ -959,7 +959,7 @@ static NSTimeInterval launchStartedAt;
{ {
OWSLogInfo(@"performing background fetch"); OWSLogInfo(@"performing background fetch");
[AppReadiness runNowOrWhenAppIsReady:^{ [AppReadiness runNowOrWhenAppIsReady:^{
__block AnyPromise *job = [[SignalApp sharedApp].messageFetcherJob run].then(^{ __block AnyPromise *job = [AppEnvironment.shared.messageFetcherJob run].then(^{
// HACK: Call completion handler after n seconds. // HACK: Call completion handler after n seconds.
// //
// We don't currently have a convenient API to know when message fetching is *done* when // We don't currently have a convenient API to know when message fetching is *done* when
@ -1031,11 +1031,11 @@ static NSTimeInterval launchStartedAt;
// Fetch messages as soon as possible after launching. In particular, when // Fetch messages as soon as possible after launching. In particular, when
// launching from the background, without this, we end up waiting some extra // launching from the background, without this, we end up waiting some extra
// seconds before receiving an actionable push notification. // seconds before receiving an actionable push notification.
__unused AnyPromise *messagePromise = [SignalApp.sharedApp.messageFetcherJob run]; __unused AnyPromise *messagePromise = [AppEnvironment.shared.messageFetcherJob run];
// This should happen at any launch, background or foreground. // This should happen at any launch, background or foreground.
__unused AnyPromise *pushTokenpromise = __unused AnyPromise *pushTokenpromise =
[OWSSyncPushTokensJob runWithAccountManager:SignalApp.sharedApp.accountManager [OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager
preferences:Environment.shared.preferences]; preferences:Environment.shared.preferences];
} }

@ -9,16 +9,14 @@ import SignalServiceKit
@objc(OWSMessageFetcherJob) @objc(OWSMessageFetcherJob)
public class MessageFetcherJob: NSObject { public class MessageFetcherJob: NSObject {
private private var timer : Timer?
var timer : Timer ?
@objc
@objc public override public override init()
init()
{ {
super super.init()
.init()
SwiftSingletons.register(self)
SwiftSingletons.register(self)
} }
// MARK: Singletons // MARK: Singletons

@ -18,7 +18,8 @@ public class AccountManager: NSObject {
return PushManager.shared() return PushManager.shared()
} }
@objc public override init() @objc
public override init()
{ {
super.init() super.init()

@ -18,7 +18,7 @@ public class CallNotificationsAdapter: NSObject {
// We have to first port *all* the existing UINotification categories to UNNotifications // We have to first port *all* the existing UINotification categories to UNNotifications
// which is a good thing to do, but in trying to limit the scope of changes that's been // which is a good thing to do, but in trying to limit the scope of changes that's been
// left out for now. // left out for now.
return SignalApp.shared().notificationsManager return AppEnvironment.shared.notificationsManager
} }
@objc public override init() { @objc public override init() {

@ -239,8 +239,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)syncPushTokens - (void)syncPushTokens
{ {
OWSSyncPushTokensJob *job = [[OWSSyncPushTokensJob alloc] initWithAccountManager:SignalApp.sharedApp.accountManager OWSSyncPushTokensJob *job =
preferences:Environment.shared.preferences]; [[OWSSyncPushTokensJob alloc] initWithAccountManager:AppEnvironment.shared.accountManager
preferences:Environment.shared.preferences];
job.uploadOnlyIfStale = NO; job.uploadOnlyIfStale = NO;
[job run] [job run]
.then(^{ .then(^{

@ -56,7 +56,7 @@
[Environment.shared.preferences setNotificationPreviewType:notificationType]; [Environment.shared.preferences setNotificationPreviewType:notificationType];
// rebuild callUIAdapter since notification configuration changed. // rebuild callUIAdapter since notification configuration changed.
[SignalApp.sharedApp.callService createCallUIAdapter]; [AppEnvironment.shared.callService createCallUIAdapter];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }

@ -298,7 +298,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.preferences setIsSystemCallLogEnabled:sender.isOn]; [self.preferences setIsSystemCallLogEnabled:sender.isOn];
// rebuild callUIAdapter since CallKit configuration changed. // rebuild callUIAdapter since CallKit configuration changed.
[SignalApp.sharedApp.callService createCallUIAdapter]; [AppEnvironment.shared.callService createCallUIAdapter];
} }
- (void)didToggleEnableCallKitSwitch:(UISwitch *)sender - (void)didToggleEnableCallKitSwitch:(UISwitch *)sender
@ -307,7 +307,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.preferences setIsCallKitEnabled:sender.isOn]; [self.preferences setIsCallKitEnabled:sender.isOn];
// rebuild callUIAdapter since CallKit vs not changed. // rebuild callUIAdapter since CallKit vs not changed.
[SignalApp.sharedApp.callService createCallUIAdapter]; [AppEnvironment.shared.callService createCallUIAdapter];
// Show/Hide dependent switch: CallKit privacy // Show/Hide dependent switch: CallKit privacy
[self updateTableContents]; [self updateTableContents];
@ -319,7 +319,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.preferences setIsCallKitPrivacyEnabled:!sender.isOn]; [self.preferences setIsCallKitPrivacyEnabled:!sender.isOn];
// rebuild callUIAdapter since CallKit configuration changed. // rebuild callUIAdapter since CallKit configuration changed.
[SignalApp.sharedApp.callService createCallUIAdapter]; [AppEnvironment.shared.callService createCallUIAdapter];
} }
- (void)didToggleUDUnrestrictedAccessSwitch:(UISwitch *)sender - (void)didToggleUDUnrestrictedAccessSwitch:(UISwitch *)sender

@ -14,7 +14,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// Dependencies // Dependencies
var callUIAdapter: CallUIAdapter { var callUIAdapter: CallUIAdapter {
return SignalApp.shared().callUIAdapter return AppEnvironment.shared.callService.callUIAdapter
} }
// Feature Flag // Feature Flag
@ -208,7 +208,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// Subscribe for future call updates // Subscribe for future call updates
call.addObserverAndSyncState(observer: self) call.addObserverAndSyncState(observer: self)
SignalApp.shared().callService.addObserverAndSyncState(observer: self) AppEnvironment.shared.callService.addObserverAndSyncState(observer: self)
assert(callUIAdapter.audioService.delegate == nil) assert(callUIAdapter.audioService.delegate == nil)
callUIAdapter.audioService.delegate = self callUIAdapter.audioService.delegate = self

@ -277,7 +277,7 @@ typedef enum : NSUInteger {
_contactsManager = Environment.shared.contactsManager; _contactsManager = Environment.shared.contactsManager;
_contactsUpdater = SSKEnvironment.shared.contactsUpdater; _contactsUpdater = SSKEnvironment.shared.contactsUpdater;
_messageSender = SSKEnvironment.shared.messageSender; _messageSender = SSKEnvironment.shared.messageSender;
_outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; _outboundCallInitiator = AppEnvironment.shared.outboundCallInitiator;
_primaryStorage = [OWSPrimaryStorage sharedManager]; _primaryStorage = [OWSPrimaryStorage sharedManager];
_networkManager = [TSNetworkManager sharedManager]; _networkManager = [TSNetworkManager sharedManager];
_blockingManager = [OWSBlockingManager sharedManager]; _blockingManager = [OWSBlockingManager sharedManager];

@ -11,7 +11,7 @@ class DebugUINotifications: DebugUIPage {
// MARK: Dependencies // MARK: Dependencies
var notificationsManager: NotificationsManager { var notificationsManager: NotificationsManager {
return SignalApp.shared().notificationsManager return AppEnvironment.shared.notificationsManager
} }
var notificationsAdapter: CallNotificationsAdapter { var notificationsAdapter: CallNotificationsAdapter {
return AppEnvironment.shared.callNotificationsAdapter return AppEnvironment.shared.callNotificationsAdapter

@ -146,7 +146,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
- (void)commonInit - (void)commonInit
{ {
_accountManager = SignalApp.sharedApp.accountManager; _accountManager = AppEnvironment.shared.accountManager;
_contactsManager = Environment.shared.contactsManager; _contactsManager = Environment.shared.contactsManager;
_messageSender = SSKEnvironment.shared.messageSender; _messageSender = SSKEnvironment.shared.messageSender;
_blocklistCache = [OWSBlockListCache new]; _blocklistCache = [OWSBlockListCache new];
@ -939,7 +939,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSLogInfo(@"beggining refreshing."); OWSLogInfo(@"beggining refreshing.");
[SignalApp.sharedApp.messageFetcherJob run].ensure(^{ [AppEnvironment.shared.messageFetcherJob run].ensure(^{
OWSLogInfo(@"ending refreshing."); OWSLogInfo(@"ending refreshing.");
[refreshControl endRefreshing]; [refreshControl endRefreshing];
}); });

@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
_accountManager = SignalApp.sharedApp.accountManager; _accountManager = AppEnvironment.shared.accountManager;
return self; return self;
} }
@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
_accountManager = SignalApp.sharedApp.accountManager; _accountManager = AppEnvironment.shared.accountManager;
return self; return self;
} }

@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
_accountManager = SignalApp.sharedApp.accountManager; _accountManager = AppEnvironment.shared.accountManager;
return self; return self;
} }
@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
_accountManager = SignalApp.sharedApp.accountManager; _accountManager = AppEnvironment.shared.accountManager;
return self; return self;
} }

@ -147,28 +147,25 @@ private class SignalCallData: NSObject {
} }
} }
required init(call required init(call: SignalCall) {
: SignalCall) { self.call = call self.call = call
let(callConnectedPromise, callConnectedResolver) let (callConnectedPromise, callConnectedResolver) = Promise<Void>.pending()
= Promise<Void>.pending() self.callConnectedPromise = callConnectedPromise self.callConnectedResolver self.callConnectedPromise = callConnectedPromise
= callConnectedResolver self.callConnectedResolver = callConnectedResolver
let(peerConnectionClientPromise, peerConnectionClientResolver) let (peerConnectionClientPromise, peerConnectionClientResolver) = Promise<Void>.pending()
= Promise<Void>.pending() self.peerConnectionClientPromise self.peerConnectionClientPromise = peerConnectionClientPromise
= peerConnectionClientPromise self.peerConnectionClientResolver = peerConnectionClientResolver self.peerConnectionClientResolver = peerConnectionClientResolver
let(readyToSendIceUpdatesPromise, readyToSendIceUpdatesResolver) let (readyToSendIceUpdatesPromise, readyToSendIceUpdatesResolver) = Promise<Void>.pending()
= Promise<Void>.pending() self.readyToSendIceUpdatesPromise self.readyToSendIceUpdatesPromise = readyToSendIceUpdatesPromise
= readyToSendIceUpdatesPromise self.readyToSendIceUpdatesResolver = readyToSendIceUpdatesResolver self.readyToSendIceUpdatesResolver = readyToSendIceUpdatesResolver
super super.init()
.init() }
SwiftSingletons.register(self) }
deinit deinit {
{
Logger.debug("[SignalCallData] deinit") Logger.debug("[SignalCallData] deinit")
} }
@ -205,23 +202,17 @@ private class SignalCallData: NSObject {
var observers = [Weak<CallServiceObserver>]() var observers = [Weak<CallServiceObserver>]()
// MARK: Dependencies // Exposed by environment.m
// Exposed by environment.m
@objc public var callUIAdapter : CallUIAdapter ! @objc public var callUIAdapter: CallUIAdapter!
// MARK: Class // MARK: Class
static let fallbackIceServer static let fallbackIceServer = RTCIceServer(urlStrings: ["stun:stun1.l.google.com:19302"])
= RTCIceServer(urlStrings
: ["stun:stun1.l.google.com:19302"])
// MARK: Ivars // MARK: Ivars
fileprivate var callData : SignalCallData fileprivate var callData: SignalCallData? {
?
{
didSet { didSet {
AssertIsOnMainThread() AssertIsOnMainThread()
@ -293,57 +284,48 @@ private class SignalCallData: NSObject {
} }
} }
@objc public override init() { super @objc public override init() {
.init()
SwiftSingletons super.init()
.register(self)
self SwiftSingletons.register(self)
.createCallUIAdapter()
NotificationCenter.default NotificationCenter.default.addObserver(self,
.addObserver(self, selector selector: #selector(didEnterBackground),
: #selector(didEnterBackground), name name: NSNotification.Name.OWSApplicationDidEnterBackground,
: NSNotification.Name.OWSApplicationDidEnterBackground, object object: nil)
: nil) NotificationCenter.default.addObserver(self,
NotificationCenter.default.addObserver( selector: #selector(didBecomeActive),
self, selector name: NSNotification.Name.OWSApplicationDidBecomeActive,
: #selector(didBecomeActive), name object: nil)
: NSNotification.Name.OWSApplicationDidBecomeActive, object }
: nil) }
deinit deinit {
{
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
// MARK: - Dependencies // MARK: - Dependencies
private private var contactsManager : OWSContactsManager
var contactsManager : OWSContactsManager
{ {
return Environment.shared.contactsManager return Environment.shared.contactsManager
} }
private private var messageSender : MessageSender
var messageSender : MessageSender
{ {
return SSKEnvironment.shared.messageSender return SSKEnvironment.shared.messageSender
} }
private private var accountManager : AccountManager
var accountManager : AccountManager
{ {
return AppEnvironment.shared.accountManager return AppEnvironment.shared.accountManager
} }
private private var notificationsAdapter : CallNotificationsAdapter
var notificationsAdapter : CallNotificationsAdapter
{ {
return AppEnvironment.shared.callNotificationsAdapter return AppEnvironment.shared.callNotificationsAdapter
} }
// MARK: - Notifications // MARK: - Notifications
@objc func didEnterBackground() { @objc func didEnterBackground() {
@ -356,8 +338,6 @@ private
self.updateIsVideoEnabled() self.updateIsVideoEnabled()
} }
// MARK: -
/** /**
* Choose whether to use CallKit or a Notification backed interface for calling. * Choose whether to use CallKit or a Notification backed interface for calling.
*/ */

@ -20,14 +20,12 @@ import SignalMessaging
// MARK: - Dependencies // MARK: - Dependencies
private private var contactsManager : OWSContactsManager
var contactsManager : OWSContactsManager
{ {
return Environment.shared.contactsManager return Environment.shared.contactsManager
} }
private private var contactsUpdater : ContactsUpdater
var contactsUpdater : ContactsUpdater
{ {
return SSKEnvironment.shared.contactsUpdater return SSKEnvironment.shared.contactsUpdater
} }
@ -53,9 +51,10 @@ private
*/ */
@discardableResult @objc public func initiateCall(recipientId: String, @discardableResult @objc public func initiateCall(recipientId: String,
isVideo: Bool) -> Bool { isVideo: Bool) -> Bool {
// Rather than an init-assigned dependency property, we access `callUIAdapter` via Environment guard let callUIAdapter = AppEnvironment.shared.callService.callUIAdapter else {
// because it can change after app launch due to user settings owsFailDebug("missing callUIAdapter")
let callUIAdapter = SignalApp.shared().callUIAdapter return false
}
guard let frontmostViewController = UIApplication.shared.frontmostViewController else { guard let frontmostViewController = UIApplication.shared.frontmostViewController else {
owsFailDebug("could not identify frontmostViewController") owsFailDebug("could not identify frontmostViewController")
return false return false

@ -11,30 +11,27 @@ public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
// MARK: Initializers // MARK: Initializers
@objc public override init() @objc
public override init()
{ {
super super.init()
.init()
SwiftSingletons.register(self) SwiftSingletons.register(self)
} }
// MARK: - Dependencies // MARK: - Dependencies
private private var messageSender : MessageSender
var messageSender : MessageSender
{ {
return SSKEnvironment.shared.messageSender return SSKEnvironment.shared.messageSender
} }
private private var accountManager : AccountManager
var accountManager : AccountManager
{ {
return AppEnvironment.shared.accountManager return AppEnvironment.shared.accountManager
} }
private private var callService : CallService
var callService : CallService
{ {
return AppEnvironment.shared.callService return AppEnvironment.shared.callService
} }

@ -3,87 +3,100 @@
// //
import Foundation import Foundation
//import PromiseKit import SignalServiceKit
//import PushKit import SignalMessaging
import SignalServiceKit import SignalMessaging
@objc public class AppEnvironment : NSObject {
@objc public class AppEnvironment : NSObject {
private static var _shared : AppEnvironment = AppEnvironment()
private
static var _shared : AppEnvironment = AppEnvironment() @objc
public class var shared : AppEnvironment {
@objc public class var shared : AppEnvironment { get {
get { return _shared } set return _shared
{ }
set {
_shared = newValue _shared = newValue
} }
} }
@objc public var callMessageHandler : WebRTCCallMessageHandler @objc
public var callMessageHandler : WebRTCCallMessageHandler
@objc public var callService : CallService
@objc
@objc public var outboundCallInitiator public var callService : CallService
: OutboundCallInitiator
@objc
@objc public var messageFetcherJob : MessageFetcherJob public var outboundCallInitiator : OutboundCallInitiator
@objc public var notificationsManager : NotificationsManager @objc
public var messageFetcherJob : MessageFetcherJob
@objc public var accountManager
: AccountManager @objc
public var notificationsManager : NotificationsManager
@objc public var callNotificationsAdapter : CallNotificationsAdapter
@objc
@objc public init(callMessageHandler public var accountManager : AccountManager
: WebRTCCallMessageHandler, callService
: CallService, outboundCallInitiator @objc
: OutboundCallInitiator, messageFetcherJob public var callNotificationsAdapter : CallNotificationsAdapter
: MessageFetcherJob, notificationsManager
: NotificationsManager, accountManager @objc
: AccountManager, callNotificationsAdapter public init(callMessageHandler : WebRTCCallMessageHandler,
: CallNotificationsAdapter) callService : CallService,
outboundCallInitiator : OutboundCallInitiator,
messageFetcherJob : MessageFetcherJob,
notificationsManager : NotificationsManager,
accountManager : AccountManager,
callNotificationsAdapter : CallNotificationsAdapter)
{ {
self.callMessageHandler = callMessageHandler self.callService = callService self.outboundCallInitiator self.callMessageHandler = callMessageHandler
= outboundCallInitiator self.messageFetcherJob = messageFetcherJob self.notificationsManager self.callService = callService
= notificationsManager self.accountManager = accountManager self.callNotificationsAdapter self.outboundCallInitiator = outboundCallInitiator
= callNotificationsAdapter self.messageFetcherJob = messageFetcherJob
self.notificationsManager = notificationsManager
super self.accountManager = accountManager
.init() self.callNotificationsAdapter = callNotificationsAdapter
SwiftSingletons.register(self) super
.init()
setup()
SwiftSingletons.register(self)
setup()
} }
private private override init()
override init()
{ {
let accountManager = AccountManager() let notificationsManager let accountManager = AccountManager()
= NotificationsManager() let callNotificationsAdapter = CallNotificationsAdapter() let callService let notificationsManager = NotificationsManager()
= CallService() let callMessageHandler = WebRTCCallMessageHandler() let outboundCallInitiator let callNotificationsAdapter = CallNotificationsAdapter()
= OutboundCallInitiator() let messageFetcherJob = MessageFetcherJob() let callService = CallService()
let callMessageHandler = WebRTCCallMessageHandler()
self.callMessageHandler let outboundCallInitiator = OutboundCallInitiator()
= callMessageHandler self.callService = callService self.outboundCallInitiator let messageFetcherJob = MessageFetcherJob()
= outboundCallInitiator self.messageFetcherJob = messageFetcherJob self.notificationsManager
= notificationsManager self.accountManager = accountManager self.callNotificationsAdapter self.callMessageHandler = callMessageHandler
= callNotificationsAdapter self.callService = callService
self.outboundCallInitiator = outboundCallInitiator
super self.messageFetcherJob = messageFetcherJob
.init() self.notificationsManager = notificationsManager
self.accountManager = accountManager
SwiftSingletons.register(self) self.callNotificationsAdapter = callNotificationsAdapter
setup() super.init()
SwiftSingletons.register(self)
setup()
} }
private private func setup()
func setup()
{ {
callService.createCallUIAdapter()
// Hang certain singletons on SSKEnvironment too. // Hang certain singletons on SSKEnvironment too.
SSKEnvironment.shared.notificationsManager = notificationsManager SSKEnvironment.shared.callMessageHandler SSKEnvironment.shared.notificationsManager = notificationsManager
= callMessageHandler SSKEnvironment.shared.callMessageHandler = callMessageHandler
} }
} }

@ -17,20 +17,18 @@ NS_ASSUME_NONNULL_BEGIN
@class OutboundCallInitiator; @class OutboundCallInitiator;
@class TSThread; @class TSThread;
// TODO: Pull out singletons to MainAppEnvironment?
@interface SignalApp : NSObject @interface SignalApp : NSObject
@property (nonatomic, nullable, weak) HomeViewController *homeViewController; @property (nonatomic, nullable, weak) HomeViewController *homeViewController;
@property (nonatomic, nullable, weak) OWSNavigationController *signUpFlowNavigationController; @property (nonatomic, nullable, weak) OWSNavigationController *signUpFlowNavigationController;
// TODO: Convert to singletons? //@property (nonatomic, readonly) OWSWebRTCCallMessageHandler *callMessageHandler;
@property (nonatomic, readonly) OWSWebRTCCallMessageHandler *callMessageHandler; //@property (nonatomic, readonly) CallService *callService;
@property (nonatomic, readonly) CallService *callService; //@property (nonatomic, readonly) CallUIAdapter *callUIAdapter;
@property (nonatomic, readonly) CallUIAdapter *callUIAdapter; //@property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator;
@property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator; //@property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob;
@property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob; //@property (nonatomic, readonly) NotificationsManager *notificationsManager;
@property (nonatomic, readonly) NotificationsManager *notificationsManager; //@property (nonatomic, readonly) AccountManager *accountManager;
@property (nonatomic, readonly) AccountManager *accountManager;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;

@ -49,41 +49,6 @@ NS_ASSUME_NONNULL_BEGIN
object:nil]; object:nil];
} }
- (OWSWebRTCCallMessageHandler *)callMessageHandler
{
return AppEnvironment.shared.callMessageHandler;
}
- (CallService *)callService
{
return AppEnvironment.shared.callService;
}
- (CallUIAdapter *)callUIAdapter
{
return AppEnvironment.shared.callService.callUIAdapter;
}
- (OutboundCallInitiator *)outboundCallInitiator
{
return AppEnvironment.shared.outboundCallInitiator;
}
- (OWSMessageFetcherJob *)messageFetcherJob
{
return AppEnvironment.shared.messageFetcherJob;
}
- (NotificationsManager *)notificationsManager
{
return AppEnvironment.shared.notificationsManager;
}
- (AccountManager *)accountManager
{
return AppEnvironment.shared.accountManager;
}
#pragma mark - View Convenience Methods #pragma mark - View Convenience Methods
- (void)presentConversationForRecipientId:(NSString *)recipientId animated:(BOOL)isAnimated - (void)presentConversationForRecipientId:(NSString *)recipientId animated:(BOOL)isAnimated
@ -157,7 +122,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)didChangeCallLoggingPreference:(NSNotification *)notitication - (void)didChangeCallLoggingPreference:(NSNotification *)notitication
{ {
[self.callService createCallUIAdapter]; [AppEnvironment.shared.callService createCallUIAdapter];
} }
#pragma mark - Methods #pragma mark - Methods

@ -54,10 +54,10 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
- (instancetype)initDefault - (instancetype)initDefault
{ {
return [self initWithMessageFetcherJob:SignalApp.sharedApp.messageFetcherJob return [self initWithMessageFetcherJob:AppEnvironment.shared.messageFetcherJob
primaryStorage:[OWSPrimaryStorage sharedManager] primaryStorage:[OWSPrimaryStorage sharedManager]
messageSender:SSKEnvironment.shared.messageSender messageSender:SSKEnvironment.shared.messageSender
notificationsManager:SignalApp.sharedApp.notificationsManager]; notificationsManager:AppEnvironment.shared.notificationsManager];
} }
- (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob - (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob
@ -89,7 +89,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
- (CallUIAdapter *)callUIAdapter - (CallUIAdapter *)callUIAdapter
{ {
return SignalApp.sharedApp.callService.callUIAdapter; return AppEnvironment.shared.callService.callUIAdapter;
} }
- (void)handleMessageRead:(NSNotification *)notification - (void)handleMessageRead:(NSNotification *)notification

@ -42,10 +42,11 @@ class FailingTSAccountManager: TSAccountManager {
} }
class VerifyingTSAccountManager: FailingTSAccountManager { class VerifyingTSAccountManager: FailingTSAccountManager {
override func verifyAccount(withCode override func verifyAccount(withCode: String,
: String, pin pin: String?,
: String ?, success : @escaping()->Void, failure success: @escaping () -> Void, failure: @escaping (Error) -> Void) {
: @escaping(Error)->Void) { success() } s success()
}
} }
class TokenObtainingTSAccountManager: VerifyingTSAccountManager { class TokenObtainingTSAccountManager: VerifyingTSAccountManager {

Loading…
Cancel
Save