-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
EXKernelServiceRegistry.m
211 lines (187 loc) · 6.69 KB
/
EXKernelServiceRegistry.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright 2015-present 650 Industries. All rights reserved.
#import "EXKernelServiceRegistry.h"
#import "EXCachedResourceManager.h"
#import "EXErrorRecoveryManager.h"
#import "EXFileSystemManager.h"
#import "EXGoogleAuthManager.h"
#import "EXHomeModuleManager.h"
#import "EXKernelAppRegistry.h"
#import "EXKernelLinkingManager.h"
#import "EXKernelService.h"
#import "EXRemoteNotificationManager.h"
#import "EXScreenOrientationManager.h"
#import "EXSensorManager.h"
#import "EXUpdatesManager.h"
#import "EXUserNotificationManager.h"
#import "EXUserNotificationCenter.h"
#import <UMCore/UMModuleRegistryProvider.h>
@interface EXKernelServiceRegistry ()
@property (nonatomic, strong) EXCachedResourceManager *cachedResourceManager;
@property (nonatomic, strong) EXFileSystemManager *fileSystemManager;
@property (nonatomic, strong) EXGoogleAuthManager *googleAuthManager;
@property (nonatomic, strong) EXErrorRecoveryManager *errorRecoveryManager;
@property (nonatomic, strong) EXHomeModuleManager *homeModuleManager;
@property (nonatomic, strong) EXKernelLinkingManager *linkingManager;
@property (nonatomic, strong) EXRemoteNotificationManager *remoteNotificationManager;
@property (nonatomic, strong) EXScreenOrientationManager *screenOrientationManager;
@property (nonatomic, strong) EXSensorManager *sensorManager;
@property (nonatomic, strong) EXUpdatesManager *updatesManager;
@property (nonatomic, strong) EXUserNotificationManager *notificationsManager;
@property (nonatomic, strong) EXUserNotificationCenter *notificationCenter;
@property (nonatomic, strong) NSDictionary<NSString *, id> *allServices;
@end
@implementation EXKernelServiceRegistry
- (instancetype)init
{
if (self = [super init]) {
// TODO: init these in some clean way
[self cachedResourceManager];
[self errorRecoveryManager];
[self remoteNotificationManager];
[self linkingManager];
[self homeModuleManager];
[self screenOrientationManager];
[self googleAuthManager];
[self sensorManager];
[self fileSystemManager];
[self updatesManager];
[self notificationsManager];
[self notificationCenter];
}
return self;
}
- (EXCachedResourceManager *)cachedResourceManager
{
if (!_cachedResourceManager) {
_cachedResourceManager = [[EXCachedResourceManager alloc] init];
}
return _cachedResourceManager;
}
- (EXRemoteNotificationManager *)remoteNotificationManager
{
if (!_remoteNotificationManager) {
_remoteNotificationManager = [[EXRemoteNotificationManager alloc] initWithUserNotificationCenter:[self notificationCenter]];
}
return _remoteNotificationManager;
}
- (EXErrorRecoveryManager *)errorRecoveryManager
{
if (!_errorRecoveryManager) {
_errorRecoveryManager = [[EXErrorRecoveryManager alloc] init];
}
return _errorRecoveryManager;
}
- (EXFileSystemManager *)fileSystemManager
{
if (!_fileSystemManager) {
_fileSystemManager = [[EXFileSystemManager alloc] init];
}
return _fileSystemManager;
}
- (EXGoogleAuthManager *)googleAuthManager
{
if (!_googleAuthManager) {
_googleAuthManager = [[EXGoogleAuthManager alloc] init];
}
return _googleAuthManager;
}
- (EXKernelLinkingManager *)linkingManager
{
if (!_linkingManager) {
_linkingManager = [[EXKernelLinkingManager alloc] init];
}
return _linkingManager;
}
- (EXHomeModuleManager *)homeModuleManager
{
if (!_homeModuleManager) {
_homeModuleManager = [[EXHomeModuleManager alloc] init];
}
return _homeModuleManager;
}
- (EXScreenOrientationManager *)screenOrientationManager
{
if (!_screenOrientationManager) {
_screenOrientationManager = [[EXScreenOrientationManager alloc] init];
}
return _screenOrientationManager;
}
- (EXSensorManager *)sensorManager
{
if (!_sensorManager) {
_sensorManager = [[EXSensorManager alloc] init];
}
return _sensorManager;
}
- (EXUpdatesManager *)updatesManager
{
if (!_updatesManager) {
_updatesManager = [[EXUpdatesManager alloc] init];
}
return _updatesManager;
}
- (EXUserNotificationManager *)notificationsManager
{
if (!_notificationsManager) {
_notificationsManager = [[EXUserNotificationManager alloc] init];
}
return _notificationsManager;
}
- (EXUserNotificationCenter *)notificationCenter
{
if (!_notificationCenter) {
_notificationCenter = [[EXUserNotificationCenter alloc] init];
}
return _notificationCenter;
}
- (NSDictionary *)allServices
{
if (!_allServices) {
NSMutableDictionary *result = [NSMutableDictionary dictionary];
// Here we have services that must be accessible by our scoped Expo modules
// EXVersionManagers pass these modules to scoped modules as an initializer argument
//
// New modules should access singleton modules via the module registry.
// New singleton modules should register themselves in UMModuleRegistryProvider's set
// using EX_REGISTER_SINGLETON_MODULE macro.
NSArray *registryServices = @[
self.cachedResourceManager,
self.errorRecoveryManager,
self.fileSystemManager,
self.googleAuthManager,
self.homeModuleManager,
self.linkingManager,
self.remoteNotificationManager,
self.screenOrientationManager,
self.sensorManager,
self.updatesManager,
self.notificationsManager,
self.notificationCenter
];
NSArray *allServices = [registryServices arrayByAddingObjectsFromArray:[[UMModuleRegistryProvider singletonModules] allObjects]];
for (id service in allServices) {
NSString *className = NSStringFromClass([service class]);
result[className] = service;
}
_allServices = result;
}
return _allServices;
}
#pragma mark - app registry delegate
- (void)appRegistry:(EXKernelAppRegistry *)registry didRegisterAppRecord:(EXKernelAppRecord *)appRecord
{
[self.allServices enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull className, id _Nonnull service, BOOL * _Nonnull stop) {
if ([service respondsToSelector:@selector(kernelDidRegisterAppWithRecord:)]) {
[service kernelDidRegisterAppWithRecord:appRecord];
}
}];
}
- (void)appRegistry:(EXKernelAppRegistry *)registry willUnregisterAppRecord:(EXKernelAppRecord *)appRecord
{
[self.allServices enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull className, id _Nonnull service, BOOL * _Nonnull stop) {
if ([service respondsToSelector:@selector(kernelWillUnregisterAppWithRecord:)]) {
[service kernelWillUnregisterAppWithRecord:appRecord];
}
}];
}
@end