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) == '.') { |             if (sub.getName().charAt(0) == '.') { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |             if (isFileUpdatedWithinDays(sub, 7)) { | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|             if (sub.isFile()) { |             if (sub.isFile()) { | ||||||
|                 sub.delete(); |                 sub.delete(); | ||||||
|             } else { |             } 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 |     @Override | ||||||
|     protected Void doInBackground(DownloadTaskParams... params) { |     protected Void doInBackground(DownloadTaskParams... params) { | ||||||
|         int taskType = params[0].type; |         int taskType = params[0].type; | ||||||
|   | |||||||
| @@ -536,7 +536,15 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve | |||||||
|      |      | ||||||
|     for(NSString *fileName in list) { |     for(NSString *fileName in list) { | ||||||
|         if (![fileName isEqualToString:curVersion]) { |         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.getConstants() | ||||||
|   : PushyModule; |   : PushyModule; | ||||||
|  |  | ||||||
| export const downloadRootDir = PushyConstants.downloadRootDir; | export const downloadRootDir: string = PushyConstants.downloadRootDir; | ||||||
| export const packageVersion = PushyConstants.packageVersion; | export const packageVersion: string = PushyConstants.packageVersion; | ||||||
| export const currentVersion = PushyConstants.currentVersion; | export const currentVersion: string = PushyConstants.currentVersion; | ||||||
| export const isFirstTime = PushyConstants.isFirstTime; | export const isFirstTime: boolean = PushyConstants.isFirstTime; | ||||||
| export const rolledBackVersion = PushyConstants.rolledBackVersion; | export const rolledBackVersion: string = PushyConstants.rolledBackVersion; | ||||||
| export const isRolledBack = typeof rolledBackVersion === 'string'; | export const isRolledBack: boolean = typeof rolledBackVersion === 'string'; | ||||||
|  |  | ||||||
| export const buildTime = PushyConstants.buildTime; | export const buildTime: string = PushyConstants.buildTime; | ||||||
| let uuid = PushyConstants.uuid; | let uuid = PushyConstants.uuid; | ||||||
|  |  | ||||||
| if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) { | if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) { | ||||||
|   | |||||||
| @@ -166,7 +166,7 @@ export const PushyProvider = ({ | |||||||
|       if (!info) { |       if (!info) { | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|       const rollout = info.config?.rollout; |       const rollout = info.config?.rollout?.[packageVersion]; | ||||||
|       if (rollout) { |       if (rollout) { | ||||||
|         if (!isInRollout(rollout)) { |         if (!isInRollout(rollout)) { | ||||||
|           log(`not in ${rollout}% rollout, ignored`); |           log(`not in ${rollout}% rollout, ignored`); | ||||||
|   | |||||||
| @@ -8,7 +8,9 @@ export interface CheckResult { | |||||||
|   description?: string; |   description?: string; | ||||||
|   metaInfo?: string; |   metaInfo?: string; | ||||||
|   config?: { |   config?: { | ||||||
|     rollout?: number; |     rollout?: { | ||||||
|  |       [packageVersion: string]: number; | ||||||
|  |     }; | ||||||
|     [key: string]: any; |     [key: string]: any; | ||||||
|   }; |   }; | ||||||
|   pdiff?: string; |   pdiff?: string; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm