1// Copyright © 2018 650 Industries. All rights reserved.
2
3#import "EXScopedModuleRegistry.h"
4
5#import "EXScopedModuleRegistryAdapter.h"
6#import "EXSensorsManagerBinding.h"
7#import "EXConstantsBinding.h"
8#import "EXScopedFileSystemModule.h"
9#import "EXUnversioned.h"
10#import "EXScopedFilePermissionModule.h"
11#import "EXScopedFontLoader.h"
12#import "EXScopedSecureStore.h"
13#import "EXScopedPermissions.h"
14#import "EXScopedSegment.h"
15#import "EXScopedLocalAuthentication.h"
16#import "EXScopedBranch.h"
17#import "EXScopedErrorRecoveryModule.h"
18#import "EXScopedFacebook.h"
19#import "EXScopedFirebaseCore.h"
20#import "EXUpdatesBinding.h"
21
22#import "EXScopedReactNativeAdapter.h"
23#import "EXExpoUserNotificationCenterProxy.h"
24
25#import "EXScopedNotificationsEmitter.h"
26#import "EXScopedNotificationsHandlerModule.h"
27#import "EXScopedNotificationBuilder.h"
28#import "EXScopedNotificationSchedulerModule.h"
29#import "EXScopedNotificationPresentationModule.h"
30#import "EXScopedNotificationCategoriesModule.h"
31#import "EXScopedServerRegistrationModule.h"
32
33#if __has_include(<EXTaskManager/EXTaskManager.h>)
34#import <EXTaskManager/EXTaskManager.h>
35#endif
36
37@implementation EXScopedModuleRegistryAdapter
38
39- (EXModuleRegistry *)moduleRegistryForParams:(NSDictionary *)params
40                  forExperienceStableLegacyId:(NSString *)experienceStableLegacyId
41                                     scopeKey:(NSString *)scopeKey
42                                     manifest:(EXManifestsManifest *)manifest
43                           withKernelServices:(NSDictionary *)kernelServices
44{
45  EXModuleRegistry *moduleRegistry = [self.moduleRegistryProvider moduleRegistry];
46
47#if __has_include(<EXUpdates/EXUpdatesService.h>)
48  EXUpdatesBinding *updatesBinding = [[EXUpdatesBinding alloc] initWithScopeKey:scopeKey
49                                                                     updatesKernelService:kernelServices[EX_UNVERSIONED(@"EXUpdatesManager")]
50                                                                    databaseKernelService:kernelServices[EX_UNVERSIONED(@"EXUpdatesDatabaseManager")]];
51  [moduleRegistry registerInternalModule:updatesBinding];
52#endif
53
54#if __has_include(<EXConstants/EXConstantsService.h>)
55  EXConstantsBinding *constantsBinding = [[EXConstantsBinding alloc] initWithParams:params];
56  [moduleRegistry registerInternalModule:constantsBinding];
57#endif
58
59#if __has_include(<EXFacebook/EXFacebook.h>)
60  // only override in Expo Go
61  if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) {
62    EXScopedFacebook *scopedFacebook = [[EXScopedFacebook alloc] initWithScopeKey:scopeKey manifest:manifest];
63    [moduleRegistry registerExportedModule:scopedFacebook];
64  }
65#endif
66
67#if __has_include(<ExpoFileSystem/EXFileSystem.h>)
68  EXScopedFileSystemModule *fileSystemModule;
69  if (params[@"fileSystemDirectories"]) {
70    NSString *documentDirectory = params[@"fileSystemDirectories"][@"documentDirectory"];
71    NSString *cachesDirectory = params[@"fileSystemDirectories"][@"cachesDirectory"];
72    fileSystemModule = [[EXScopedFileSystemModule alloc] initWithDocumentDirectory:documentDirectory
73                                                                   cachesDirectory:cachesDirectory
74                                                                   bundleDirectory:nil];
75  } else {
76    fileSystemModule = [EXScopedFileSystemModule new];
77  }
78  [moduleRegistry registerExportedModule:fileSystemModule];
79  [moduleRegistry registerInternalModule:fileSystemModule];
80#endif
81
82#if __has_include(<EXFont/EXFontLoader.h>)
83  EXScopedFontLoader *fontModule = [[EXScopedFontLoader alloc] init];
84  [moduleRegistry registerExportedModule:fontModule];
85#endif
86
87#if __has_include(<EXSensors/EXSensorsManager.h>)
88  EXSensorsManagerBinding *sensorsManagerBinding = [[EXSensorsManagerBinding alloc] initWithScopeKey:scopeKey andKernelService:kernelServices[EX_UNVERSIONED(@"EXSensorManager")]];
89  [moduleRegistry registerInternalModule:sensorsManagerBinding];
90#endif
91
92  EXScopedReactNativeAdapter *reactNativeAdapter = [[EXScopedReactNativeAdapter alloc] init];
93  [moduleRegistry registerInternalModule:reactNativeAdapter];
94
95  EXExpoUserNotificationCenterProxy *userNotificationCenter = [[EXExpoUserNotificationCenterProxy alloc] initWithUserNotificationCenter:kernelServices[EX_UNVERSIONED(@"EXUserNotificationCenter")]];
96  [moduleRegistry registerInternalModule:userNotificationCenter];
97
98#if __has_include(<ExpoFileSystem/EXFilePermissionModule.h>)
99  EXScopedFilePermissionModule *filePermissionModule = [[EXScopedFilePermissionModule alloc] init];
100  [moduleRegistry registerInternalModule:filePermissionModule];
101#endif
102
103#if __has_include(<EXSecureStore/EXSecureStore.h>)
104  EXScopedSecureStore *secureStoreModule = [[EXScopedSecureStore alloc] initWithScopeKey:scopeKey andConstantsBinding:constantsBinding];
105  [moduleRegistry registerExportedModule:secureStoreModule];
106#endif
107
108#if __has_include(<ExpoModulesCore/EXPermissionsService.h>)
109  EXScopedPermissions *permissionsModule = [[EXScopedPermissions alloc] initWithScopeKey:scopeKey andConstantsBinding:constantsBinding];
110  [moduleRegistry registerExportedModule:permissionsModule];
111  [moduleRegistry registerInternalModule:permissionsModule];
112#endif
113
114#if __has_include(<EXSegment/EXSegment.h>)
115  EXScopedSegment *segmentModule = [[EXScopedSegment alloc] init];
116  [moduleRegistry registerExportedModule:segmentModule];
117#endif
118
119#if __has_include(<EXBranch/RNBranch.h>)
120  EXScopedBranch *branchModule = [[EXScopedBranch alloc] initWithScopeKey:scopeKey];
121  [moduleRegistry registerInternalModule:branchModule];
122#endif
123
124#if __has_include(<EXLocalAuthentication/EXLocalAuthentication.h>)
125  EXScopedLocalAuthentication *localAuthenticationModule = [[EXScopedLocalAuthentication alloc] init];
126  [moduleRegistry registerExportedModule:localAuthenticationModule];
127#endif
128
129#if __has_include(<EXTaskManager/EXTaskManager.h>)
130  // TODO: Make scoped task manager when adding support for bare React Native
131  EXTaskManager *taskManagerModule = [[EXTaskManager alloc] initWithScopeKey:scopeKey];
132  [moduleRegistry registerInternalModule:taskManagerModule];
133  [moduleRegistry registerExportedModule:taskManagerModule];
134#endif
135
136#if __has_include(<EXErrorRecovery/EXErrorRecoveryModule.h>)
137  EXScopedErrorRecoveryModule *errorRecovery = [[EXScopedErrorRecoveryModule alloc] initWithScopeKey:scopeKey];
138  [moduleRegistry registerExportedModule:errorRecovery];
139#endif
140
141#if __has_include(<EXFirebaseCore/EXFirebaseCore.h>)
142  EXScopedFirebaseCore *firebaseCoreModule = [[EXScopedFirebaseCore alloc] initWithScopeKey:scopeKey manifest:manifest constantsBinding:constantsBinding];
143  [moduleRegistry registerExportedModule:firebaseCoreModule];
144  [moduleRegistry registerInternalModule:firebaseCoreModule];
145#endif
146
147#if __has_include(<EXNotifications/EXNotificationsEmitter.h>)
148  // only override in Expo Go
149  if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) {
150    EXScopedNotificationsEmitter *notificationsEmmitter = [[EXScopedNotificationsEmitter alloc] initWithScopeKey:scopeKey];
151    [moduleRegistry registerExportedModule:notificationsEmmitter];
152  }
153#endif
154
155#if __has_include(<EXNotifications/EXNotificationsHandlerModule.h>)
156  // only override in Expo Go
157  if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) {
158    EXScopedNotificationsHandlerModule *notificationsHandler = [[EXScopedNotificationsHandlerModule alloc] initWithScopeKey:scopeKey];
159    [moduleRegistry registerExportedModule:notificationsHandler];
160  }
161#endif
162
163#if __has_include(<EXNotifications/EXNotificationsHandlerModule.h>)
164  EXScopedNotificationBuilder *notificationsBuilder = [[EXScopedNotificationBuilder alloc] initWithScopeKey:scopeKey
165                                                                                                  andConstantsBinding:constantsBinding];
166  [moduleRegistry registerInternalModule:notificationsBuilder];
167#endif
168
169#if __has_include(<EXNotifications/EXNotificationSchedulerModule.h>)
170  // only override in Expo Go
171  if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) {
172    EXScopedNotificationSchedulerModule *schedulerModule = [[EXScopedNotificationSchedulerModule alloc] initWithScopeKey:scopeKey];
173    [moduleRegistry registerExportedModule:schedulerModule];
174  }
175#endif
176
177#if __has_include(<EXNotifications/EXNotificationPresentationModule.h>)
178  // only override in Expo Go
179  if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) {
180    EXScopedNotificationPresentationModule *notificationPresentationModule = [[EXScopedNotificationPresentationModule alloc] initWithScopeKey:scopeKey];
181    [moduleRegistry registerExportedModule:notificationPresentationModule];
182  }
183#endif
184
185#if __has_include(<EXNotifications/EXNotificationCategoriesModule.h>)
186  // only override in Expo Go
187  if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) {
188    EXScopedNotificationCategoriesModule *scopedCategoriesModule = [[EXScopedNotificationCategoriesModule alloc] initWithScopeKey:scopeKey];
189    [moduleRegistry registerExportedModule:scopedCategoriesModule];
190  }
191  [EXScopedNotificationCategoriesModule maybeMigrateLegacyCategoryIdentifiersForProjectWithExperienceStableLegacyId:experienceStableLegacyId
192                                                                                                 scopeKey:scopeKey
193                                                                                                         isInExpoGo:[params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]];
194#endif
195
196#if __has_include(<EXNotifications/EXServerRegistrationModule.h>)
197  EXScopedServerRegistrationModule *serverRegistrationModule = [[EXScopedServerRegistrationModule alloc] initWithScopeKey:scopeKey];
198  [moduleRegistry registerExportedModule:serverRegistrationModule];
199#endif
200
201  return moduleRegistry;
202}
203
204@end
205