@hot-updater/react-native 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/HotUpdater.podspec +1 -2
  2. package/android/build.gradle +16 -3
  3. package/android/generated/java/com/hotupdater/NativeHotUpdaterSpec.java +54 -0
  4. package/android/generated/jni/CMakeLists.txt +36 -0
  5. package/android/generated/jni/HotUpdaterSpec-generated.cpp +56 -0
  6. package/android/generated/jni/HotUpdaterSpec.h +31 -0
  7. package/android/generated/jni/react/renderer/components/HotUpdaterSpec/HotUpdaterSpecJSI-generated.cpp +57 -0
  8. package/android/generated/jni/react/renderer/components/HotUpdaterSpec/HotUpdaterSpecJSI.h +103 -0
  9. package/android/react-native-helpers.gradle +42 -0
  10. package/android/src/main/java/com/hotupdater/HotUpdater.kt +151 -240
  11. package/android/src/main/java/com/hotupdater/HotUpdaterModule.kt +52 -40
  12. package/android/src/main/java/com/hotupdater/HotUpdaterPackage.kt +25 -24
  13. package/android/src/main/java/com/hotupdater/ReactIntegrationManagerBase.kt +34 -0
  14. package/android/src/newarch/HotUpdaterSpec.kt +3 -2
  15. package/android/src/newarch/ReactIntegrationManager.kt +46 -0
  16. package/android/src/oldarch/HotUpdaterSpec.kt +12 -8
  17. package/android/src/oldarch/ReactIntegrationManager.kt +41 -0
  18. package/dist/index.d.mts +71 -0
  19. package/dist/index.d.ts +43 -52
  20. package/dist/index.js +2366 -139
  21. package/dist/index.mjs +2411 -0
  22. package/ios/HotUpdater/HotUpdater.h +8 -4
  23. package/ios/HotUpdater/HotUpdater.mm +167 -116
  24. package/ios/generated/HotUpdaterSpec/HotUpdaterSpec-generated.mm +67 -0
  25. package/ios/generated/HotUpdaterSpec/HotUpdaterSpec.h +67 -0
  26. package/ios/generated/HotUpdaterSpecJSI-generated.cpp +57 -0
  27. package/ios/generated/HotUpdaterSpecJSI.h +103 -0
  28. package/package.json +26 -10
  29. package/react-native.config.js +12 -0
  30. package/src/const.ts +1 -0
  31. package/src/ensureBundles.ts +21 -0
  32. package/src/global.d.ts +3 -0
  33. package/src/index.ts +27 -5
  34. package/src/init.tsx +25 -7
  35. package/src/native.ts +50 -42
  36. package/src/specs/{NativeHotUpdaterModule.ts → NativeHotUpdater.ts} +6 -7
  37. package/src/store.ts +48 -0
  38. package/dist/index.cjs +0 -220
  39. package/dist/index.d.cts +0 -80
  40. package/src/checkForUpdate.test.ts +0 -517
  41. package/src/checkForUpdate.ts +0 -111
  42. package/src/utils.ts +0 -2
@@ -1,9 +1,13 @@
1
- #import <React/RCTBridgeModule.h>
2
-
1
+ #import <React/RCTEventEmitter.h>
3
2
  #import <React/RCTBundleURLProvider.h>
4
- #import <React/RCTReloadCommand.h>
5
3
 
6
- @interface HotUpdater : NSObject <RCTBridgeModule>
4
+ #ifdef RCT_NEW_ARCH_ENABLED
5
+ #import "HotUpdaterSpec.h"
6
+ @interface HotUpdater : RCTEventEmitter <NativeHotUpdaterSpec>
7
+ #else
8
+ #import <React/RCTBridgeModule.h>
9
+ @interface HotUpdater : RCTEventEmitter <RCTBridgeModule>
10
+ #endif // RCT_NEW_ARCH_ENABLED
7
11
 
8
12
  + (NSURL *)bundleURL;
9
13
 
@@ -1,42 +1,22 @@
1
1
  #import "HotUpdater.h"
2
+ #import <React/RCTReloadCommand.h>
2
3
  #import <SSZipArchive/SSZipArchive.h>
3
4
 
4
- @implementation HotUpdater
5
+ @implementation HotUpdater {
6
+ bool hasListeners;
7
+ }
5
8
 
6
9
  RCT_EXPORT_MODULE();
