From 100adae2459e82164126c480fc9d5a5200b6ca96 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 26 Jan 2018 15:58:36 -0500 Subject: [PATCH] Register all database views asynchronously. --- Signal/src/AppDelegate.m | 4 ++-- SignalServiceKit/src/Storage/OWSStorage.m | 5 ----- SignalServiceKit/src/Util/AppReadiness.h | 7 +++++++ SignalServiceKit/src/Util/AppReadiness.m | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 8f5c44fac..f5cd08944 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -401,7 +401,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [self ensureRootViewController]; - [AppReadiness.sharedManager runNowOrWhenAppIsReady:^{ + [AppReadiness runNowOrWhenAppIsReady:^{ [self handleActivation]; }]; @@ -768,7 +768,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [OWSPreferences setIsRegistered:[TSAccountManager isRegistered]]; - [AppReadiness.sharedManager setAppIsReady]; + [AppReadiness setAppIsReady]; if ([TSAccountManager isRegistered]) { DDLogInfo(@"localNumber: %@", [TSAccountManager localNumber]); diff --git a/SignalServiceKit/src/Storage/OWSStorage.m b/SignalServiceKit/src/Storage/OWSStorage.m index 4258e91bd..d92749bad 100644 --- a/SignalServiceKit/src/Storage/OWSStorage.m +++ b/SignalServiceKit/src/Storage/OWSStorage.m @@ -314,11 +314,6 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void); - (BOOL)areAllRegistrationsComplete { - DDLogInfo(@"%@ areAllRegistrationsComplete: %d %d = %d", - self.logTag, - self.areSyncRegistrationsComplete, - self.areAsyncRegistrationsComplete, - self.areSyncRegistrationsComplete && self.areAsyncRegistrationsComplete); return self.areSyncRegistrationsComplete && self.areAsyncRegistrationsComplete; } diff --git a/SignalServiceKit/src/Util/AppReadiness.h b/SignalServiceKit/src/Util/AppReadiness.h index 03541b0e5..e54156d5e 100755 --- a/SignalServiceKit/src/Util/AppReadiness.h +++ b/SignalServiceKit/src/Util/AppReadiness.h @@ -10,10 +10,17 @@ typedef void (^AppReadyBlock)(void); - (instancetype)init NS_UNAVAILABLE; +// This method can be called on any thread. + (BOOL)isAppReady; +// This method should only be called on the main thread. + (void)setAppIsReady; +// 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)runNowOrWhenAppIsReady:(AppReadyBlock)block; @end diff --git a/SignalServiceKit/src/Util/AppReadiness.m b/SignalServiceKit/src/Util/AppReadiness.m index 42fee4440..95ba13e7c 100755 --- a/SignalServiceKit/src/Util/AppReadiness.m +++ b/SignalServiceKit/src/Util/AppReadiness.m @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)isAppReady { - return self.sharedManager.isAppReady; + return [self.sharedManager isAppReady]; } + (void)runNowOrWhenAppIsReady:(AppReadyBlock)block