Merge branch 'charlesmchen/loadingRootViewController'

pull/1/head
Matthew Chen 8 years ago
commit 9eb769fe9c

@ -46,10 +46,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
@interface AppDelegate () @interface AppDelegate ()
@property (nonatomic) UIWindow *screenProtectionWindow; @property (nonatomic) UIWindow *screenProtectionWindow;
@property (nonatomic) UIWindow *databaseViewRegistrationOverlay;
@property (nonatomic) OWSIncomingMessageReadObserver *incomingMessageReadObserver; @property (nonatomic) OWSIncomingMessageReadObserver *incomingMessageReadObserver;
@property (nonatomic) OWSStaleNotificationObserver *staleNotificationObserver; @property (nonatomic) OWSStaleNotificationObserver *staleNotificationObserver;
@property (nonatomic) OWSContactsSyncing *contactsSyncing; @property (nonatomic) OWSContactsSyncing *contactsSyncing;
@property (nonatomic) BOOL hasInitialRootViewController;
@end @end
@ -118,15 +118,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([TSAccountManager isRegistered]) { // Show the launch screen until the async database view registrations are complete.
self.window.rootViewController = [[UIStoryboard main] instantiateInitialViewController]; self.window.rootViewController = [self loadingRootViewController];
} else {
RegistrationViewController *viewController = [RegistrationViewController new];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.navigationBarHidden = YES;
self.window.rootViewController = navigationController;
}
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
@ -198,6 +191,43 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return YES; return YES;
} }
- (UIViewController *)loadingRootViewController
{
UIViewController *viewController =
[[UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil] instantiateInitialViewController];
BOOL shouldShowUpgradeLabel = NO;
NSString *previousVersion = AppVersion.instance.lastAppVersion;
// We added a number of database views in v2.13.0.
if ([VersionMigrations isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.13.0"]) {
shouldShowUpgradeLabel = YES;
}
if (shouldShowUpgradeLabel) {
UIView *rootView = viewController.view;
UIImageView *iconView = nil;
for (UIView *subview in viewController.view.subviews) {
if ([subview isKindOfClass:[UIImageView class]]) {
iconView = (UIImageView *)subview;
break;
}
}
if (!iconView) {
OWSFail(@"Database view registration overlay has unexpected contents.");
} else {
UILabel *label = [UILabel new];
label.text = NSLocalizedString(
@"DATABASE_VIEW_OVERLAY_TITLE", @"Indicates that the app is updating its database.");
label.font = [UIFont ows_mediumFontWithSize:18.f];
label.textColor = [UIColor whiteColor];
[rootView addSubview:label];
[label autoHCenterInSuperview];
[label autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:iconView withOffset:25.f];
}
}
return viewController;
}
- (void)setupEnvironment - (void)setupEnvironment
{ {
[Environment setCurrent:[Release releaseEnvironment]]; [Environment setCurrent:[Release releaseEnvironment]];
@ -417,7 +447,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
[self removeScreenProtection]; [self removeScreenProtection];
[self ensureDatabaseViewRegistrationOverlay]; [self ensureRootViewController];
// Always check prekeys after app launches, and sometimes check on app activation. // Always check prekeys after app launches, and sometimes check on app activation.
[TSPreKeyManager checkPreKeysIfNecessary]; [TSPreKeyManager checkPreKeysIfNecessary];
@ -689,68 +719,29 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
{ {
DDLogInfo(@"databaseViewRegistrationComplete"); DDLogInfo(@"databaseViewRegistrationComplete");
[self ensureDatabaseViewRegistrationOverlay]; [self ensureRootViewController];
} }
- (void)ensureDatabaseViewRegistrationOverlay - (void)ensureRootViewController
{ {
BOOL shouldShowOverlay = [TSDatabaseView hasPendingViewRegistrations]; DDLogInfo(@"ensureRootViewController");
if (!shouldShowOverlay) { if ([TSDatabaseView hasPendingViewRegistrations] || self.hasInitialRootViewController) {
if (self.databaseViewRegistrationOverlay && !self.databaseViewRegistrationOverlay.hidden) {
DDLogWarn(@"Hiding database view registration overlay.");
}
self.databaseViewRegistrationOverlay.hidden = YES;
return; return;
} }
self.hasInitialRootViewController = YES;
if (!self.databaseViewRegistrationOverlay || self.databaseViewRegistrationOverlay.hidden) { DDLogInfo(@"Presenting initial root view controller");
DDLogWarn(@"Showing database view registration overlay.");
}
if (!self.databaseViewRegistrationOverlay) { if ([TSAccountManager isRegistered]) {
// Recycle the "screen lock view", but add a label. self.window.rootViewController = [[UIStoryboard main] instantiateInitialViewController];
UIWindow *window = [[UIWindow alloc] initWithFrame:self.window.bounds];
window.hidden = YES;
window.opaque = YES;
window.userInteractionEnabled = NO;
window.windowLevel = CGFLOAT_MAX;
window.backgroundColor = UIColor.ows_materialBlueColor;
window.rootViewController =
[[UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil] instantiateInitialViewController];
BOOL shouldShowUpgradeLabel = NO;
NSString *previousVersion = AppVersion.instance.lastAppVersion;
// We added a number of database views in v2.13.0.
if ([VersionMigrations isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.13.0"]) {
shouldShowUpgradeLabel = YES;
}
if (shouldShowUpgradeLabel) {
UIView *rootView = window.rootViewController.view;
UIImageView *iconView = nil;
for (UIView *subview in rootView.subviews) {
if ([subview isKindOfClass:[UIImageView class]]) {
iconView = (UIImageView *)subview;
break;
}
}
if (!iconView) {
OWSFail(@"Database view registration overlay has unexpected contents.");
} else { } else {
UILabel *label = [UILabel new]; RegistrationViewController *viewController = [RegistrationViewController new];
label.text = NSLocalizedString( UINavigationController *navigationController =
@"DATABASE_VIEW_OVERLAY_TITLE", @"Indicates that the app is updating its database."); [[UINavigationController alloc] initWithRootViewController:viewController];
label.font = [UIFont ows_mediumFontWithSize:18.f]; navigationController.navigationBarHidden = YES;
label.textColor = [UIColor whiteColor]; self.window.rootViewController = navigationController;
[rootView addSubview:label];
[label autoHCenterInSuperview];
[label autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:iconView withOffset:25.f];
}
}
self.databaseViewRegistrationOverlay = window;
} }
self.databaseViewRegistrationOverlay.hidden = NO;
} }
#pragma mark - Logging #pragma mark - Logging

Loading…
Cancel
Save