2017-12-07 19:53:13 +01:00
|
|
|
//
|
2018-01-10 16:54:17 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-12-07 19:53:13 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "AppSetup.h"
|
|
|
|
#import "Environment.h"
|
|
|
|
#import "Release.h"
|
|
|
|
#import "VersionMigrations.h"
|
|
|
|
#import <AxolotlKit/SessionCipher.h>
|
2018-01-10 16:54:17 +01:00
|
|
|
#import <SignalMessaging/OWSDatabaseMigration.h>
|
2017-12-07 19:53:13 +01:00
|
|
|
#import <SignalMessaging/OWSProfileManager.h>
|
|
|
|
#import <SignalMessaging/SignalMessaging-Swift.h>
|
2018-02-27 17:14:25 +01:00
|
|
|
#import <SignalServiceKit/OWSBackgroundTask.h>
|
2017-12-19 04:56:02 +01:00
|
|
|
#import <SignalServiceKit/OWSStorage.h>
|
2018-08-31 19:12:40 +02:00
|
|
|
#import <SignalServiceKit/SSKEnvironment.h>
|
2017-12-07 19:53:13 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation AppSetup
|
|
|
|
|
2018-04-24 19:15:11 +02:00
|
|
|
+ (void)setupEnvironmentWithCallMessageHandlerBlock:(CallMessageHandlerBlock)callMessageHandlerBlock
|
|
|
|
notificationsProtocolBlock:(NotificationsManagerBlock)notificationsManagerBlock
|
|
|
|
migrationCompletion:(dispatch_block_t)migrationCompletion
|
2017-12-07 19:53:13 +01:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(callMessageHandlerBlock);
|
|
|
|
OWSAssertDebug(notificationsManagerBlock);
|
|
|
|
OWSAssertDebug(migrationCompletion);
|
2018-04-23 21:49:20 +02:00
|
|
|
|
|
|
|
__block OWSBackgroundTask *_Nullable backgroundTask =
|
|
|
|
[OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
|
2017-12-07 19:53:13 +01:00
|
|
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
2018-02-27 17:14:25 +01:00
|
|
|
// Order matters here.
|
|
|
|
[[OWSBackgroundTaskManager sharedManager] observeNotifications];
|
|
|
|
|
2018-08-31 19:22:19 +02:00
|
|
|
[Environment setShared:[Release releaseEnvironment]];
|
2017-12-07 19:53:13 +01:00
|
|
|
|
|
|
|
id<OWSCallMessageHandler> callMessageHandler = callMessageHandlerBlock();
|
|
|
|
id<NotificationsProtocol> notificationsManager = notificationsManagerBlock();
|
|
|
|
|
2018-08-31 19:16:31 +02:00
|
|
|
SSKEnvironment *shared = [[SSKEnvironment alloc] initWithCallMessageHandler:callMessageHandler
|
|
|
|
contactsManager:Environment.shared.contactsManager
|
|
|
|
messageSender:Environment.shared.messageSender
|
|
|
|
notificationsManager:notificationsManager
|
|
|
|
profileManager:OWSProfileManager.sharedManager];
|
|
|
|
[SSKEnvironment setShared:shared];
|
2017-12-07 19:53:13 +01:00
|
|
|
|
2018-01-10 16:54:17 +01:00
|
|
|
// Register renamed classes.
|
|
|
|
[NSKeyedUnarchiver setClass:[OWSUserProfile class] forClassName:[OWSUserProfile collection]];
|
|
|
|
[NSKeyedUnarchiver setClass:[OWSDatabaseMigration class] forClassName:[OWSDatabaseMigration collection]];
|
|
|
|
|
2018-04-24 19:15:11 +02:00
|
|
|
[OWSStorage registerExtensionsWithMigrationBlock:^() {
|
|
|
|
// Don't start database migrations until storage is ready.
|
|
|
|
[VersionMigrations performUpdateCheckWithCompletion:^() {
|
|
|
|
OWSAssertIsOnMainThread();
|
2018-04-23 21:49:20 +02:00
|
|
|
|
2018-04-24 19:15:11 +02:00
|
|
|
migrationCompletion();
|
2018-04-23 21:49:20 +02:00
|
|
|
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(backgroundTask);
|
2018-04-24 19:15:11 +02:00
|
|
|
backgroundTask = nil;
|
|
|
|
}];
|
2018-04-23 21:49:20 +02:00
|
|
|
}];
|
2017-12-07 19:53:13 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|