@bravemobile/react-native-code-push 12.4.0 → 12.4.1
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.
- package/README.md +1 -1
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +18 -15
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +4 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressEventDispatcher.java +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -341,19 +341,28 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
|
|
|
341
341
|
try {
|
|
342
342
|
JSONObject mutableUpdatePackage = CodePushUtils.convertReadableToJsonObject(updatePackage);
|
|
343
343
|
mUpdateManager.downloadPackage(mutableUpdatePackage, mCodePush.getAssetsBundleFileName(), new DownloadProgressCallback() {
|
|
344
|
-
private boolean hasScheduledNextFrame = false;
|
|
345
|
-
private DownloadProgress latestDownloadProgress = null;
|
|
344
|
+
private volatile boolean hasScheduledNextFrame = false;
|
|
345
|
+
private volatile DownloadProgress latestDownloadProgress = null;
|
|
346
|
+
private final DownloadProgressEventDispatcher progressEventDispatcher = new DownloadProgressEventDispatcher(
|
|
347
|
+
new DownloadProgressEventDispatcher.EventEmitter() {
|
|
348
|
+
@Override
|
|
349
|
+
public void emit(DownloadProgress downloadProgress) {
|
|
350
|
+
getReactApplicationContext()
|
|
351
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
352
|
+
.emit(CodePushConstants.DOWNLOAD_PROGRESS_EVENT_NAME, downloadProgress.createWritableMap());
|
|
353
|
+
}
|
|
354
|
+
});
|
|
346
355
|
|
|
347
356
|
@Override
|
|
348
357
|
public void call(DownloadProgress downloadProgress) {
|
|
349
|
-
if (!notifyProgress) {
|
|
358
|
+
if (!notifyProgress || downloadProgress == null) {
|
|
350
359
|
return;
|
|
351
360
|
}
|
|
352
361
|
|
|
353
362
|
latestDownloadProgress = downloadProgress;
|
|
354
363
|
// If the download is completed, synchronously send the last event.
|
|
355
|
-
if (
|
|
356
|
-
|
|
364
|
+
if (downloadProgress.isCompleted()) {
|
|
365
|
+
progressEventDispatcher.dispatch(downloadProgress);
|
|
357
366
|
return;
|
|
358
367
|
}
|
|
359
368
|
|
|
@@ -368,22 +377,16 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule {
|
|
|
368
377
|
ReactChoreographer.getInstance().postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, new Choreographer.FrameCallback() {
|
|
369
378
|
@Override
|
|
370
379
|
public void doFrame(long frameTimeNanos) {
|
|
371
|
-
|
|
372
|
-
|
|
380
|
+
try {
|
|
381
|
+
progressEventDispatcher.dispatch(latestDownloadProgress);
|
|
382
|
+
} finally {
|
|
383
|
+
hasScheduledNextFrame = false;
|
|
373
384
|
}
|
|
374
|
-
|
|
375
|
-
hasScheduledNextFrame = false;
|
|
376
385
|
}
|
|
377
386
|
});
|
|
378
387
|
}
|
|
379
388
|
});
|
|
380
389
|
}
|
|
381
|
-
|
|
382
|
-
public void dispatchDownloadProgressEvent() {
|
|
383
|
-
getReactApplicationContext()
|
|
384
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
385
|
-
.emit(CodePushConstants.DOWNLOAD_PROGRESS_EVENT_NAME, latestDownloadProgress.createWritableMap());
|
|
386
|
-
}
|
|
387
390
|
});
|
|
388
391
|
|
|
389
392
|
JSONObject newPackage = mUpdateManager.getPackage(CodePushUtils.tryGetString(updatePackage, CodePushConstants.PACKAGE_HASH_KEY));
|
package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressEventDispatcher.java
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.microsoft.codepush.react;
|
|
2
|
+
|
|
3
|
+
class DownloadProgressEventDispatcher {
|
|
4
|
+
interface EventEmitter {
|
|
5
|
+
void emit(DownloadProgress downloadProgress);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
private final EventEmitter mEventEmitter;
|
|
9
|
+
private long mLastDispatchedBytes = -1;
|
|
10
|
+
|
|
11
|
+
DownloadProgressEventDispatcher(EventEmitter eventEmitter) {
|
|
12
|
+
mEventEmitter = eventEmitter;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
synchronized void dispatch(DownloadProgress downloadProgress) {
|
|
16
|
+
if (downloadProgress == null || downloadProgress.getReceivedBytes() <= mLastDispatchedBytes) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
mEventEmitter.emit(downloadProgress);
|
|
21
|
+
mLastDispatchedBytes = downloadProgress.getReceivedBytes();
|
|
22
|
+
}
|
|
23
|
+
}
|