Add mainWindow property to app context.

This commit is contained in:
Matthew Chen 2018-04-16 17:19:06 -04:00
parent 4e9c653c8a
commit 85cb78ddfe
5 changed files with 18 additions and 22 deletions

View File

@ -168,12 +168,12 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return YES;
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIWindow *mainWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = mainWindow;
CurrentAppContext().mainWindow = mainWindow;
// Show the launch screen until the async database view registrations are complete.
self.window.rootViewController = [self loadingRootViewController];
[self.window makeKeyAndVisible];
mainWindow.rootViewController = [self loadingRootViewController];
[mainWindow makeKeyAndVisible];
// performUpdateCheck must be invoked after Environment has been initialized because
// upgrade process may depend on Environment.

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -7,16 +7,19 @@ import Foundation
extension UIApplication {
var frontmostViewControllerIgnoringAlerts: UIViewController? {
return findFrontmostViewController(ignoringAlerts:true)
return findFrontmostViewController(ignoringAlerts: true)
}
var frontmostViewController: UIViewController? {
return findFrontmostViewController(ignoringAlerts:false)
return findFrontmostViewController(ignoringAlerts: false)
}
internal func findFrontmostViewController(ignoringAlerts: Bool) -> UIViewController? {
let window = UIApplication.shared.keyWindow
guard let viewController = window!.rootViewController else {
guard let window = CurrentAppContext().mainWindow else {
return nil
}
Logger.error("findFrontmostViewController: \(window)")
guard let viewController = window.rootViewController else {
owsFail("\(self.logTag) in \(#function) Missing root view controller.")
return nil
}

View File

@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
@implementation MainAppContext
@synthesize mainWindow = _mainWindow;
- (instancetype)init
{
self = [super init];
@ -174,11 +176,6 @@ NS_ASSUME_NONNULL_BEGIN
return UIApplication.sharedApplication.frontmostViewControllerIgnoringAlerts;
}
- (nullable UIView *)rootReferenceView
{
return UIApplication.sharedApplication.keyWindow;
}
- (nullable UIAlertAction *)openSystemSettingsAction
{
return [UIAlertAction actionWithTitle:CommonStrings.openSettingsButton

View File

@ -29,8 +29,7 @@ typedef void (^BackgroundTaskExpirationHandler)(void);
@property (nonatomic, readonly) BOOL isRunningTests;
// Useful for translating coordinates to the "entire screen"
@property (nonatomic, readonly, nullable) UIView *rootReferenceView;
@property (atomic, nullable) UIWindow *mainWindow;
// Should only be called if isMainApp is YES.
//

View File

@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
@implementation ShareAppExtensionContext
@synthesize mainWindow = _mainWindow;
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super init];
@ -172,11 +174,6 @@ NS_ASSUME_NONNULL_BEGIN
return [self.rootViewController findFrontmostViewController:YES];
}
- (nullable UIView *)rootReferenceView
{
return self.rootViewController.view;
}
- (nullable UIAlertAction *)openSystemSettingsAction
{
return nil;