@hot-updater/react-native 0.6.7 → 0.8.0

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.
@@ -65,7 +65,7 @@ android {
65
65
  minSdkVersion getExtOrIntegerDefault("minSdkVersion")
66
66
  targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
67
67
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
68
-
68
+ consumerProguardFiles 'proguard-rules.pro'
69
69
  }
70
70
 
71
71
  buildFeatures {
@@ -0,0 +1,15 @@
1
+ # Old Architecture
2
+ # Invoked via reflection, when setting js bundle.
3
+ -keepclassmembers class com.facebook.react.ReactInstanceManager {
4
+ private final ** mBundleLoader;
5
+ }
6
+
7
+ # New Architecture
8
+ # Keep fields accessed via reflection in ReactHost
9
+ -keepclassmembers class com.facebook.react.runtime.ReactHostImpl {
10
+ private final ** mReactHostDelegate;
11
+ }
12
+
13
+ -keepclassmembers class * implements com.facebook.react.runtime.ReactHostDelegate {
14
+ ** jsBundleLoader;
15
+ }
@@ -59,6 +59,11 @@ class HotUpdater : ReactPackage {
59
59
  putString("HotUpdaterBundleURL", bundleURL)
60
60
  apply()
61
61
  }
62
+
63
+ if (bundleURL == null) {
64
+ return
65
+ }
66
+
62
67
  val reactIntegrationManager = ReactIntegrationManager(context)
63
68
 
64
69
  val activity: Activity? = getCurrentActivity(context)
@@ -133,11 +138,11 @@ class HotUpdater : ReactPackage {
133
138
  fun updateBundle(
134
139
  context: Context,
135
140
  bundleId: String,
136
- zipUrl: String,
141
+ zipUrl: String?,
137
142
  progressCallback: ((Double) -> Unit),
138
143
  ): Boolean {
139
144
  Log.d("HotUpdater", "updateBundle bundleId $bundleId zipUrl $zipUrl")
140
- if (zipUrl.isEmpty()) {
145
+ if (zipUrl.isNullOrEmpty()) {
141
146
  setBundleURL(context, null)
142
147
  return true
143
148
  }
@@ -26,7 +26,7 @@ class HotUpdaterModule internal constructor(
26
26
  @ReactMethod
27
27
  override fun updateBundle(
28
28
  bundleId: String,
29
- zipUrl: String,
29
+ zipUrl: String?,
30
30
  promise: Promise,
31
31
  ) {
32
32
  val isSuccess =
@@ -26,7 +26,7 @@ class HotUpdaterModule internal constructor(
26
26
  @ReactMethod
27
27
  override fun updateBundle(
28
28
  bundleId: String,
29
- zipUrl: String,
29
+ zipUrl: String?,
30
30
  promise: Promise,
31
31
  ) {
32
32
  val isSuccess =
@@ -9,7 +9,7 @@ abstract class HotUpdaterSpec internal constructor(
9
9
  ) : ReactContextBaseJavaModule(context) {
10
10
  abstract fun updateBundle(
11
11
  bundleId: String,
12
- zipUrl: String,
12
+ zipUrl: String?,
13
13
  promise: Promise,
14
14
  )
15
15
 
@@ -71,71 +71,66 @@ RCT_EXPORT_MODULE();
71
71
  return success;
72
72
  }
73
73
 
74
- - (BOOL)updateBundle:(NSString *)bundleId zipUrl:(NSURL *)zipUrl {
74
+ - (void)updateBundle:(NSString *)bundleId zipUrl:(NSURL *)zipUrl completion:(void (^)(BOOL success))completion {
75
75
  if (!zipUrl) {
76
- [self setBundleURL:nil];
77
- return YES;
76
+ dispatch_async(dispatch_get_main_queue(), ^{
77
+ [self setBundleURL:nil];
78
+ if (completion) completion(YES);
79
+ });
80
+ return;
78
81
  }
79
-
82
+
80
83
  NSString *basePath = [self stripPrefixFromPath:bundleId path:[zipUrl path]];
81
84
  NSString *path = [self convertFileSystemPathFromBasePath:basePath];
82
-
85
+
83
86
  NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
84
87
  NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
85
-
86
- dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
87
- __block BOOL success = NO;
88
-
88
+
89
89
  NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:zipUrl
90
90
  completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
91
91
  if (error) {
92
92
  NSLog(@"Failed to download data from URL: %@, error: %@", zipUrl, error);
93
- success = NO;
94
- dispatch_semaphore_signal(semaphore);
93
+ if (completion) completion(NO);
95
94
  return;
96
95
  }
97
-
96
+
98
97
  NSFileManager *fileManager = [NSFileManager defaultManager];
99
98
  NSError *folderError;
100
-
99
+
101
100
  // Ensure directory exists
102
101
  if (![fileManager createDirectoryAtPath:[path stringByDeletingLastPathComponent]
103
102
  withIntermediateDirectories:YES
104
103
  attributes:nil
105
104
  error:&folderError]) {
106
105
  NSLog(@"Failed to create folder: %@", folderError);
107
- success = NO;
108
- dispatch_semaphore_signal(semaphore);
106
+ if (completion) completion(NO);
109
107
  return;
110
108
  }
111
-
109
+
112
110
  // Check if file already exists and remove it
113
111
  if ([fileManager fileExistsAtPath:path]) {
114
112
  NSError *removeError;
115
113
  if (![fileManager removeItemAtPath:path error:&removeError]) {
116
114
  NSLog(@"Failed to remove existing file: %@", removeError);
117
- success = NO;
118
- dispatch_semaphore_signal(semaphore);
115
+ if (completion) completion(NO);
119
116
  return;
120
117
  }
121
118
  }
122
-
119
+
123
120
  NSError *moveError;
124
121
  if (![fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:path] error:&moveError]) {
125
122
  NSLog(@"Failed to save data: %@", moveError);
126
- success = NO;
127
- dispatch_semaphore_signal(semaphore);
123
+ if (completion) completion(NO);
128
124
  return;
129
125
  }
130
-
126
+
131
127
  NSString *extractedPath = [path stringByDeletingLastPathComponent];
132
128
  if (![self extractZipFileAtPath:path toDestination:extractedPath]) {
133
129
  NSLog(@"Failed to extract zip file.");
134
- success = NO;
135
- dispatch_semaphore_signal(semaphore);
130
+ if (completion) completion(NO);
136
131
  return;
137
132
  }
138
-
133
+
139
134
  NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:extractedPath];
140
135
  NSString *filename = nil;
141
136
  for (NSString *file in enumerator) {
@@ -144,20 +139,21 @@ RCT_EXPORT_MODULE();
144
139
  break;
145
140
  }
146
141
  }
147
-
142
+
148
143
  if (filename) {
149
144
  NSString *bundlePath = [extractedPath stringByAppendingPathComponent:filename];
150
145
  NSLog(@"Setting bundle URL: %@", bundlePath);
151
- [self setBundleURL:bundlePath];
152
- success = YES;
146
+ dispatch_async(dispatch_get_main_queue(), ^{
147
+ [self setBundleURL:bundlePath];
148
+ if (completion) completion(YES);
149
+ });
153
150
  } else {
154
151
  NSLog(@"index.ios.bundle not found.");
155
- success = NO;
152
+ if (completion) completion(NO);
156
153
  }
157
-
158
- dispatch_semaphore_signal(semaphore);
159
154
  }];
160
-
155
+
156
+
161
157
  // Add observer for progress updates
162
158
  [downloadTask addObserver:self
163
159
  forKeyPath:@"countOfBytesReceived"
@@ -167,11 +163,8 @@ RCT_EXPORT_MODULE();
167
163
  forKeyPath:@"countOfBytesExpectedToReceive"
168
164
  options:NSKeyValueObservingOptionNew
169
165
  context:nil];
170
-
166
+
171
167
  [downloadTask resume];
172
- dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
173
-
174
- return success;
175
168
  }
176
169
 
177
170
  #pragma mark - Progress Updates
@@ -234,9 +227,12 @@ RCT_EXPORT_METHOD(updateBundle:(NSString *)bundleId zipUrl:(NSString *)zipUrlStr
234
227
  if (![zipUrlString isEqualToString:@""]) {
235
228
  zipUrl = [NSURL URLWithString:zipUrlString];
236
229
  }
237
-
238
- BOOL result = [self updateBundle:bundleId zipUrl:zipUrl];
239
- resolve(@[@(result)]);
230
+
231
+ [self updateBundle:bundleId zipUrl:zipUrl completion:^(BOOL success) {
232
+ dispatch_async(dispatch_get_main_queue(), ^{
233
+ resolve(@[@(success)]);
234
+ });
235
+ }];
240
236
  }
241
237
 
242
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/react-native",
3
- "version": "0.6.7",
3
+ "version": "0.8.0",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -78,8 +78,8 @@
78
78
  "react-native-builder-bob": "^0.33.1"
79
79
  },
80
80
  "dependencies": {
81
- "@hot-updater/js": "0.6.7",
82
- "@hot-updater/core": "0.6.7"
81
+ "@hot-updater/js": "0.8.0",
82
+ "@hot-updater/core": "0.8.0"
83
83
  },
84
84
  "scripts": {
85
85
  "build": "rslib build",