1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-07 22:55:13 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Detect android bundle url

This commit is contained in:
sunnylqm
2020-08-13 00:32:07 +08:00
parent 6abb2c7a5d
commit ed7f5ac606
4 changed files with 26 additions and 14 deletions

View File

@@ -123,7 +123,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
WritableMap params = Arguments.createMap();
params.putDouble("received", (values[0][0]));
params.putDouble("total", (values[0][1]));
params.putDouble("hashname", this.hash);
params.putString("hashname", this.hash);
sendEvent("RCTPushyDownloadProgress", params);
}

View File

@@ -23,6 +23,7 @@ public class UpdateContext {
public static boolean DEBUG = false;
private static ReactInstanceManager mReactInstanceManager;
private static boolean isUsingBundleUrl = false;
public UpdateContext(Context context) {
this.context = context;
@@ -67,6 +68,10 @@ public class UpdateContext {
return context.getString(R.string.pushy_build_time);
}
public boolean getIsUsingBundleUrl() {
return isUsingBundleUrl;
}
public interface DownloadFileListener {
void onDownloadCompleted();
void onDownloadFailed(Throwable error);
@@ -184,6 +189,7 @@ public class UpdateContext {
}
public String getBundleUrl(String defaultAssetsUrl) {
isUsingBundleUrl = true;
String currentVersion = getCurrentVersion();
if (currentVersion == null) {
return defaultAssetsUrl;

View File

@@ -46,6 +46,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
constants.put("packageVersion", updateContext.getPackageVersion());
constants.put("currentVersion", updateContext.getCurrentVersion());
constants.put("buildTime", updateContext.getBuildTime());
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
boolean isFirstTime = updateContext.isFirstTime();
constants.put("isFirstTime", isFirstTime);
if (isFirstTime) {
@@ -134,14 +135,14 @@ public class UpdateModule extends ReactContextBaseJavaModule{
}
try {
Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
jsBundleField.setAccessible(true);
jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
} catch (Throwable err) {
JSBundleLoader loader = JSBundleLoader.createFileLoader(UpdateContext.getBundleUrl(application));
Field loadField = instanceManager.getClass().getDeclaredField("mBundleLoader");
loadField.setAccessible(true);
loadField.set(instanceManager, loader);
} catch (Throwable err) {
Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
jsBundleField.setAccessible(true);
jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
}
try {