diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 6d2b0d1cd..1bc41914b 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -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. diff --git a/Signal/src/UIApplication+OWS.swift b/Signal/src/UIApplication+OWS.swift index 34c1bd2dd..9f0149b9e 100644 --- a/Signal/src/UIApplication+OWS.swift +++ b/Signal/src/UIApplication+OWS.swift @@ -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 } diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index 7f59b2ff9..df030df79 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -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 diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index 061780bee..21c0ed8a8 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -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. // diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index c73db5fc4..0b926a223 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -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;