mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-17 15:16:10 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5202cbec96 | ||
![]() |
d7c7e27eaa | ||
![]() |
e9e60bc5c6 | ||
![]() |
a93875884c |
@@ -3,6 +3,8 @@ package cn.reactnative.modules.update;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import com.facebook.react.bridge.Arguments;
|
||||||
|
import com.facebook.react.bridge.WritableMap;
|
||||||
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
@@ -31,11 +33,11 @@ import java.util.HashMap;
|
|||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.BufferedSource;
|
import okio.BufferedSource;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
|
import static cn.reactnative.modules.update.UpdateModule.sendEvent;
|
||||||
/**
|
/**
|
||||||
* Created by tdzl2003 on 3/31/16.
|
* Created by tdzl2003 on 3/31/16.
|
||||||
*/
|
*/
|
||||||
class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
|
class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||||
final int DOWNLOAD_CHUNK_SIZE = 4096;
|
final int DOWNLOAD_CHUNK_SIZE = 4096;
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
@@ -91,11 +93,17 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
|
|||||||
|
|
||||||
long bytesRead = 0;
|
long bytesRead = 0;
|
||||||
long totalRead = 0;
|
long totalRead = 0;
|
||||||
|
double lastProgressValue=0;
|
||||||
while ((bytesRead = source.read(sink.buffer(), DOWNLOAD_CHUNK_SIZE)) != -1) {
|
while ((bytesRead = source.read(sink.buffer(), DOWNLOAD_CHUNK_SIZE)) != -1) {
|
||||||
totalRead += bytesRead;
|
totalRead += bytesRead;
|
||||||
if (UpdateContext.DEBUG) {
|
if (UpdateContext.DEBUG) {
|
||||||
Log.d("RNUpdate", "Progress " + totalRead + "/" + contentLength);
|
Log.d("RNUpdate", "Progress " + totalRead + "/" + contentLength);
|
||||||
}
|
}
|
||||||
|
double progress = Math.round(((double) totalRead * 100) / contentLength);
|
||||||
|
if ((progress != lastProgressValue) || (totalRead == contentLength)) {
|
||||||
|
lastProgressValue = progress;
|
||||||
|
publishProgress(new long[]{(long)progress,totalRead, contentLength});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (totalRead != contentLength) {
|
if (totalRead != contentLength) {
|
||||||
throw new Error("Unexpected eof while reading ppk");
|
throw new Error("Unexpected eof while reading ppk");
|
||||||
@@ -108,6 +116,17 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, Void, Void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(long[]... values) {
|
||||||
|
super.onProgressUpdate(values);
|
||||||
|
WritableMap params = Arguments.createMap();
|
||||||
|
params.putDouble("progress", (values[0][0]));
|
||||||
|
params.putDouble("totalRead", (values[0][1]));
|
||||||
|
params.putDouble("contentLength", (values[0][2]));
|
||||||
|
sendEvent("progress", params);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
private static native byte[] bsdiffPatch(byte[] origin, byte[] patch);
|
private static native byte[] bsdiffPatch(byte[] origin, byte[] patch);
|
||||||
|
@@ -9,11 +9,14 @@ import com.facebook.react.ReactApplication;
|
|||||||
import com.facebook.react.ReactInstanceManager;
|
import com.facebook.react.ReactInstanceManager;
|
||||||
import com.facebook.react.bridge.Promise;
|
import com.facebook.react.bridge.Promise;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
|
import com.facebook.react.bridge.ReactContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
import com.facebook.react.bridge.UiThreadUtil;
|
import com.facebook.react.bridge.UiThreadUtil;
|
||||||
import com.facebook.react.bridge.JSBundleLoader;
|
import com.facebook.react.bridge.JSBundleLoader;
|
||||||
|
import com.facebook.react.bridge.WritableMap;
|
||||||
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -25,10 +28,11 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class UpdateModule extends ReactContextBaseJavaModule{
|
public class UpdateModule extends ReactContextBaseJavaModule{
|
||||||
UpdateContext updateContext;
|
UpdateContext updateContext;
|
||||||
|
public static ReactApplicationContext mContext;
|
||||||
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
|
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
this.updateContext = updateContext;
|
this.updateContext = updateContext;
|
||||||
|
mContext=reactContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateModule(ReactApplicationContext reactContext) {
|
public UpdateModule(ReactApplicationContext reactContext) {
|
||||||
@@ -170,4 +174,10 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 发送事件*/
|
||||||
|
public static void sendEvent(String eventName, WritableMap params) {
|
||||||
|
((ReactContext) mContext).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName,
|
||||||
|
params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,11 +71,14 @@ export async function getApkInfo(fn) {
|
|||||||
export async function getIpaInfo(fn) {
|
export async function getIpaInfo(fn) {
|
||||||
const appInfoParser = new AppInfoParser(fn);
|
const appInfoParser = new AppInfoParser(fn);
|
||||||
const { CFBundleShortVersionString: versionName } = await appInfoParser.parse();
|
const { CFBundleShortVersionString: versionName } = await appInfoParser.parse();
|
||||||
try {
|
let buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/pushy_build_time.txt/);
|
||||||
const buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/pushy_build_time.txt/);
|
if (!buildTimeTxtBuffer) {
|
||||||
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
// Not in root bundle when use `use_frameworks`
|
||||||
return { versionName, buildTime };
|
buildTimeTxtBuffer = await appInfoParser.parser.getEntry(/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/);
|
||||||
} catch (e) {
|
}
|
||||||
|
if (!buildTimeTxtBuffer) {
|
||||||
throw new Error('Can not get build time for this app.');
|
throw new Error('Can not get build time for this app.');
|
||||||
}
|
}
|
||||||
|
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
|
||||||
|
return { versionName, buildTime };
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "5.5.1",
|
"version": "5.5.2",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@@ -11,6 +11,7 @@ Pod::Spec.new do |s|
|
|||||||
s.authors = package['author']
|
s.authors = package['author']
|
||||||
s.homepage = package['homepage']
|
s.homepage = package['homepage']
|
||||||
|
|
||||||
|
s.cocoapods_version = '>= 1.6.0'
|
||||||
s.platform = :ios, "8.0"
|
s.platform = :ios, "8.0"
|
||||||
s.source = { :git => 'https://github.com/reactnativecn/react-native-pushy.git', :tag => '#{s.version}' }
|
s.source = { :git => 'https://github.com/reactnativecn/react-native-pushy.git', :tag => '#{s.version}' }
|
||||||
s.libraries = 'bz2', 'z'
|
s.libraries = 'bz2', 'z'
|
||||||
|
Reference in New Issue
Block a user