From 9c8178653d3c4fbe82bf303943956b7c175dad6b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 12 Feb 2018 10:00:20 -0500 Subject: [PATCH] Revisit TODOs in the SAE work. --- Signal/src/AppDelegate.m | 13 +++----- SignalServiceKit/src/Util/AppVersion.h | 7 +++-- SignalServiceKit/src/Util/AppVersion.m | 30 +++++++++++++++++++ .../ShareViewController.swift | 17 ++++------- .../utils/ShareAppExtensionContext.m | 2 +- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index f911c0cda..726ecf30b 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -554,12 +554,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // and continue cleaning in the background. [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; - // TODO remove this once we're sure our app boot process is coherent. - // Currently this happens *before* db registration is complete when - // launching the app directly, but *after* db registration is complete when - // the app is launched in the background, e.g. from a voip notification. - [[OWSProfileManager sharedManager] ensureLocalProfileCached]; - // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully // sent before the app exited should be marked as failures. [[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; @@ -993,6 +987,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [OWSPreferences setIsRegistered:[TSAccountManager isRegistered]]; + // TODO: Once "app ready" logic is moved into AppSetup, move this line there. + [[OWSProfileManager sharedManager] ensureLocalProfileCached]; + // Note that this does much more than set a flag; // it will also run all deferred blocks. [AppReadiness setAppIsReady]; @@ -1013,7 +1010,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [DeviceSleepManager.sharedInstance removeBlockWithBlockObject:self]; - [AppVersion.instance appLaunchDidComplete]; + [AppVersion.instance mainAppLaunchDidComplete]; [Environment.current.contactsManager loadSignalAccountsFromCache]; @@ -1021,8 +1018,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [[OWSMessageReceiver sharedInstance] handleAnyUnprocessedEnvelopesAsync]; [[OWSBatchMessageProcessor sharedInstance] handleAnyUnprocessedEnvelopesAsync]; - [[OWSProfileManager sharedManager] ensureLocalProfileCached]; - #ifdef DEBUG // A bug in orphan cleanup could be disastrous so let's only diff --git a/SignalServiceKit/src/Util/AppVersion.h b/SignalServiceKit/src/Util/AppVersion.h index d5455f41a..df84b8b35 100755 --- a/SignalServiceKit/src/Util/AppVersion.h +++ b/SignalServiceKit/src/Util/AppVersion.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // @interface AppVersion : NSObject @@ -11,10 +11,13 @@ // Unlike lastAppVersion, this property isn't updated until // appLaunchDidComplete is called. @property (nonatomic, readonly) NSString *lastCompletedLaunchAppVersion; +@property (nonatomic, readonly) NSString *lastCompletedLaunchMainAppVersion; +@property (nonatomic, readonly) NSString *lastCompletedLaunchSAEAppVersion; + (instancetype)instance; -- (void)appLaunchDidComplete; +- (void)mainAppLaunchDidComplete; +- (void)saeLaunchDidComplete; - (BOOL)isFirstLaunch; diff --git a/SignalServiceKit/src/Util/AppVersion.m b/SignalServiceKit/src/Util/AppVersion.m index 863bfc79a..19f0b15ef 100755 --- a/SignalServiceKit/src/Util/AppVersion.m +++ b/SignalServiceKit/src/Util/AppVersion.m @@ -8,6 +8,10 @@ NSString *const kNSUserDefaults_FirstAppVersion = @"kNSUserDefaults_FirstAppVersion"; NSString *const kNSUserDefaults_LastAppVersion = @"kNSUserDefaults_LastVersion"; NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefaults_LastCompletedLaunchAppVersion"; +NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp + = @"kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp"; +NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion_SAE + = @"kNSUserDefaults_LastCompletedLaunchAppVersion_SAE"; @interface AppVersion () @@ -15,6 +19,8 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault @property (nonatomic) NSString *lastAppVersion; @property (nonatomic) NSString *currentAppVersion; @property (nonatomic) NSString *lastCompletedLaunchAppVersion; +@property (nonatomic) NSString *lastCompletedLaunchMainAppVersion; +@property (nonatomic) NSString *lastCompletedLaunchSAEAppVersion; @end @@ -44,6 +50,10 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault self.lastAppVersion = [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastAppVersion]; self.lastCompletedLaunchAppVersion = [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastCompletedLaunchAppVersion]; + self.lastCompletedLaunchMainAppVersion = + [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp]; + self.lastCompletedLaunchSAEAppVersion = + [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastCompletedLaunchAppVersion_SAE]; // Ensure the value for the "first launched version". if (!self.firstAppVersion) { @@ -63,6 +73,8 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]); DDLogInfo(@"%@ lastCompletedLaunchAppVersion: %@", self.logTag, self.lastCompletedLaunchAppVersion); + DDLogInfo(@"%@ lastCompletedLaunchMainAppVersion: %@", self.logTag, self.lastCompletedLaunchMainAppVersion); + DDLogInfo(@"%@ lastCompletedLaunchSAEAppVersion: %@", self.logTag, self.lastCompletedLaunchSAEAppVersion); } - (void)appLaunchDidComplete @@ -77,6 +89,24 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault [[NSUserDefaults appUserDefaults] synchronize]; } +- (void)mainAppLaunchDidComplete +{ + self.lastCompletedLaunchMainAppVersion = self.currentAppVersion; + [[NSUserDefaults appUserDefaults] setObject:self.currentAppVersion + forKey:kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp]; + + [self appLaunchDidComplete]; +} + +- (void)saeLaunchDidComplete +{ + self.lastCompletedLaunchSAEAppVersion = self.currentAppVersion; + [[NSUserDefaults appUserDefaults] setObject:self.currentAppVersion + forKey:kNSUserDefaults_LastCompletedLaunchAppVersion_SAE]; + + [self appLaunchDidComplete]; +} + - (BOOL)isFirstLaunch { return self.firstAppVersion != nil; diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index d80c7ba19..595c6434d 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -50,8 +50,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to use DeviceSleepManager in the SAE. - // TODO: - // [UIUtil applySignalAppearence]; + // TODO: Do we need to applySignalAppearence in the SAE? + UIUtil.applySignalAppearence() if CurrentAppContext().isRunningTests { // TODO: Do we need to implement isRunningTests in the SAE context? @@ -154,12 +154,6 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to use OWSDisappearingMessagesJob in the SAE. - // TODO remove this once we're sure our app boot process is coherent. - // Currently this happens *before* db registration is complete when - // launching the app directly, but *after* db registration is complete when - // the app is launched in the background, e.g. from a voip notification. - OWSProfileManager.shared().ensureLocalProfileCached() - // We don't need to use OWSFailedMessagesJob in the SAE. // We don't need to use OWSFailedAttachmentDownloadsJob in the SAE. @@ -172,7 +166,6 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to prod the TSSocketManager in the SAE. } - // TODO: Do we want to move this logic into the notification handler for "SAE will appear". if TSAccountManager.isRegistered() { DispatchQueue.main.async { [weak self] in guard let strongSelf = self else { return } @@ -227,6 +220,9 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed Logger.debug("\(self.logTag) \(#function)") + // TODO: Once "app ready" logic is moved into AppSetup, move this line there. + OWSProfileManager.shared().ensureLocalProfileCached() + // Note that this does much more than set a flag; // it will also run all deferred blocks. AppReadiness.setAppIsReady() @@ -241,8 +237,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to use DeviceSleepManager in the SAE. - // TODO: Should we distinguish main app and SAE "completion"? - AppVersion.instance().appLaunchDidComplete() + AppVersion.instance().saeLaunchDidComplete() Environment.current().contactsManager.loadSignalAccountsFromCache() diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index 60dc26ae7..c73db5fc4 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -189,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isRunningTests { - // TODO: I don't think we'll need to distinguish this in the SAE. + // We don't need to distinguish this in the SAE. return NO; }