session-ios/SignalMessaging/environment/AppSetup.m

70 lines
2.7 KiB
Mathematica
Raw Normal View History

2017-12-07 19:53:13 +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>
#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>
#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
{
OWSAssertDebug(callMessageHandlerBlock);
OWSAssertDebug(notificationsManagerBlock);
OWSAssertDebug(migrationCompletion);
__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];
[Environment setShared:[Release releaseEnvironment]];
2017-12-07 19:53:13 +01:00
id<OWSCallMessageHandler> callMessageHandler = callMessageHandlerBlock();
id<NotificationsProtocol> notificationsManager = notificationsManagerBlock();
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
// 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-24 19:15:11 +02:00
migrationCompletion();
OWSAssertDebug(backgroundTask);
2018-04-24 19:15:11 +02:00
backgroundTask = nil;
}];
}];
2017-12-07 19:53:13 +01:00
});
}
@end
NS_ASSUME_NONNULL_END