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

Check bundlejs before switch

This commit is contained in:
sunnylqm
2020-01-09 17:45:44 +08:00
parent 5a5884c8fa
commit fa754ef8a2
2 changed files with 9 additions and 5 deletions

View File

@@ -106,8 +106,8 @@ public class UpdateContext {
private SharedPreferences sp; private SharedPreferences sp;
public void switchVersion(String hashName) { public void switchVersion(String hashName) {
if (!new File(rootDir, hashName).exists()) { if (!new File(rootDir, hashName+"/index.bundlejs").exists()) {
throw new Error("Hash name not found, must download first."); throw new Error("Bundle version " + hashName + " not found.");
} }
String lastVersion = getCurrentVersion(); String lastVersion = getCurrentVersion();
SharedPreferences.Editor editor = sp.edit(); SharedPreferences.Editor editor = sp.edit();

View File

@@ -123,8 +123,8 @@ public class UpdateModule extends ReactContextBaseJavaModule{
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
updateContext.switchVersion(hash);
try { try {
updateContext.switchVersion(hash);
Activity activity = getCurrentActivity(); Activity activity = getCurrentActivity();
Application application = activity.getApplication(); Application application = activity.getApplication();
ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager(); ReactInstanceManager instanceManager = ((ReactApplication) application).getReactNativeHost().getReactInstanceManager();
@@ -147,7 +147,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{
} }
} catch (Throwable err) { } catch (Throwable err) {
Log.e("pushy", "Failed to restart application", err); Log.e("pushy", "switchVersion failed", err);
} }
} }
}); });
@@ -160,7 +160,11 @@ public class UpdateModule extends ReactContextBaseJavaModule{
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
updateContext.switchVersion(hash); try {
updateContext.switchVersion(hash);
} catch (Throwable err) {
Log.e("pushy", "switchVersionLater failed", err);
}
} }
}); });
} }