mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-01 22:03:10 +08:00
Check bundlejs before switch
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
try {
|
||||||
updateContext.switchVersion(hash);
|
updateContext.switchVersion(hash);
|
||||||
|
} catch (Throwable err) {
|
||||||
|
Log.e("pushy", "switchVersionLater failed", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user