Move SM singletons to Environment.

pull/1/head
Matthew Chen 7 years ago
parent b9d592ed15
commit 603e3bf0b6

@ -6,7 +6,9 @@
#import "OWSBackup.h"
#import "OWSContactsSyncing.h"
#import "OWSWindowManager.h"
#import <SignalMessaging/LockInteractionController.h>
#import <SignalMessaging/OWSPreferences.h>
#import <SignalMessaging/OWSSounds.h>
NS_ASSUME_NONNULL_BEGIN
@ -21,9 +23,21 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init
{
OWSPrimaryStorage *primaryStorage = SSKEnvironment.shared.primaryStorage;
OWSAssertDebug(primaryStorage);
// TODO: We should probably mock this out.
OWSPreferences *preferences = [OWSPreferences new];
self = [super initWithPreferences:preferences];
OWSContactsSyncing *contactsSyncing = [[OWSContactsSyncing alloc] initDefault];
OWSSounds *sounds = [[OWSSounds alloc] initWithPrimaryStorage:primaryStorage];
LockInteractionController *lockInteractionController = [[LockInteractionController alloc] initDefault];
OWSWindowManager *windowManager = [[OWSWindowManager alloc] initDefault];
self = [super initWithPreferences:preferences
contactsSyncing:contactsSyncing
sounds:sounds
lockInteractionController:lockInteractionController
windowManager:windowManager];
OWSAssertDebug(self);
return self;
}

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initDefault NS_DESIGNATED_INITIALIZER;
+ (instancetype)sharedManager;
@end

@ -24,11 +24,6 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
@property (nonatomic, readonly) dispatch_queue_t serialQueue;
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) OWSProfileManager *profileManager;
@property (nonatomic) BOOL isRequestInFlight;
@end
@ -37,26 +32,12 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
+ (instancetype)sharedManager
{
static OWSContactsSyncing *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] initDefault];
});
return instance;
}
OWSAssertDebug(Environment.shared.contactsSyncing);
- (instancetype)initDefault
{
return [self initWithContactsManager:Environment.shared.contactsManager
identityManager:OWSIdentityManager.sharedManager
messageSender:SSKEnvironment.shared.messageSender
profileManager:OWSProfileManager.sharedManager];
return Environment.shared.contactsSyncing;
}
- (instancetype)initWithContactsManager:(OWSContactsManager *)contactsManager
identityManager:(OWSIdentityManager *)identityManager
messageSender:(OWSMessageSender *)messageSender
profileManager:(OWSProfileManager *)profileManager
- (instancetype)initDefault
{
self = [super init];
@ -64,15 +45,6 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
return self;
}
OWSAssertDebug(contactsManager);
OWSAssertDebug(messageSender);
OWSAssertDebug(identityManager);
_contactsManager = contactsManager;
_identityManager = identityManager;
_messageSender = messageSender;
_profileManager = profileManager;
OWSSingletonAssert();
[[NSNotificationCenter defaultCenter] addObserver:self
@ -92,6 +64,34 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Dependencies
- (OWSContactsManager *)contactsManager {
OWSAssertDebug(Environment.shared.contactsManager);
return Environment.shared.contactsManager;
}
- (OWSIdentityManager *)identityManager {
OWSAssertDebug(SSKEnvironment.shared.identityManager);
return SSKEnvironment.shared.identityManager;
}
- (OWSMessageSender *)messageSender {
OWSAssertDebug(SSKEnvironment.shared.messageSender);
return SSKEnvironment.shared.messageSender;
}
- (OWSProfileManager *)profileManager {
OWSAssertDebug(SSKEnvironment.shared.profileManager);
return SSKEnvironment.shared.profileManager;
}
#pragma mark -
- (void)signalAccountsDidChange:(id)notification
{
OWSAssertIsOnMainThread();

@ -82,7 +82,16 @@ NS_ASSUME_NONNULL_BEGIN
OWSOutgoingReceiptManager *outgoingReceiptManager =
[[OWSOutgoingReceiptManager alloc] initWithPrimaryStorage:primaryStorage];
[Environment setShared:[[Environment alloc] initWithPreferences:preferences]];
OWSContactsSyncing *contactsSyncing = [[OWSContactsSyncing alloc] initDefault];
OWSSounds *sounds = [[OWSSounds alloc] initWithPrimaryStorage:primaryStorage];
LockInteractionController *lockInteractionController = [[LockInteractionController alloc] initDefault];
OWSWindowManager *windowManager = [[OWSWindowManager alloc] initDefault];
[Environment setShared:[[Environment alloc] initWithPreferences:preferences
contactsSyncing:contactsSyncing
sounds:sounds
lockInteractionController:lockInteractionController
windowManager:windowManager]];
[SSKEnvironment setShared:[[SSKEnvironment alloc] initWithContactsManager:contactsManager
messageSender:messageSender

@ -4,8 +4,12 @@
#import <SignalServiceKit/SSKEnvironment.h>
@class LockInteractionController;
@class OWSContactsManager;
@class OWSContactsSyncing;
@class OWSPreferences;
@class OWSSounds;
@class OWSWindowManager;
/**
*
@ -19,10 +23,18 @@
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPreferences:(OWSPreferences *)preferences;
- (instancetype)initWithPreferences:(OWSPreferences *)preferences
contactsSyncing:(OWSContactsSyncing *)contactsSyncing
sounds:(OWSSounds *)sounds
lockInteractionController:(LockInteractionController *)lockInteractionController
windowManager:(OWSWindowManager *)windowManager;
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) OWSPreferences *preferences;
@property (nonatomic, readonly) OWSContactsSyncing *contactsSyncing;
@property (nonatomic, readonly) OWSSounds *sounds;
@property (nonatomic, readonly) LockInteractionController *lockInteractionController;
@property (nonatomic, readonly) OWSWindowManager *windowManager;
@property (class, nonatomic) Environment *shared;

@ -36,15 +36,26 @@ static Environment *sharedEnvironment = nil;
}
- (instancetype)initWithPreferences:(OWSPreferences *)preferences
{
contactsSyncing:(OWSContactsSyncing *)contactsSyncing
sounds:(OWSSounds *)sounds
lockInteractionController:(LockInteractionController *)lockInteractionController
windowManager:(OWSWindowManager *)windowManager {
self = [super init];
if (!self) {
return self;
}
OWSAssertDebug(preferences);
OWSAssertDebug(contactsSyncing);
OWSAssertDebug(sounds);
OWSAssertDebug(lockInteractionController);
OWSAssertDebug(windowManager);
_preferences = preferences;
_contactsSyncing = contactsSyncing;
_sounds = sounds;
_lockInteractionController = lockInteractionController;
_windowManager = windowManager;
OWSSingletonAssert();

@ -40,6 +40,7 @@ typedef NS_ENUM(NSUInteger, OWSSound) {
};
@class OWSAudioPlayer;
@class OWSPrimaryStorage;
@class TSThread;
@class YapDatabaseReadWriteTransaction;
@ -47,6 +48,8 @@ typedef NS_ENUM(NSUInteger, OWSSound) {
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
+ (NSString *)displayNameForSound:(OWSSound)sound;
+ (nullable NSString *)filenameForSound:(OWSSound)sound;

@ -3,6 +3,7 @@
//
#import "OWSSounds.h"
#import "Environment.h"
#import "OWSAudioPlayer.h"
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/OWSFileSystem.h>
@ -68,19 +69,9 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
+ (instancetype)sharedManager
{
static OWSSounds *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] initDefault];
});
return instance;
}
- (instancetype)initDefault
{
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
OWSAssertDebug(Environment.shared.sounds);
return [self initWithPrimaryStorage:primaryStorage];
return Environment.shared.sounds;
}
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage

@ -20,6 +20,7 @@ extern const UIWindowLevel UIWindowLevel_Background;
@interface OWSWindowManager : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initDefault NS_DESIGNATED_INITIALIZER;
+ (instancetype)sharedManager;

@ -3,6 +3,7 @@
//
#import "OWSWindowManager.h"
#import "Environment.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"
@ -129,12 +130,9 @@ const UIWindowLevel UIWindowLevel_MessageActions(void)
+ (instancetype)sharedManager
{
static OWSWindowManager *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] initDefault];
});
return instance;
OWSAssertDebug(Environment.shared.windowManager);
return Environment.shared.windowManager;
}
- (instancetype)initDefault

@ -1,9 +1,12 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
@interface LockInteractionController : NSObject
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initDefault NS_DESIGNATED_INITIALIZER;
typedef void (^LIControllerCompletionBlock)(void);
typedef BOOL (^LIControllerBlockingOperation)(void);
typedef void (^LIControllerRetryBlock)(

@ -1,8 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "LockInteractionController.h"
#import "Environment.h"
#import <SignalServiceKit/AppContext.h>
@interface LockInteractionController ()
@ -17,12 +18,22 @@
+ (instancetype)sharedController
{
static LockInteractionController *sharedController = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedController = [self new];
});
return sharedController;
OWSAssertDebug(Environment.shared.lockInteractionController);
return Environment.shared.lockInteractionController;
}
- (instancetype)initDefault {
self = [super init];
if (!self) {
return self;
}
OWSAssertIsOnMainThread();
OWSSingletonAssert();
return self;
}
+ (void)performBlock:(LIControllerBlockingOperation)blockingOperation

Loading…
Cancel
Save