提交 8f915974 authored 作者: vipcxj's avatar vipcxj

修复更新进度错误

上级 62e3f3d0
...@@ -80,6 +80,14 @@ public class Updater extends ReactContextBaseJavaModule { ...@@ -80,6 +80,14 @@ public class Updater extends ReactContextBaseJavaModule {
WritableMap event; WritableMap event;
do { do {
int numRead = is.read(buf); int numRead = is.read(buf);
if (numRead <= 0) {
event = Arguments.createMap();
event.putInt("progress", 100);
event.putInt("current", count);
event.putInt("all", length);
emit("Updater/downloaded", event);
break;
}
count += numRead; count += numRead;
int progress = (int) (((float) count / length) * 100); int progress = (int) (((float) count / length) * 100);
if (progress != lastProgress) { if (progress != lastProgress) {
...@@ -90,14 +98,6 @@ public class Updater extends ReactContextBaseJavaModule { ...@@ -90,14 +98,6 @@ public class Updater extends ReactContextBaseJavaModule {
event.putInt("all", length); event.putInt("all", length);
emit("Updater/downloading", event); emit("Updater/downloading", event);
} }
if (numRead <= 0) {
event = Arguments.createMap();
event.putInt("progress", progress);
event.putInt("current", count);
event.putInt("all", length);
emit("Updater/downloaded", event);
break;
}
fos.write(buf, 0, numRead); fos.write(buf, 0, numRead);
} while (!cancel); } while (!cancel);
if (cancel) { if (cancel) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论