mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-01 05:43:11 +08:00
Detect android bundle url
This commit is contained in:
@@ -123,7 +123,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|||||||
WritableMap params = Arguments.createMap();
|
WritableMap params = Arguments.createMap();
|
||||||
params.putDouble("received", (values[0][0]));
|
params.putDouble("received", (values[0][0]));
|
||||||
params.putDouble("total", (values[0][1]));
|
params.putDouble("total", (values[0][1]));
|
||||||
params.putDouble("hashname", this.hash);
|
params.putString("hashname", this.hash);
|
||||||
sendEvent("RCTPushyDownloadProgress", params);
|
sendEvent("RCTPushyDownloadProgress", params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class UpdateContext {
|
|||||||
|
|
||||||
public static boolean DEBUG = false;
|
public static boolean DEBUG = false;
|
||||||
private static ReactInstanceManager mReactInstanceManager;
|
private static ReactInstanceManager mReactInstanceManager;
|
||||||
|
private static boolean isUsingBundleUrl = false;
|
||||||
|
|
||||||
public UpdateContext(Context context) {
|
public UpdateContext(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -67,6 +68,10 @@ public class UpdateContext {
|
|||||||
return context.getString(R.string.pushy_build_time);
|
return context.getString(R.string.pushy_build_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getIsUsingBundleUrl() {
|
||||||
|
return isUsingBundleUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public interface DownloadFileListener {
|
public interface DownloadFileListener {
|
||||||
void onDownloadCompleted();
|
void onDownloadCompleted();
|
||||||
void onDownloadFailed(Throwable error);
|
void onDownloadFailed(Throwable error);
|
||||||
@@ -184,6 +189,7 @@ public class UpdateContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getBundleUrl(String defaultAssetsUrl) {
|
public String getBundleUrl(String defaultAssetsUrl) {
|
||||||
|
isUsingBundleUrl = true;
|
||||||
String currentVersion = getCurrentVersion();
|
String currentVersion = getCurrentVersion();
|
||||||
if (currentVersion == null) {
|
if (currentVersion == null) {
|
||||||
return defaultAssetsUrl;
|
return defaultAssetsUrl;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
|||||||
constants.put("packageVersion", updateContext.getPackageVersion());
|
constants.put("packageVersion", updateContext.getPackageVersion());
|
||||||
constants.put("currentVersion", updateContext.getCurrentVersion());
|
constants.put("currentVersion", updateContext.getCurrentVersion());
|
||||||
constants.put("buildTime", updateContext.getBuildTime());
|
constants.put("buildTime", updateContext.getBuildTime());
|
||||||
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
||||||
boolean isFirstTime = updateContext.isFirstTime();
|
boolean isFirstTime = updateContext.isFirstTime();
|
||||||
constants.put("isFirstTime", isFirstTime);
|
constants.put("isFirstTime", isFirstTime);
|
||||||
if (isFirstTime) {
|
if (isFirstTime) {
|
||||||
@@ -134,14 +135,14 @@ public class UpdateModule extends ReactContextBaseJavaModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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));
|
JSBundleLoader loader = JSBundleLoader.createFileLoader(UpdateContext.getBundleUrl(application));
|
||||||
Field loadField = instanceManager.getClass().getDeclaredField("mBundleLoader");
|
Field loadField = instanceManager.getClass().getDeclaredField("mBundleLoader");
|
||||||
loadField.setAccessible(true);
|
loadField.setAccessible(true);
|
||||||
loadField.set(instanceManager, loader);
|
loadField.set(instanceManager, loader);
|
||||||
|
} catch (Throwable err) {
|
||||||
|
Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
|
||||||
|
jsBundleField.setAccessible(true);
|
||||||
|
jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
23
lib/index.js
23
lib/index.js
@@ -1,5 +1,9 @@
|
|||||||
import { tryBackupEndpoints, getCheckUrl, setCustomEndpoints } from './endpoint';
|
import {
|
||||||
import { NativeAppEventEmitter, NativeModules } from 'react-native';
|
tryBackupEndpoints,
|
||||||
|
getCheckUrl,
|
||||||
|
setCustomEndpoints,
|
||||||
|
} from './endpoint';
|
||||||
|
import { NativeAppEventEmitter, NativeModules, Platform } from 'react-native';
|
||||||
export { setCustomEndpoints };
|
export { setCustomEndpoints };
|
||||||
|
|
||||||
let Pushy = NativeModules.Pushy;
|
let Pushy = NativeModules.Pushy;
|
||||||
@@ -15,6 +19,12 @@ export const isFirstTime = Pushy.isFirstTime;
|
|||||||
export const isRolledBack = Pushy.isRolledBack;
|
export const isRolledBack = Pushy.isRolledBack;
|
||||||
export const buildTime = Pushy.buildTime;
|
export const buildTime = Pushy.buildTime;
|
||||||
|
|
||||||
|
if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) {
|
||||||
|
throw new Error(
|
||||||
|
'react-native-update模块无法加载,请对照文档检查Bundle URL的配置',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Return json:
|
Return json:
|
||||||
Package was expired:
|
Package was expired:
|
||||||
@@ -111,11 +121,6 @@ export function markSuccess() {
|
|||||||
Pushy.markSuccess();
|
Pushy.markSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
// function report(action) {
|
NativeAppEventEmitter.addListener('RCTPushyDownloadProgress', (params) => {});
|
||||||
// // ${project}.${host}/logstores/${logstore}/track?APIVersion=0.6.0&key1=val1
|
|
||||||
// fetch(`${logUrl}&action=${action}`);
|
|
||||||
// }
|
|
||||||
|
|
||||||
NativeAppEventEmitter.addListener('RCTPushyDownloadProgress', params => {});
|
NativeAppEventEmitter.addListener('RCTPushyUnzipProgress', (params) => {});
|
||||||
|
|
||||||
NativeAppEventEmitter.addListener('RCTPushyUnzipProgress', params => {});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user