mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	improve cleanup and rollout
This commit is contained in:
		
							
								
								
									
										6
									
								
								Example/update.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Example/update.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| { | ||||
|     "android": { | ||||
|         "appId": 28605, | ||||
|         "appKey": "5gbQes9blswLW_jv8dnp8QBz" | ||||
|     } | ||||
| } | ||||
| @@ -430,6 +430,9 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | ||||
|             if (sub.getName().charAt(0) == '.') { | ||||
|                 continue; | ||||
|             } | ||||
|             if (isFileUpdatedWithinDays(sub, 7)) { | ||||
|                 continue; | ||||
|             } | ||||
|             if (sub.isFile()) { | ||||
|                 sub.delete(); | ||||
|             } else { | ||||
| @@ -441,6 +444,13 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private boolean isFileUpdatedWithinDays(File file, int days) { | ||||
|         long currentTime = System.currentTimeMillis(); | ||||
|         long lastModified = file.lastModified(); | ||||
|         long daysInMillis = days * 24 * 60 * 60 * 1000L; | ||||
|         return (currentTime - lastModified) < daysInMillis; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected Void doInBackground(DownloadTaskParams... params) { | ||||
|         int taskType = params[0].type; | ||||
|   | ||||
| @@ -536,7 +536,15 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve | ||||
|      | ||||
|     for(NSString *fileName in list) { | ||||
|         if (![fileName isEqualToString:curVersion]) { | ||||
|             [_fileManager removeFile:[downloadDir stringByAppendingPathComponent:fileName] completionHandler:nil]; | ||||
|             NSString *filePath = [downloadDir stringByAppendingPathComponent:fileName]; | ||||
|             NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error]; | ||||
|             if (error) { | ||||
|                 continue; | ||||
|             } | ||||
|             NSDate *modificationDate = [attributes fileModificationDate]; | ||||
|             if ([[NSDate date] timeIntervalSinceDate:modificationDate] > 7 * 24 * 60 * 60) { | ||||
|                 [_fileManager removeFile:filePath completionHandler:nil]; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										14
									
								
								src/core.ts
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/core.ts
									
									
									
									
									
								
							| @@ -21,14 +21,14 @@ const PushyConstants = isTurboModuleEnabled | ||||
|   ? PushyModule.getConstants() | ||||
|   : PushyModule; | ||||
|  | ||||
| export const downloadRootDir = PushyConstants.downloadRootDir; | ||||
| export const packageVersion = PushyConstants.packageVersion; | ||||
| export const currentVersion = PushyConstants.currentVersion; | ||||
| export const isFirstTime = PushyConstants.isFirstTime; | ||||
| export const rolledBackVersion = PushyConstants.rolledBackVersion; | ||||
| export const isRolledBack = typeof rolledBackVersion === 'string'; | ||||
| export const downloadRootDir: string = PushyConstants.downloadRootDir; | ||||
| export const packageVersion: string = PushyConstants.packageVersion; | ||||
| export const currentVersion: string = PushyConstants.currentVersion; | ||||
| export const isFirstTime: boolean = PushyConstants.isFirstTime; | ||||
| export const rolledBackVersion: string = PushyConstants.rolledBackVersion; | ||||
| export const isRolledBack: boolean = typeof rolledBackVersion === 'string'; | ||||
|  | ||||
| export const buildTime = PushyConstants.buildTime; | ||||
| export const buildTime: string = PushyConstants.buildTime; | ||||
| let uuid = PushyConstants.uuid; | ||||
|  | ||||
| if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) { | ||||
|   | ||||
| @@ -166,7 +166,7 @@ export const PushyProvider = ({ | ||||
|       if (!info) { | ||||
|         return; | ||||
|       } | ||||
|       const rollout = info.config?.rollout; | ||||
|       const rollout = info.config?.rollout?.[packageVersion]; | ||||
|       if (rollout) { | ||||
|         if (!isInRollout(rollout)) { | ||||
|           log(`not in ${rollout}% rollout, ignored`); | ||||
|   | ||||
| @@ -8,7 +8,9 @@ export interface CheckResult { | ||||
|   description?: string; | ||||
|   metaInfo?: string; | ||||
|   config?: { | ||||
|     rollout?: number; | ||||
|     rollout?: { | ||||
|       [packageVersion: string]: number; | ||||
|     }; | ||||
|     [key: string]: any; | ||||
|   }; | ||||
|   pdiff?: string; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm