mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	Prevent some repeated actions
This commit is contained in:
		| @@ -154,7 +154,7 @@ public class UpdateContext { | ||||
|         String lastVersion = getCurrentVersion(); | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putString("currentVersion", hash); | ||||
|         if (lastVersion != null) { | ||||
|         if (lastVersion != null && lastVersion != hash) { | ||||
|             editor.putString("lastVersion", lastVersion); | ||||
|         } | ||||
|         editor.putBoolean("firstTime", true); | ||||
|   | ||||
							
								
								
									
										37
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								lib/index.js
									
									
									
									
									
								
							| @@ -85,8 +85,17 @@ function assertRelease() { | ||||
|   } | ||||
| } | ||||
|  | ||||
| let checkingThrottling = false; | ||||
| export async function checkUpdate(APPKEY, isRetry) { | ||||
|   assertRelease(); | ||||
|   if (checkingThrottling) { | ||||
|     logger('repeated checking, ignored'); | ||||
|     return; | ||||
|   } | ||||
|   checkingThrottling = true; | ||||
|   setTimeout(() => { | ||||
|     checkingThrottling = false; | ||||
|   }, 3000); | ||||
|   if (blockUpdate && blockUpdate.until > Date.now() / 1000) { | ||||
|     throw new Error( | ||||
|       `热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date( | ||||
| @@ -145,11 +154,25 @@ function checkOperation(op) { | ||||
|   }); | ||||
| } | ||||
|  | ||||
| let downloadingThrottling = false; | ||||
| let downloadedHash; | ||||
| export async function downloadUpdate(options, eventListeners) { | ||||
|   assertRelease(); | ||||
|   if (!options.update) { | ||||
|     return; | ||||
|   } | ||||
|   if (downloadedHash === options.hash) { | ||||
|     logger(`duplicated downloaded hash ${downloadedHash}, ignored`); | ||||
|     return; | ||||
|   } | ||||
|   if (downloadingThrottling) { | ||||
|     logger('repeated downloading, ignored'); | ||||
|     return; | ||||
|   } | ||||
|   downloadingThrottling = true; | ||||
|   setTimeout(() => { | ||||
|     downloadingThrottling = false; | ||||
|   }, 3000); | ||||
|   let progressHandler; | ||||
|   if (eventListeners) { | ||||
|     if (eventListeners.onDownloadProgress) { | ||||
| @@ -188,7 +211,7 @@ export async function downloadUpdate(options, eventListeners) { | ||||
|     }); | ||||
|   } | ||||
|   progressHandler && progressHandler.remove(); | ||||
|   await new Promise((resolve) => setTimeout(resolve, 100)); | ||||
|   downloadedHash = options.hash; | ||||
|   return options.hash; | ||||
| } | ||||
|  | ||||
| @@ -198,14 +221,26 @@ export function switchVersion(hash) { | ||||
|   Pushy.reloadUpdate({ hash }); | ||||
| } | ||||
|  | ||||
| let readyHash; | ||||
| export function switchVersionLater(hash) { | ||||
|   assertRelease(); | ||||
|   if (readyHash === hash) { | ||||
|     logger(`duplicated ready hash ${readyHash}, ignored`); | ||||
|     return; | ||||
|   } | ||||
|   readyHash = hash; | ||||
|   logger('switchVersionLater'); | ||||
|   Pushy.setNeedUpdate({ hash }); | ||||
| } | ||||
|  | ||||
| let marked = false; | ||||
| export function markSuccess() { | ||||
|   assertRelease(); | ||||
|   if (marked) { | ||||
|     logger('repeated markSuccess, ignored'); | ||||
|     return; | ||||
|   } | ||||
|   marked = true; | ||||
|   logger('markSuccess'); | ||||
|   Pushy.markSuccess(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm