mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.6 KiB
Matlab
101 lines
1.6 KiB
Matlab
8 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "AppReadiness.h"
|
||
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
@interface AppReadiness ()
|
||
|
|
||
|
@property (atomic) BOOL isAppReady;
|
||
|
|
||
|
@property (nonatomic, nullable) NSMutableArray<AppReadyBlock> *appReadyBlocks;
|
||
|
|
||
|
@end
|
||
|
|
||
|
#pragma mark -
|
||
|
|
||
|
@implementation AppReadiness
|
||
|
|
||
|
+ (instancetype)sharedManager
|
||
|
{
|
||
|
static AppReadiness *sharedMyManager = nil;
|
||
|
static dispatch_once_t onceToken;
|
||
|
dispatch_once(&onceToken, ^{
|
||
|
sharedMyManager = [[self alloc] initDefault];
|
||
|
});
|
||
|
return sharedMyManager;
|
||
|
}
|
||
|
|
||
|
- (instancetype)initDefault
|
||
|
{
|
||
|
self = [super init];
|
||
|
|
||
|
if (!self) {
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
OWSSingletonAssert();
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
+ (BOOL)isAppReady
|
||
|
{
|
||
|
return self.sharedManager.isAppReady;
|
||
|
}
|
||
|
|
||
|
+ (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
|
||
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
|
|
||
|
[self.sharedManager runNowOrWhenAppIsReady:block];
|
||
|
}
|
||
|
|
||
|
- (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
|
||
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
|
OWSAssert(block);
|
||
|
|
||
|
if (self.isAppReady) {
|
||
|
block();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (!self.appReadyBlocks) {
|
||
|
self.appReadyBlocks = [NSMutableArray new];
|
||
|
}
|
||
|
[self.appReadyBlocks addObject:block];
|
||
|
}
|
||
|
|
||
|
+ (void)setAppIsReady
|
||
|
{
|
||
|
[self.sharedManager setAppIsReady];
|
||
|
}
|
||
|
|
||
|
- (void)setAppIsReady
|
||
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
|
OWSAssert(!self.isAppReady);
|
||
|
|
||
|
self.isAppReady = YES;
|
||
|
|
||
|
[self runAppReadyBlocks];
|
||
|
}
|
||
|
|
||
|
- (void)runAppReadyBlocks
|
||
|
{
|
||
|
OWSAssertIsOnMainThread();
|
||
|
OWSAssert(self.isAppReady);
|
||
|
|
||
|
for (AppReadyBlock block in self.appReadyBlocks) {
|
||
|
block();
|
||
|
}
|
||
|
self.appReadyBlocks = nil;
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|