react-native-update 10.39.1 → 10.40.0-beta.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.
Files changed (37) hide show
  1. package/android/build.gradle +0 -1
  2. package/android/src/main/java/cn/reactnative/modules/update/BundledResourceCopier.java +314 -0
  3. package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +253 -586
  4. package/android/src/main/java/cn/reactnative/modules/update/ReactReloadManager.java +220 -0
  5. package/android/src/main/java/cn/reactnative/modules/update/SafeZipFile.java +9 -3
  6. package/android/src/main/java/cn/reactnative/modules/update/UiThreadRunner.java +36 -0
  7. package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +36 -26
  8. package/android/src/main/java/cn/reactnative/modules/update/UpdateEventEmitter.java +39 -0
  9. package/android/src/main/java/cn/reactnative/modules/update/UpdateFileUtils.java +74 -0
  10. package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleImpl.java +143 -260
  11. package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleSupport.java +63 -0
  12. package/android/src/main/java/cn/reactnative/modules/update/UpdatePackage.java +1 -5
  13. package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +26 -73
  14. package/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +28 -242
  15. package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +89 -135
  16. package/harmony/pushy/src/main/cpp/PushyTurboModule.h +5 -5
  17. package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +7 -7
  18. package/harmony/pushy/src/main/ets/PushyPackage.ets +3 -9
  19. package/harmony/pushy/src/main/ets/PushyPackageCompat.ts +3 -9
  20. package/harmony/pushy/src/main/ets/PushyPackageFactory.ts +14 -0
  21. package/harmony/pushy/src/main/ets/PushyTurboModule.ts +124 -24
  22. package/harmony/pushy/src/main/ets/UpdateContext.ts +92 -70
  23. package/harmony/pushy.har +0 -0
  24. package/ios/Expo/ExpoPushyReactDelegateHandler.swift +6 -26
  25. package/ios/RCTPushy/RCTPushy.mm +315 -259
  26. package/ios/RCTPushy/RCTPushyDownloader.mm +52 -29
  27. package/package.json +1 -1
  28. package/react-native-update.podspec +3 -3
  29. package/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +0 -123
  30. package/ios/ImportReact.h +0 -2
  31. package/ios/RCTPushy/HDiffPatch/HDiffPatch.h +0 -16
  32. package/ios/RCTPushy/HDiffPatch/HDiffPatch.mm +0 -35
  33. package/ios/RCTPushy/RCTPushyManager.h +0 -27
  34. package/ios/RCTPushy/RCTPushyManager.mm +0 -181
  35. package/ios/RCTPushy.xcodeproj/project.pbxproj +0 -479
  36. package/package/harmony/pushy.har +0 -0
  37. package/react-native-update-10.39.0.tgz +0 -0
