Distinguish 'app will/did become ready' events.
This commit is contained in:
parent
d338e00b1a
commit
eb2e16872e
|
@ -550,7 +550,7 @@ static NSTimeInterval launchStartedAt;
|
|||
|
||||
if (!AppReadiness.isAppReady) {
|
||||
OWSLogWarn(@"Ignoring openURL: app not ready.");
|
||||
// We don't need to use [AppReadiness runNowOrWhenAppIsReady:];
|
||||
// We don't need to use [AppReadiness runNowOrWhenAppDidBecomeReady:];
|
||||
// the only URLs we handle in Signal iOS at the moment are used
|
||||
// for resuming the verification step of the registration flow.
|
||||
return NO;
|
||||
|
@ -596,7 +596,7 @@ static NSTimeInterval launchStartedAt;
|
|||
|
||||
[self ensureRootViewController];
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self handleActivation];
|
||||
}];
|
||||
|
||||
|
@ -616,7 +616,7 @@ static NSTimeInterval launchStartedAt;
|
|||
|
||||
- (void)enableBackgroundRefreshIfNecessary
|
||||
{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
if (OWS2FAManager.sharedManager.is2FAEnabled && [self.tsAccountManager isRegistered]) {
|
||||
// Ping server once a day to keep-alive 2FA clients.
|
||||
const NSTimeInterval kBackgroundRefreshInterval = 24 * 60 * 60;
|
||||
|
@ -732,7 +732,7 @@ static NSTimeInterval launchStartedAt;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
[SignalApp clearAllNotifications];
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[OWSMessageUtils.sharedManager updateApplicationBadgeCount];
|
||||
}];
|
||||
}
|
||||
|
@ -747,7 +747,7 @@ static NSTimeInterval launchStartedAt;
|
|||
return;
|
||||
}
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
if (![self.tsAccountManager isRegistered]) {
|
||||
UIAlertController *controller =
|
||||
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"REGISTER_CONTACTS_WELCOME", nil)
|
||||
|
@ -818,7 +818,7 @@ static NSTimeInterval launchStartedAt;
|
|||
return NO;
|
||||
}
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
NSString *_Nullable phoneNumber = handle;
|
||||
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
|
||||
phoneNumber = [self.primaryStorage phoneNumberForCallKitId:handle];
|
||||
|
@ -875,7 +875,7 @@ static NSTimeInterval launchStartedAt;
|
|||
return NO;
|
||||
}
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
NSString *_Nullable phoneNumber = handle;
|
||||
if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
|
||||
phoneNumber = [self.primaryStorage phoneNumberForCallKitId:handle];
|
||||
|
@ -980,7 +980,7 @@ static NSTimeInterval launchStartedAt;
|
|||
}
|
||||
|
||||
OWSLogInfo(@"%@", notification);
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[[PushManager sharedManager] application:application didReceiveLocalNotification:notification];
|
||||
}];
|
||||
}
|
||||
|
@ -1003,7 +1003,7 @@ static NSTimeInterval launchStartedAt;
|
|||
// later, after this method returns.
|
||||
//
|
||||
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623068-application?language=objc
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[[PushManager sharedManager] application:application
|
||||
handleActionWithIdentifier:identifier
|
||||
forLocalNotification:notification
|
||||
|
@ -1032,7 +1032,7 @@ static NSTimeInterval launchStartedAt;
|
|||
// later, after this method returns.
|
||||
//
|
||||
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623068-application?language=objc
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[[PushManager sharedManager] application:application
|
||||
handleActionWithIdentifier:identifier
|
||||
forLocalNotification:notification
|
||||
|
@ -1045,7 +1045,7 @@ static NSTimeInterval launchStartedAt;
|
|||
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
|
||||
{
|
||||
OWSLogInfo(@"performing background fetch");
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
__block AnyPromise *job = [AppEnvironment.shared.messageFetcherJob run].then(^{
|
||||
// HACK: Call completion handler after n seconds.
|
||||
//
|
||||
|
|
|
@ -105,13 +105,13 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
|||
{
|
||||
OWSLogInfo(@"received remote notification");
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self.messageFetcherJob run];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive {
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self.messageFetcherJob run];
|
||||
}];
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
|||
// If we want to re-introduce silent pushes we can remove this assert.
|
||||
OWSFailDebug(@"Unexpected content-available push.");
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
||||
completionHandler(UIBackgroundFetchResultNewData);
|
||||
});
|
||||
|
|
|
@ -138,7 +138,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
//
|
||||
// It's not safe to access OWSScreenLock.isScreenLockEnabled
|
||||
// until the app is ready.
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppWillBecomeReady:^{
|
||||
self.isScreenLockLocked = OWSScreenLock.sharedManager.isScreenLockEnabled;
|
||||
|
||||
[self ensureUI];
|
||||
|
@ -251,7 +251,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (!AppReadiness.isAppReady) {
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppWillBecomeReady:^{
|
||||
[self ensureUI];
|
||||
}];
|
||||
return;
|
||||
|
|
|
@ -214,7 +214,7 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
|
|||
}
|
||||
|
||||
- (void)sendConfigurationSyncMessage {
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self sendConfigurationSyncMessage_AppReady];
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class ContactsFrameworkContactStoreAdaptee: NSObject, ContactStoreAdaptee {
|
|||
|
||||
@objc
|
||||
func didBecomeActive() {
|
||||
AppReadiness.runNowOrWhenAppIsReady {
|
||||
AppReadiness.runNowOrWhenAppDidBecomeReady {
|
||||
let currentSortOrder = CNContactsUserDefaults.shared().sortOrder
|
||||
|
||||
guard currentSortOrder != self.lastSortOrder else {
|
||||
|
|
|
@ -94,7 +94,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
|
||||
OWSSingletonAssert();
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self rotateLocalProfileKeyIfNecessary];
|
||||
}];
|
||||
|
||||
|
@ -1479,7 +1479,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
- (void)blockListDidChange:(NSNotification *)notification {
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self rotateLocalProfileKeyIfNecessary];
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
object:nil];
|
||||
}
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self updateAccountAttributesIfNecessary];
|
||||
}];
|
||||
|
||||
|
@ -683,7 +683,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
- (void)reachabilityChanged {
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self updateAccountAttributesIfNecessary];
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
object:nil];
|
||||
|
||||
// Start processing.
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self drainQueue];
|
||||
}];
|
||||
|
||||
|
|
|
@ -422,7 +422,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedGroupIdsKey = @"kOWSBlockingMan
|
|||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
@synchronized(self)
|
||||
{
|
||||
[self syncBlockListIfNecessary];
|
||||
|
|
|
@ -69,7 +69,7 @@ void AssertIsOnDisappearingMessagesQueue()
|
|||
|
||||
// suspenders in case a deletion schedule is missed.
|
||||
NSTimeInterval kFallBackTimerInterval = 5 * kMinuteInterval;
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
if (CurrentAppContext().isMainApp) {
|
||||
self.fallbackTimer = [NSTimer weakScheduledTimerWithTimeInterval:kFallBackTimerInterval
|
||||
target:self
|
||||
|
@ -405,7 +405,7 @@ void AssertIsOnDisappearingMessagesQueue()
|
|||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
dispatch_async(OWSDisappearingMessagesJob.serialQueue, ^{
|
||||
[self runLoop];
|
||||
});
|
||||
|
|
|
@ -569,7 +569,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self syncQueuedVerificationStates];
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
} else {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[OWSMessageUtils.sharedManager updateApplicationBadgeCount];
|
||||
}];
|
||||
});
|
||||
|
|
|
@ -248,7 +248,7 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
|||
_finder = finder;
|
||||
_isDrainingQueue = NO;
|
||||
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self drainQueue];
|
||||
}];
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ NSString *const kOutgoingReadReceiptManagerCollection = @"kOutgoingReadReceiptMa
|
|||
object:nil];
|
||||
|
||||
// Start processing.
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self process];
|
||||
}];
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
OWSSingletonAssert();
|
||||
|
||||
// Start processing.
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self scheduleProcessing];
|
||||
}];
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
|
|||
}
|
||||
|
||||
@objc public func setup() {
|
||||
AppReadiness.runNowOrWhenAppIsReady {
|
||||
AppReadiness.runNowOrWhenAppDidBecomeReady {
|
||||
guard TSAccountManager.isRegistered() else {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1048,7 +1048,7 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
|
|||
if (!AppReadiness.isAppReady) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
[AppReadiness runNowOrWhenAppIsReady:^{
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
[self applyDesiredSocketState];
|
||||
}];
|
||||
});
|
||||
|
|
|
@ -21,7 +21,14 @@ typedef void (^AppReadyBlock)(void);
|
|||
//
|
||||
// This method should only be called on the main thread.
|
||||
// The block will always be called on the main thread.
|
||||
+ (void)runNowOrWhenAppIsReady:(AppReadyBlock)block NS_SWIFT_NAME(runNowOrWhenAppIsReady(_:));
|
||||
+ (void)runNowOrWhenAppWillBecomeReady:(AppReadyBlock)block NS_SWIFT_NAME(runNowOrWhenAppWillBecomeReady(_:));
|
||||
|
||||
// If the app is ready, the block is called immediately;
|
||||
// otherwise it is called when the app becomes ready.
|
||||
//
|
||||
// This method should only be called on the main thread.
|
||||
// The block will always be called on the main thread.
|
||||
+ (void)runNowOrWhenAppDidBecomeReady:(AppReadyBlock)block NS_SWIFT_NAME(runNowOrWhenAppDidBecomeReady(_:));
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@property (atomic) BOOL isAppReady;
|
||||
|
||||
@property (nonatomic) NSMutableArray<AppReadyBlock> *appReadyBlocks;
|
||||
@property (nonatomic) NSMutableArray<AppReadyBlock> *appWillBecomeReadyBlocks;
|
||||
@property (nonatomic) NSMutableArray<AppReadyBlock> *appDidBecomeReadyBlocks;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -39,7 +40,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
OWSSingletonAssert();
|
||||
|
||||
self.appReadyBlocks = [NSMutableArray new];
|
||||
self.appWillBecomeReadyBlocks = [NSMutableArray new];
|
||||
self.appDidBecomeReadyBlocks = [NSMutableArray new];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -49,14 +51,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return [self.sharedManager isAppReady];
|
||||
}
|
||||
|
||||
+ (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
|
||||
+ (void)runNowOrWhenAppWillBecomeReady:(AppReadyBlock)block
|
||||
{
|
||||
DispatchMainThreadSafe(^{
|
||||
[self.sharedManager runNowOrWhenAppIsReady:block];
|
||||
[self.sharedManager runNowOrWhenAppWillBecomeReady:block];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)runNowOrWhenAppIsReady:(AppReadyBlock)block
|
||||
- (void)runNowOrWhenAppWillBecomeReady:(AppReadyBlock)block
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssertDebug(block);
|
||||
|
@ -72,7 +74,33 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return;
|
||||
}
|
||||
|
||||
[self.appReadyBlocks addObject:block];
|
||||
[self.appWillBecomeReadyBlocks addObject:block];
|
||||
}
|
||||
|
||||
+ (void)runNowOrWhenAppDidBecomeReady:(AppReadyBlock)block
|
||||
{
|
||||
DispatchMainThreadSafe(^{
|
||||
[self.sharedManager runNowOrWhenAppDidBecomeReady:block];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)runNowOrWhenAppDidBecomeReady:(AppReadyBlock)block
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssertDebug(block);
|
||||
|
||||
if (CurrentAppContext().isRunningTests) {
|
||||
// We don't need to an any "on app ready" work
|
||||
// in the tests.
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.isAppReady) {
|
||||
block();
|
||||
return;
|
||||
}
|
||||
|
||||
[self.appDidBecomeReadyBlocks addObject:block];
|
||||
}
|
||||
|
||||
+ (void)setAppIsReady
|
||||
|
@ -97,10 +125,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSAssertIsOnMainThread();
|
||||
OWSAssertDebug(self.isAppReady);
|
||||
|
||||
NSArray<AppReadyBlock> *appReadyBlocks = [self.appReadyBlocks copy];
|
||||
[self.appReadyBlocks removeAllObjects];
|
||||
NSArray<AppReadyBlock> *appWillBecomeReadyBlocks = [self.appWillBecomeReadyBlocks copy];
|
||||
[self.appWillBecomeReadyBlocks removeAllObjects];
|
||||
NSArray<AppReadyBlock> *appDidBecomeReadyBlocks = [self.appDidBecomeReadyBlocks copy];
|
||||
[self.appDidBecomeReadyBlocks removeAllObjects];
|
||||
|
||||
for (AppReadyBlock block in appReadyBlocks) {
|
||||
// We invoke the _will become_ blocks before the _did become_ blocks.
|
||||
for (AppReadyBlock block in appWillBecomeReadyBlocks) {
|
||||
block();
|
||||
}
|
||||
for (AppReadyBlock block in appDidBecomeReadyBlocks) {
|
||||
block();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
|||
Logger.debug("")
|
||||
|
||||
if isReadyForAppExtensions {
|
||||
AppReadiness.runNowOrWhenAppIsReady { [weak self] in
|
||||
AppReadiness.runNowOrWhenAppDidBecomeReady { [weak self] in
|
||||
AssertIsOnMainThread()
|
||||
guard let strongSelf = self else { return }
|
||||
strongSelf.activate()
|
||||
|
|
Loading…
Reference in New Issue