mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	bugfix
This commit is contained in:
		| @@ -27,6 +27,16 @@ public class UpdateContext { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.sp = context.getSharedPreferences("update", Context.MODE_PRIVATE); |         this.sp = context.getSharedPreferences("update", Context.MODE_PRIVATE); | ||||||
|  |  | ||||||
|  |         String packageVersion = getPackageVersion(); | ||||||
|  |         if (!packageVersion.equals(this.sp.getString("packageVersion", null))) { | ||||||
|  |             SharedPreferences.Editor editor = sp.edit(); | ||||||
|  |             editor.clear(); | ||||||
|  |             editor.putString("packageVersion", packageVersion); | ||||||
|  |             editor.apply(); | ||||||
|  |  | ||||||
|  |             this.clearUp(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String getRootDir() { |     public String getRootDir() { | ||||||
| @@ -98,7 +108,7 @@ public class UpdateContext { | |||||||
|             editor.putString("lastVersion", hashName); |             editor.putString("lastVersion", hashName); | ||||||
|         } |         } | ||||||
|         editor.putBoolean("firstTime", true); |         editor.putBoolean("firstTime", true); | ||||||
|         editor.putBoolean("shouldRollback", false); |         editor.putBoolean("firstTimeOk", false); | ||||||
|         editor.putBoolean("rolledBack", false); |         editor.putBoolean("rolledBack", false); | ||||||
|         editor.apply(); |         editor.apply(); | ||||||
|     } |     } | ||||||
| @@ -115,10 +125,17 @@ public class UpdateContext { | |||||||
|         return sp.getBoolean("rolledBack", false); |         return sp.getBoolean("rolledBack", false); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void clearFirstTimeMark() { |     public void markSuccess() { | ||||||
|  |         SharedPreferences.Editor editor = sp.edit(); | ||||||
|  |         editor.putBoolean("firstTimeOk", true); | ||||||
|  |         editor.apply(); | ||||||
|  |  | ||||||
|  |         this.clearUp(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void clearFirstTime() { | ||||||
|         SharedPreferences.Editor editor = sp.edit(); |         SharedPreferences.Editor editor = sp.edit(); | ||||||
|         editor.putBoolean("firstTime", false); |         editor.putBoolean("firstTime", false); | ||||||
|         editor.putBoolean("shouldRollback", false); |  | ||||||
|         editor.apply(); |         editor.apply(); | ||||||
|  |  | ||||||
|         this.clearUp(); |         this.clearUp(); | ||||||
| @@ -145,33 +162,32 @@ public class UpdateContext { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String getBundleUrl(String defaultAssetsUrl) { |     public String getBundleUrl(String defaultAssetsUrl) { | ||||||
|         // Test should rollback. |  | ||||||
|         if (sp.getBoolean("shouldRollback", false)) { |  | ||||||
|             this.rollBack(); |  | ||||||
|         } |  | ||||||
|         String currentVersion = getCurrentVersion(); |         String currentVersion = getCurrentVersion(); | ||||||
|         if (currentVersion == null) { |         if (currentVersion == null) { | ||||||
|             return defaultAssetsUrl; |             return defaultAssetsUrl; | ||||||
|         } |         } | ||||||
|         if (sp.getBoolean("firstTime", false)) { |         // Test should rollback. | ||||||
|             SharedPreferences.Editor editor = sp.edit(); |         if (!sp.getBoolean("firstTime", false)) { | ||||||
|             editor.putBoolean("shouldRollback", true); |             if (!sp.getBoolean("firstTimeOk", true)) { | ||||||
|             editor.apply(); |                 // Not firstTime, but not ok, so we roll back. | ||||||
|  |                 currentVersion = this.rollBack(); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         return (new File(rootDir, currentVersion+"/index.bundlejs").toString()); |         return (new File(rootDir, currentVersion+"/index.bundlejs").toString()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void rollBack() { |     private String rollBack() { | ||||||
|         String lastVersion = sp.getString("lastVersion", null); |         String lastVersion = sp.getString("lastVersion", null); | ||||||
|         if (lastVersion == null) { |         if (lastVersion == null) { | ||||||
|             throw new Error("This should never happen"); |             throw new Error("This should never happen"); | ||||||
|         } |         } | ||||||
|         SharedPreferences.Editor editor = sp.edit(); |         SharedPreferences.Editor editor = sp.edit(); | ||||||
|         editor.putString("currentVersion", lastVersion); |         editor.putString("currentVersion", lastVersion); | ||||||
|         editor.putBoolean("shouldRollback", false); |         editor.putBoolean("firstTimeOk", true); | ||||||
|         editor.putBoolean("firstTime", false); |         editor.putBoolean("firstTime", false); | ||||||
|         editor.putBoolean("rolledBack", true); |         editor.putBoolean("rolledBack", true); | ||||||
|         editor.apply(); |         editor.apply(); | ||||||
|  |         return lastVersion; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void clearUp() { |     private void clearUp() { | ||||||
|   | |||||||
| @@ -34,7 +34,11 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|         constants.put("downloadRootDir", updateContext.getRootDir()); |         constants.put("downloadRootDir", updateContext.getRootDir()); | ||||||
|         constants.put("packageVersion", updateContext.getPackageVersion()); |         constants.put("packageVersion", updateContext.getPackageVersion()); | ||||||
|         constants.put("currentVersion", updateContext.getCurrentVersion()); |         constants.put("currentVersion", updateContext.getCurrentVersion()); | ||||||
|         constants.put("isFirstTime", updateContext.isFirstTime()); |         boolean isFirstTime = updateContext.isFirstTime(); | ||||||
|  |         constants.put("isFirstTime", isFirstTime); | ||||||
|  |         if (isFirstTime) { | ||||||
|  |             updateContext.clearFirstTime(); | ||||||
|  |         } | ||||||
|         boolean isRolledBack = updateContext.isRolledBack(); |         boolean isRolledBack = updateContext.isRolledBack(); | ||||||
|         constants.put("isRolledBack", isRolledBack); |         constants.put("isRolledBack", isRolledBack); | ||||||
|         if (isRolledBack) { |         if (isRolledBack) { | ||||||
| @@ -129,11 +133,11 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void clearFirstTimeMark() { |     public void markSuccess() { | ||||||
|         UiThreadUtil.runOnUiThread(new Runnable() { |         UiThreadUtil.runOnUiThread(new Runnable() { | ||||||
|             @Override |             @Override | ||||||
|             public void run() { |             public void run() { | ||||||
|                 updateContext.clearFirstTimeMark(); |                 updateContext.markSuccess(); | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -87,6 +87,6 @@ export async function switchVersionLater(hash) { | |||||||
|   HotUpdate.setNeedUpdate({hashName:hash}); |   HotUpdate.setNeedUpdate({hashName:hash}); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function clearFirstTimeMark() { | export function markSuccess() { | ||||||
|   HotUpdate.clearFirstTimeMark(); |   HotUpdate.markSuccess(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -88,7 +88,7 @@ export const commands = { | |||||||
|   selectApp: async function({args, options}) { |   selectApp: async function({args, options}) { | ||||||
|     const {platform} = options; |     const {platform} = options; | ||||||
|     checkPlatform(platform); |     checkPlatform(platform); | ||||||
|     const id = args[0] || (await chooseApp()).id; |     const id = args[0] || (await chooseApp(platform)).id; | ||||||
|  |  | ||||||
|     let updateInfo = {}; |     let updateInfo = {}; | ||||||
|     if (await fs.exists('update.json')) { |     if (await fs.exists('update.json')) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 tdzl2003
					tdzl2003