@@ -16,7 +16,7 @@ import NativePatchCore, {
16
16
  export class UpdateContext {
17
17
  private context: common.UIAbilityContext;
18
18
  private rootDir: string;
19
- private preferences: preferences.Preferences;
19
+ private preferences!: preferences.Preferences;
20
20
  private static DEBUG: boolean = false;
21
21
  private static isUsingBundleUrl: boolean = false;
22
22
 
@@ -121,6 +121,61 @@ export class UpdateContext {
121
121
  this.putNullableString('rolledBackVersion', state.rolledBackVersion);
122
122
  }
123
123
 
124
+ private persistState(
125
+ state: StateCoreResult,
126
+ options: {
127
+ clearExisting?: boolean;
128
+ removeStaleHash?: boolean;
129
+ cleanUp?: boolean;
130
+ } = {},
131
+ ): void {
132
+ if (options.clearExisting) {
133
+ this.preferences.clear();
134
+ }
135
+ this.applyState(state);
136
+ if (options.removeStaleHash && state.staleVersionToDelete) {
137
+ this.preferences.deleteSync(`hash_${state.staleVersionToDelete}`);
138
+ }
139
+ this.preferences.flush();
140
+ if (options.cleanUp) {
141
+ this.cleanUp();
142
+ }
143
+ }
144
+
145
+ private runStateOperation(
146
+ operation: number,
147
+ stringArg: string = '',
148
+ options: {
149
+ removeStaleHash?: boolean;
150
+ cleanUp?: boolean;
151
+ } = {},
152
+ ): StateCoreResult {
153
+ const nextState = NativePatchCore.runStateCore(
154
+ operation,
155
+ this.getStateSnapshot(),
156
+ stringArg,
157
+ );
158
+ this.persistState(nextState, options);
159
+ return nextState;
160
+ }
161
+
162
+ private createTaskParams(
163
+ type: number,
164
+ url: string,
165
+ hash: string,
166
+ ): DownloadTaskParams {
167
+ const params = new DownloadTaskParams();
168
+ params.type = type;
169
+ params.url = url;
170
+ params.hash = hash;
171
+ return params;
172
+ }
173
+
174
+ private async executeTask(params: DownloadTaskParams): Promise<void> {
175
+ const downloadTask = new DownloadTask(this.context);
176
+ await downloadTask.execute(params);
177
+ }
178
+
124
179
  public syncStateWithBinaryVersion(
125
180
  packageVersion: string,
126
181
  buildTime: string,
@@ -136,9 +191,7 @@ export class UpdateContext {
136
191
  }
137
192
 
138
193
  this.cleanUp();
139
- this.preferences.clear();
140
- this.applyState(nextState);
141
- this.preferences.flush();
194
+ this.persistState(nextState, { clearExisting: true });
142
195
  }
143
196
 
144
197
  public setKv(key: string, value: string): void {
@@ -163,48 +216,32 @@ export class UpdateContext {
163
216
  return;
164
217
  }
165
218
 
166
- const nextState = NativePatchCore.runStateCore(
167
- STATE_OP_MARK_SUCCESS,
168
- this.getStateSnapshot(),
169
- );
170
- this.applyState(nextState);
171
- if (nextState.staleVersionToDelete) {
172
- this.preferences.deleteSync(`hash_${nextState.staleVersionToDelete}`);
173
- }
174
- this.preferences.flush();
175
- this.cleanUp();
219
+ this.runStateOperation(STATE_OP_MARK_SUCCESS, '', {
220
+ removeStaleHash: true,
221
+ cleanUp: true,
222
+ });
176
223
  }
177
224
 
178
225
  public clearFirstTime(): void {
179
- const nextState = NativePatchCore.runStateCore(
180
- STATE_OP_CLEAR_FIRST_TIME,
181
- this.getStateSnapshot(),
182
- );
183
- this.applyState(nextState);
184
- this.preferences.flush();
185
- this.cleanUp();
226
+ this.runStateOperation(STATE_OP_CLEAR_FIRST_TIME, '', { cleanUp: true });
186
227
  }
187
228
 
188
229
  public clearRollbackMark(): void {
189
- const nextState = NativePatchCore.runStateCore(
190
- STATE_OP_CLEAR_ROLLBACK_MARK,
191
- this.getStateSnapshot(),
192
- );
193
- this.applyState(nextState);
194
- this.preferences.flush();
195
- this.cleanUp();
230
+ this.runStateOperation(STATE_OP_CLEAR_ROLLBACK_MARK, '', {
231
+ cleanUp: true,
232
+ });
196
233
  }
197
234
 
198
235
  public async downloadFullUpdate(url: string, hash: string): Promise<void> {
199
236
  try {
200
- const params = new DownloadTaskParams();
201
- params.type = DownloadTaskParams.TASK_TYPE_PATCH_FULL;
202
- params.url = url;
203
- params.hash = hash;
237
+ const params = this.createTaskParams(
238
+ DownloadTaskParams.TASK_TYPE_PATCH_FULL,
239
+ url,
240
+ hash,
241
+ );
204
242
  params.targetFile = `${this.rootDir}/${hash}.ppk`;
205
243
  params.unzipDirectory = `${this.rootDir}/${hash}`;
206
- const downloadTask = new DownloadTask(this.context);
207
- await downloadTask.execute(params);
244
+ await this.executeTask(params);
208
245
  } catch (e) {
209
246
  console.error('Failed to download full update:', e);
210
247
  throw e;
@@ -216,14 +253,13 @@ export class UpdateContext {
216
253
  hash: string,
217
254
  fileName: string,
218
255
  ): Promise<void> {
219
- const params = new DownloadTaskParams();
220
- params.type = DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD;
221
- params.url = url;
222
- params.hash = hash;
256
+ const params = this.createTaskParams(
257
+ DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD,
258
+ url,
259
+ hash,
260
+ );
223
261
  params.targetFile = this.rootDir + '/' + fileName;
224
-
225
- const downloadTask = new DownloadTask(this.context);
226
- await downloadTask.execute(params);
262
+ await this.executeTask(params);
227
263
  }
228
264
 
229
265
  public async downloadPatchFromPpk(
@@ -231,17 +267,16 @@ export class UpdateContext {
231
267
  hash: string,
232
268
  originHash: string,
233
269
  ): Promise<void> {
234
- const params = new DownloadTaskParams();
235
- params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
236
- params.url = url;
237
- params.hash = hash;
270
+ const params = this.createTaskParams(
271
+ DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK,
272
+ url,
273
+ hash,
274
+ );
238
275
  params.originHash = originHash;
239
276
  params.targetFile = `${this.rootDir}/${originHash}_${hash}.ppk.patch`;
240
277
  params.unzipDirectory = `${this.rootDir}/${hash}`;
241
278
  params.originDirectory = `${this.rootDir}/${params.originHash}`;
242
-
243
- const downloadTask = new DownloadTask(this.context);
244
- await downloadTask.execute(params);
279
+ await this.executeTask(params);
245
280
  }
246
281
 
247
282
  public async downloadPatchFromPackage(
@@ -249,15 +284,14 @@ export class UpdateContext {
249
284
  hash: string,
250
285
  ): Promise<void> {
251
286
  try {
252
- const params = new DownloadTaskParams();
253
- params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APP;
254
- params.url = url;
255
- params.hash = hash;
287
+ const params = this.createTaskParams(
288
+ DownloadTaskParams.TASK_TYPE_PATCH_FROM_APP,
289
+ url,
290
+ hash,
291
+ );
256
292
  params.targetFile = `${this.rootDir}/${hash}.app.patch`;
257
293
  params.unzipDirectory = `${this.rootDir}/${hash}`;
258
-
259
- const downloadTask = new DownloadTask(this.context);
260
- return await downloadTask.execute(params);
294
+ return await this.executeTask(params);
261
295
  } catch (e) {
262
296
  console.error('Failed to download package patch:', e);
263
297
  throw e;
@@ -271,13 +305,7 @@ export class UpdateContext {
271
305
  throw Error(`Bundle version ${hash} not found.`);
272
306
  }
273
307
 
274
- const nextState = NativePatchCore.runStateCore(
275
- STATE_OP_SWITCH_VERSION,
276
- this.getStateSnapshot(),
277
- hash,
278
- );
279
- this.applyState(nextState);
280
- this.preferences.flush();
308
+ this.runStateOperation(STATE_OP_SWITCH_VERSION, hash);
281
309
  } catch (e) {
282
310
  console.error('Failed to switch version:', e);
283
311
  throw e;
@@ -294,8 +322,7 @@ export class UpdateContext {
294
322
  false,
295
323
  );
296
324
  if (launchState.didRollback || launchState.consumedFirstTime) {
297
- this.applyState(launchState);
298
- this.preferences.flush();
325
+ this.persistState(launchState);
299
326
  }
300
327
 
301
328
  let version = launchState.loadVersion || '';
@@ -321,12 +348,7 @@ export class UpdateContext {
321
348
  }
322
349
 
323
350
  private rollBack(): string {
324
- const nextState = NativePatchCore.runStateCore(
325
- STATE_OP_ROLLBACK,
326
- this.getStateSnapshot(),
327
- );
328
- this.applyState(nextState);
329
- this.preferences.flush();
351
+ const nextState = this.runStateOperation(STATE_OP_ROLLBACK);
330
352
  return nextState.currentVersion || '';
331
353
  }
332
354
 
package/harmony/pushy.har CHANGED
Binary file
@@ -2,39 +2,19 @@ import ExpoModulesCore
2
2
  import React
3
3
 
4
4
  public final class ExpoPushyReactDelegateHandler: ExpoReactDelegateHandler {
5
+ private func resolvedBundleURL() -> URL? {
6
+ RCTPushy.bundleURL()
7
+ }
5
8
 
6
9
  #if EXPO_SUPPORTS_BUNDLEURL
7
- // This code block compiles only if EXPO_SUPPORTS_BUNDLEURL is defined
8
- // For expo-modules-core >= 1.12.0
9
-
10
- // Override bundleURL, which is the primary mechanism for these versions.
11
- // Expo's default createBridge implementation should respect this.
12
10
  override public func bundleURL(reactDelegate: ExpoReactDelegate) -> URL? {
13
- let bundleURL = RCTPushy.bundleURL()
14
- print("PushyHandler: Using bundleURL: \(bundleURL?.absoluteString ?? "nil")")
15
- return bundleURL
11
+ resolvedBundleURL()
16
12
  }
17
13
 
18
- // No createBridge override needed here, rely on default behavior using the bundleURL override.
19
-
20
14
  #else
21
- // This code block compiles only if EXPO_SUPPORTS_BUNDLEURL is NOT defined
22
- // For expo-modules-core < 1.12.0
23
-
24
- // No bundleURL override possible here.
25
-
26
- // createBridge is the mechanism to customize the URL here.
27
- // We completely override it and do not call super.
28
15
  override public func createBridge(reactDelegate: ExpoReactDelegate, bridgeDelegate: RCTBridgeDelegate, launchOptions: [AnyHashable: Any]?) -> RCTBridge? {
29
- let bundleURL = RCTPushy.bundleURL()
30
- // Print the URL being provided to the initializer
31
- print("PushyHandler: createBridge bundleURL: \(bundleURL?.absoluteString ?? "nil")")
32
-
33
- // Directly create the bridge using the bundleURL initializer.
34
- // Pass nil for moduleProvider, assuming default behavior is sufficient.
35
- // WARNING: If bundleURL is nil, this initialization might fail silently or crash.
36
- return RCTBridge(bundleURL: bundleURL, moduleProvider: nil, launchOptions: launchOptions)
16
+ RCTBridge(bundleURL: resolvedBundleURL(), moduleProvider: nil, launchOptions: launchOptions)
37
17
  }
38
18
 
39
- #endif // EXPO_SUPPORTS_BUNDLEURL
19
+ #endif
40
20
  }