7
10
 
8
11
  #pragma mark - Bundle URL Management
9
12
 
10
- + (void)reload {
11
- NSLog(@"HotUpdater requested a reload");
12
- dispatch_async(dispatch_get_main_queue(), ^{
13
- RCTTriggerReloadCommandListeners(@"HotUpdater requested a reload");
14
- });
15
- }
16
-
17
- + (void)setBundleVersion:(NSString*)bundleVersion {
18
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
19
- [defaults setObject:bundleVersion forKey:@"HotUpdaterBundleVersion"];
20
- [defaults synchronize];
21
- }
22
-
23
- + (NSString *)getAppVersion {
24
- NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
25
- return appVersion;
26
- }
27
13
 
28
- + (NSNumber *)getBundleVersion {
29
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
30
- NSString *bundleVersion = [defaults objectForKey:@"HotUpdaterBundleVersion"];
31
-
32
- if (bundleVersion) {
33
- return @([bundleVersion integerValue]);
34
- }
35
-
36
- return @(-1);
14
+ - (NSString *)getAppVersion {
15
+ NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
16
+ return appVersion;
37
17
  }
38
18
 
39
- + (void)setBundleURL:(NSString *)localPath {
19
+ - (void)setBundleURL:(NSString *)localPath {
40
20
  NSLog(@"Setting bundle URL: %@", localPath);
41
21
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
42
22
  [defaults setObject:localPath forKey:@"HotUpdaterBundleURL"];
@@ -58,45 +38,31 @@ RCT_EXPORT_MODULE();
58
38
 
59
39
  + (NSURL *)fallbackURL {
60
40
  // This Support React Native 0.72.6
61
- #if DEBUG
62
- return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
63
- #else
64
- return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
65
- #endif
41
+ #if DEBUG
42
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
43
+ #else
44
+ return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
45
+ #endif
66
46
  }
67
47
 
68
48
  + (NSURL *)bundleURL {
69
49
  return [self cachedURLFromBundle] ?: [self fallbackURL];
70
50
  }
71
51
 
72
- + (void)initializeOnAppUpdate {
73
- NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
74
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
75
- NSString *savedVersion = [defaults stringForKey:@"HotUpdaterAppVersion"];
76
-
77
- if (![currentVersion isEqualToString:savedVersion]) {
78
- [defaults removeObjectForKey:@"HotUpdaterBundleURL"];
79
- [defaults removeObjectForKey:@"HotUpdaterBundleVersion"];
80
-
81
- [defaults setObject:currentVersion forKey:@"HotUpdaterAppVersion"];
82
- [defaults synchronize];
83
- }
84
- }
85
-
86
52
  #pragma mark - Utility Methods
87
53
 
88
- + (NSString *)convertFileSystemPathFromBasePath:(NSString *)basePath {
54
+ - (NSString *)convertFileSystemPathFromBasePath:(NSString *)basePath {
89
55
  return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:basePath];
90
56
  }
91
57
 
92
- + (NSString *)stripPrefixFromPath:(NSString *)prefix path:(NSString *)path {
58
+ - (NSString *)stripPrefixFromPath:(NSString *)prefix path:(NSString *)path {
93
59
  if ([path hasPrefix:[NSString stringWithFormat:@"/%@/", prefix]]) {
94
60
  return [path stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"/%@/", prefix] withString:@""];
95
61
  }
96
62
  return path;
97
63
  }
98
64
 
99
- + (BOOL)extractZipFileAtPath:(NSString *)filePath toDestination:(NSString *)destinationPath {
65
+ - (BOOL)extractZipFileAtPath:(NSString *)filePath toDestination:(NSString *)destinationPath {
100
66
  NSError *error = nil;
101
67
  BOOL success = [SSZipArchive unzipFileAtPath:filePath toDestination:destinationPath overwrite:YES password:nil error:&error];
102
68
  if (!success) {
@@ -105,97 +71,182 @@ RCT_EXPORT_MODULE();
105
71
  return success;
106
72
  }
107
73
 
108
- + (BOOL)updateBundle:(NSString *)prefix url:(NSURL *)url {
109
- if (url == nil) {
110
- [self setBundleVersion:nil];
74
+ - (BOOL)updateBundle:(NSString *)bundleId zipUrl:(NSURL *)zipUrl {
75
+ if (!zipUrl) {
111
76
  [self setBundleURL:nil];
112
77
  return YES;
113
78
  }
114
- NSString *basePath = [self stripPrefixFromPath:prefix path:[url path]];
79
+
80
+ NSString *basePath = [self stripPrefixFromPath:bundleId path:[zipUrl path]];
115
81
  NSString *path = [self convertFileSystemPathFromBasePath:basePath];
82
+
83
+ NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
84
+ NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
85
+
86
+ dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
87
+ __block BOOL success = NO;
88
+
89
+ NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:zipUrl
90
+ completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
91
+ if (error) {
92
+ NSLog(@"Failed to download data from URL: %@, error: %@", zipUrl, error);
93
+ success = NO;
94
+ dispatch_semaphore_signal(semaphore);
95
+ return;
96
+ }
97
+
98
+ NSFileManager *fileManager = [NSFileManager defaultManager];
99
+ NSError *folderError;
100
+
101
+ // Ensure directory exists
102
+ if (![fileManager createDirectoryAtPath:[path stringByDeletingLastPathComponent]
103
+ withIntermediateDirectories:YES
104
+ attributes:nil
105
+ error:&folderError]) {
106
+ NSLog(@"Failed to create folder: %@", folderError);
107
+ success = NO;
108
+ dispatch_semaphore_signal(semaphore);
109
+ return;
110
+ }
111
+
112
+ // Check if file already exists and remove it
113
+ if ([fileManager fileExistsAtPath:path]) {
114
+ NSError *removeError;
115
+ if (![fileManager removeItemAtPath:path error:&removeError]) {
116
+ NSLog(@"Failed to remove existing file: %@", removeError);
117
+ success = NO;
118
+ dispatch_semaphore_signal(semaphore);
119
+ return;
120
+ }
121
+ }
122
+
123
+ NSError *moveError;
124
+ if (![fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:path] error:&moveError]) {
125
+ NSLog(@"Failed to save data: %@", moveError);
126
+ success = NO;
127
+ dispatch_semaphore_signal(semaphore);
128
+ return;
129
+ }
130
+
131
+ NSString *extractedPath = [path stringByDeletingLastPathComponent];
132
+ if (![self extractZipFileAtPath:path toDestination:extractedPath]) {
133
+ NSLog(@"Failed to extract zip file.");
134
+ success = NO;
135
+ dispatch_semaphore_signal(semaphore);
136
+ return;
137
+ }
138
+
139
+ NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:extractedPath];
140
+ NSString *filename = nil;
141
+ for (NSString *file in enumerator) {
142
+ if ([file isEqualToString:@"index.ios.bundle"]) {
143
+ filename = file;
144
+ break;
145
+ }
146
+ }
147
+
148
+ if (filename) {
149
+ NSString *bundlePath = [extractedPath stringByAppendingPathComponent:filename];
150
+ NSLog(@"Setting bundle URL: %@", bundlePath);
151
+ [self setBundleURL:bundlePath];
152
+ success = YES;
153
+ } else {
154
+ NSLog(@"index.ios.bundle not found.");
155
+ success = NO;
156
+ }
157
+
158
+ dispatch_semaphore_signal(semaphore);
159
+ }];
160
+
161
+ // Add observer for progress updates
162
+ [downloadTask addObserver:self
163
+ forKeyPath:@"countOfBytesReceived"
164
+ options:NSKeyValueObservingOptionNew
165
+ context:nil];
166
+ [downloadTask addObserver:self
167
+ forKeyPath:@"countOfBytesExpectedToReceive"
168
+ options:NSKeyValueObservingOptionNew
169
+ context:nil];
170
+
171
+ [downloadTask resume];
172
+ dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
173
+
174
+ return success;
175
+ }
116
176
 
117
- NSData *data = [NSData dataWithContentsOfURL:url];
118
- if (!data) {
119
- NSLog(@"Failed to download data from URL: %@", url);
120
- return NO;
121
- }
177
+ #pragma mark - Progress Updates
122
178
 
123
- NSFileManager *fileManager = [NSFileManager defaultManager];
124
- NSError *folderError;
125
- if (![fileManager createDirectoryAtPath:[path stringByDeletingLastPathComponent]
126
- withIntermediateDirectories:YES
127
- attributes:nil
128
- error:&folderError]) {
129
- NSLog(@"Failed to create folder: %@", folderError);
130
- return NO;
179
+ - (void)observeValueForKeyPath:(NSString *)keyPath
180
+ ofObject:(id)object
181
+ change:(NSDictionary<NSKeyValueChangeKey, id> *)change
182
+ context:(void *)context {
183
+ if ([keyPath isEqualToString:@"countOfBytesReceived"] || [keyPath isEqualToString:@"countOfBytesExpectedToReceive"]) {
184
+ NSURLSessionDownloadTask *task = (NSURLSessionDownloadTask *)object;
185
+
186
+ if (task.countOfBytesExpectedToReceive > 0) {
187
+ double progress = (double)task.countOfBytesReceived / (double)task.countOfBytesExpectedToReceive;
188
+
189
+ // Send progress to React Native
190
+ [self sendEventWithName:@"onProgress" body:@{@"progress": @(progress)}];
191
+ }
131
192
  }
193
+ }
132
194
 
133
- NSError *error;
134
- [data writeToFile:path options:NSDataWritingAtomic error:&error];
135
- if (error) {
136
- NSLog(@"Failed to save data: %@", error);
137
- return NO;
138
- }
139
195
 
140
- NSString *extractedPath = [path stringByDeletingLastPathComponent];
141
- if (![self extractZipFileAtPath:path toDestination:extractedPath]) {
142
- NSLog(@"Failed to extract zip file.");
143
- return NO;
144
- }
196
+ #pragma mark - React Native Events
197
+ - (NSArray<NSString *> *)supportedEvents {
198
+ return @[@"onProgress"];
199
+ }
145
200
 
146
- NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:extractedPath];
147
- NSString *filename = nil;
148
- for (NSString *file in enumerator) {
149
- if ([file isEqualToString:@"index.ios.bundle.js"]) {
150
- filename = file;
151
- break;
152
- }
153
- }
201
+ - (void)startObserving
202
+ {
203
+ hasListeners = YES;
204
+ }
154
205
 
155
- if (filename) {
156
- NSString *bundlePath = [extractedPath stringByAppendingPathComponent:filename];
157
- NSLog(@"Setting bundle URL: %@", bundlePath);
158
- [self setBundleURL:bundlePath];
159
- } else {
160
- NSLog(@"index.ios.bundle.js not found.");
161
- return NO;
162
- }
206
+ - (void)stopObserving
207
+ {
208
+ hasListeners = NO;
209
+ }
163
210
 
164
- [self setBundleVersion:prefix];
165
- NSLog(@"Downloaded and extracted file successfully.");
166
211
 
167
- return YES;
212
+ - (void)sendEventWithName:(NSString * _Nonnull)name result:(NSDictionary *)result {
213
+ [self sendEventWithName:name body:result];
168
214
  }
169
215
 
170
- #pragma mark - React Native Exports
171
216
 
172
- RCT_EXPORT_METHOD(initializeOnAppUpdate) {
173
- [HotUpdater initializeOnAppUpdate];
174
- }
217
+ #pragma mark - React Native Exports
175
218
 
176
219
  RCT_EXPORT_METHOD(reload) {
177
- [HotUpdater reload];
220
+ NSLog(@"HotUpdater requested a reload");
221
+ dispatch_async(dispatch_get_main_queue(), ^{
222
+ RCTTriggerReloadCommandListeners(@"HotUpdater requested a reload");
223
+ });
178
224
  }
179
225
 
180
- RCT_EXPORT_METHOD(getBundleVersion:(RCTResponseSenderBlock)callback) {
181
- NSNumber *bundleVersion = [HotUpdater getBundleVersion];
182
- callback(@[bundleVersion]);
226
+ RCT_EXPORT_METHOD(getAppVersion:(RCTPromiseResolveBlock)resolve
227
+ reject:(RCTPromiseRejectBlock)reject) {
228
+ NSString *version = [self getAppVersion];
229
+ resolve(version ?: [NSNull null]);
183
230
  }
184
231
 
185
-
186
- RCT_EXPORT_METHOD(getAppVersion:(RCTResponseSenderBlock)callback) {
187
- NSString *version = [HotUpdater getAppVersion];
188
- callback(@[version ?: [NSNull null]]);
232
+ RCT_EXPORT_METHOD(updateBundle:(NSString *)bundleId zipUrl:(NSString *)zipUrlString resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
233
+ NSURL *zipUrl = nil;
234
+ if (![zipUrlString isEqualToString:@""]) {
235
+ zipUrl = [NSURL URLWithString:zipUrlString];
236
+ }
237
+
238
+ BOOL result = [self updateBundle:bundleId zipUrl:zipUrl];
239
+ resolve(@[@(result)]);
189
240
  }
190
241
 
191
- RCT_EXPORT_METHOD(updateBundle:(NSString *)prefix downloadUrl:(NSString *)urlString callback:(RCTResponseSenderBlock)callback) {
192
- NSURL *url = nil;
193
- if (urlString != nil) {
194
- url = [NSURL URLWithString:urlString];
195
- }
196
242
 
197
- BOOL result = [HotUpdater updateBundle:prefix url:url];
198
- callback(@[@(result)]);
243
+ // Don't compile this code when we build for the old architecture.
244
+ #ifdef RCT_NEW_ARCH_ENABLED
245
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
246
+ (const facebook::react::ObjCTurboModule::InitParams &)params
247
+ {
248
+ return std::make_shared<facebook::react::NativeHotUpdaterSpecJSI>(params);
199
249
  }
250
+ #endif
200
251
 
201
252
  @end
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleObjCpp
8
+ *
9
+ * We create an umbrella header (and corresponding implementation) here since
10
+ * Cxx compilation in BUCK has a limitation: source-code producing genrule()s
11
+ * must have a single output. More files => more genrule()s => slower builds.
12
+ */
13
+
14
+ #import "HotUpdaterSpec.h"
15
+
16
+
17
+ @implementation NativeHotUpdaterSpecBase
18
+
19
+
20
+ - (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
21
+ {
22
+ _eventEmitterCallback = std::move(eventEmitterCallbackWrapper->_eventEmitterCallback);
23
+ }
24
+ @end
25
+
26
+
27
+ namespace facebook::react {
28
+
29
+ static facebook::jsi::Value __hostFunction_NativeHotUpdaterSpecJSI_reload(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
30
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "reload", @selector(reload), args, count);
31
+ }
32
+
33
+ static facebook::jsi::Value __hostFunction_NativeHotUpdaterSpecJSI_updateBundle(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
34
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "updateBundle", @selector(updateBundle:zipUrl:resolve:reject:), args, count);
35
+ }
36
+
37
+ static facebook::jsi::Value __hostFunction_NativeHotUpdaterSpecJSI_getAppVersion(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
38
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "getAppVersion", @selector(getAppVersion:reject:), args, count);
39
+ }
40
+
41
+ static facebook::jsi::Value __hostFunction_NativeHotUpdaterSpecJSI_addListener(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
42
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "addListener", @selector(addListener:), args, count);
43
+ }
44
+
45
+ static facebook::jsi::Value __hostFunction_NativeHotUpdaterSpecJSI_removeListeners(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
46
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "removeListeners", @selector(removeListeners:), args, count);
47
+ }
48
+
49
+ NativeHotUpdaterSpecJSI::NativeHotUpdaterSpecJSI(const ObjCTurboModule::InitParams &params)
50
+ : ObjCTurboModule(params) {
51
+
52
+ methodMap_["reload"] = MethodMetadata {0, __hostFunction_NativeHotUpdaterSpecJSI_reload};
53
+
54
+
55
+ methodMap_["updateBundle"] = MethodMetadata {2, __hostFunction_NativeHotUpdaterSpecJSI_updateBundle};
56
+
57
+
58
+ methodMap_["getAppVersion"] = MethodMetadata {0, __hostFunction_NativeHotUpdaterSpecJSI_getAppVersion};
59
+
60
+
61
+ methodMap_["addListener"] = MethodMetadata {1, __hostFunction_NativeHotUpdaterSpecJSI_addListener};
62
+
63
+
64
+ methodMap_["removeListeners"] = MethodMetadata {1, __hostFunction_NativeHotUpdaterSpecJSI_removeListeners};
65
+
66
+ }
67
+ } // namespace facebook::react
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleObjCpp
8
+ *
9
+ * We create an umbrella header (and corresponding implementation) here since
10
+ * Cxx compilation in BUCK has a limitation: source-code producing genrule()s
11
+ * must have a single output. More files => more genrule()s => slower builds.
12
+ */
13
+
14
+ #ifndef __cplusplus
15
+ #error This file must be compiled as Obj-C++. If you are importing it, you must change your file extension to .mm.
16
+ #endif
17
+
18
+ // Avoid multiple includes of HotUpdaterSpec symbols
19
+ #ifndef HotUpdaterSpec_H
20
+ #define HotUpdaterSpec_H
21
+
22
+ #import <Foundation/Foundation.h>
23
+ #import <RCTRequired/RCTRequired.h>
24
+ #import <RCTTypeSafety/RCTConvertHelpers.h>
25
+ #import <RCTTypeSafety/RCTTypedModuleConstants.h>
26
+ #import <React/RCTBridgeModule.h>
27
+ #import <React/RCTCxxConvert.h>
28
+ #import <React/RCTManagedPointer.h>
29
+ #import <ReactCommon/RCTTurboModule.h>
30
+ #import <optional>
31
+ #import <vector>
32
+
33
+
34
+ @protocol NativeHotUpdaterSpec <RCTBridgeModule, RCTTurboModule>
35
+
36
+ - (void)reload;
37
+ - (void)updateBundle:(NSString *)bundleId
38
+ zipUrl:(NSString *)zipUrl
39
+ resolve:(RCTPromiseResolveBlock)resolve
40
+ reject:(RCTPromiseRejectBlock)reject;
41
+ - (void)getAppVersion:(RCTPromiseResolveBlock)resolve
42
+ reject:(RCTPromiseRejectBlock)reject;
43
+ - (void)addListener:(NSString *)eventName;
44
+ - (void)removeListeners:(double)count;
45
+
46
+ @end
47
+
48
+ @interface NativeHotUpdaterSpecBase : NSObject {
49
+ @protected
50
+ facebook::react::EventEmitterCallback _eventEmitterCallback;
51
+ }
52
+ - (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper;
53
+
54
+
55
+ @end
56
+
57
+ namespace facebook::react {
58
+ /**
59
+ * ObjC++ class for module 'NativeHotUpdater'
60
+ */
61
+ class JSI_EXPORT NativeHotUpdaterSpecJSI : public ObjCTurboModule {
62
+ public:
63
+ NativeHotUpdaterSpecJSI(const ObjCTurboModule::InitParams &params);
64
+ };
65
+ } // namespace facebook::react
66
+
67
+ #endif // HotUpdaterSpec_H
@@ -0,0 +1,57 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleCpp.js
8
+ */
9
+
10
+ #include "HotUpdaterSpecJSI.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ static jsi::Value __hostFunction_NativeHotUpdaterCxxSpecJSI_reload(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
+ static_cast<NativeHotUpdaterCxxSpecJSI *>(&turboModule)->reload(
16
+ rt
17
+ );
18
+ return jsi::Value::undefined();
19
+ }
20
+ static jsi::Value __hostFunction_NativeHotUpdaterCxxSpecJSI_updateBundle(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
21
+ return static_cast<NativeHotUpdaterCxxSpecJSI *>(&turboModule)->updateBundle(
22
+ rt,
23
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
24
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt)
25
+ );
26
+ }
27
+ static jsi::Value __hostFunction_NativeHotUpdaterCxxSpecJSI_getAppVersion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
28
+ return static_cast<NativeHotUpdaterCxxSpecJSI *>(&turboModule)->getAppVersion(
29
+ rt
30
+ );
31
+ }
32
+ static jsi::Value __hostFunction_NativeHotUpdaterCxxSpecJSI_addListener(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
33
+ static_cast<NativeHotUpdaterCxxSpecJSI *>(&turboModule)->addListener(
34
+ rt,
35
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
36
+ );
37
+ return jsi::Value::undefined();
38
+ }
39
+ static jsi::Value __hostFunction_NativeHotUpdaterCxxSpecJSI_removeListeners(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
40
+ static_cast<NativeHotUpdaterCxxSpecJSI *>(&turboModule)->removeListeners(
41
+ rt,
42
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber()
43
+ );
44
+ return jsi::Value::undefined();
45
+ }
46
+
47
+ NativeHotUpdaterCxxSpecJSI::NativeHotUpdaterCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
48
+ : TurboModule("HotUpdater", jsInvoker) {
49
+ methodMap_["reload"] = MethodMetadata {0, __hostFunction_NativeHotUpdaterCxxSpecJSI_reload};
50
+ methodMap_["updateBundle"] = MethodMetadata {2, __hostFunction_NativeHotUpdaterCxxSpecJSI_updateBundle};
51
+ methodMap_["getAppVersion"] = MethodMetadata {0, __hostFunction_NativeHotUpdaterCxxSpecJSI_getAppVersion};
52
+ methodMap_["addListener"] = MethodMetadata {1, __hostFunction_NativeHotUpdaterCxxSpecJSI_addListener};
53
+ methodMap_["removeListeners"] = MethodMetadata {1, __hostFunction_NativeHotUpdaterCxxSpecJSI_removeListeners};
54
+ }
55
+
56
+
57
+ } // namespace facebook::react
@@ -0,0 +1,103 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+ class JSI_EXPORT NativeHotUpdaterCxxSpecJSI : public TurboModule {
19
+ protected:
20
+ NativeHotUpdaterCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
21
+
22
+ public:
23
+ virtual void reload(jsi::Runtime &rt) = 0;
24
+ virtual jsi::Value updateBundle(jsi::Runtime &rt, jsi::String bundleId, jsi::String zipUrl) = 0;
25
+ virtual jsi::Value getAppVersion(jsi::Runtime &rt) = 0;
26
+ virtual void addListener(jsi::Runtime &rt, jsi::String eventName) = 0;
27
+ virtual void removeListeners(jsi::Runtime &rt, double count) = 0;
28
+
29
+ };
30
+
31
+ template <typename T>
32
+ class JSI_EXPORT NativeHotUpdaterCxxSpec : public TurboModule {
33
+ public:
34
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
35
+ return delegate_.get(rt, propName);
36
+ }
37
+
38
+ static constexpr std::string_view kModuleName = "HotUpdater";
39
+
40
+ protected:
41
+ NativeHotUpdaterCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
42
+ : TurboModule(std::string{NativeHotUpdaterCxxSpec::kModuleName}, jsInvoker),
43
+ delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
44
+
45
+
46
+ private:
47
+ class Delegate : public NativeHotUpdaterCxxSpecJSI {
48
+ public:
49
+ Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
50
+ NativeHotUpdaterCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
51
+
52
+ }
53
+
54
+ void reload(jsi::Runtime &rt) override {
55
+ static_assert(
56
+ bridging::getParameterCount(&T::reload) == 1,
57
+ "Expected reload(...) to have 1 parameters");
58
+
59
+ return bridging::callFromJs<void>(
60
+ rt, &T::reload, jsInvoker_, instance_);
61
+ }
62
+ jsi::Value updateBundle(jsi::Runtime &rt, jsi::String bundleId, jsi::String zipUrl) override {
63
+ static_assert(
64
+ bridging::getParameterCount(&T::updateBundle) == 3,
65
+ "Expected updateBundle(...) to have 3 parameters");
66
+
67
+ return bridging::callFromJs<jsi::Value>(
68
+ rt, &T::updateBundle, jsInvoker_, instance_, std::move(bundleId), std::move(zipUrl));
69
+ }
70
+ jsi::Value getAppVersion(jsi::Runtime &rt) override {
71
+ static_assert(
72
+ bridging::getParameterCount(&T::getAppVersion) == 1,
73
+ "Expected getAppVersion(...) to have 1 parameters");
74
+
75
+ return bridging::callFromJs<jsi::Value>(
76
+ rt, &T::getAppVersion, jsInvoker_, instance_);
77
+ }
78
+ void addListener(jsi::Runtime &rt, jsi::String eventName) override {
79
+ static_assert(
80
+ bridging::getParameterCount(&T::addListener) == 2,
81
+ "Expected addListener(...) to have 2 parameters");
82
+
83
+ return bridging::callFromJs<void>(
84
+ rt, &T::addListener, jsInvoker_, instance_, std::move(eventName));
85
+ }
86
+ void removeListeners(jsi::Runtime &rt, double count) override {
87
+ static_assert(
88
+ bridging::getParameterCount(&T::removeListeners) == 2,
89
+ "Expected removeListeners(...) to have 2 parameters");
90
+
91
+ return bridging::callFromJs<void>(
92
+ rt, &T::removeListeners, jsInvoker_, instance_, std::move(count));
93
+ }
94
+
95
+ private:
96
+ friend class NativeHotUpdaterCxxSpec;
97
+ T *instance_;
98
+ };
99
+
100
+ Delegate delegate_;
101
+ };
102
+
103
+ } // namespace facebook::react