mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	添加buildTime
This commit is contained in:
		| @@ -337,7 +337,7 @@ SPEC CHECKSUMS: | |||||||
|   React-jsi: 32285a21b1b24c36060493ed3057a34677d58d09 |   React-jsi: 32285a21b1b24c36060493ed3057a34677d58d09 | ||||||
|   React-jsiexecutor: 8909917ff7d8f21a57e443a866fd8d4560e50c65 |   React-jsiexecutor: 8909917ff7d8f21a57e443a866fd8d4560e50c65 | ||||||
|   React-jsinspector: 111d7d342b07a904c400592e02a2b958f1098b60 |   React-jsinspector: 111d7d342b07a904c400592e02a2b958f1098b60 | ||||||
|   react-native-update: 5c1c198cf30994de21e05bfff431814f3722948c |   react-native-update: dd1ae7615b2281c9f2cd842ab672593074999549 | ||||||
|   React-RCTActionSheet: 89b037c0fb7d2671607cb645760164e7e0c013f6 |   React-RCTActionSheet: 89b037c0fb7d2671607cb645760164e7e0c013f6 | ||||||
|   React-RCTAnimation: e3cefa93c38c004c318f7ec04b883eb14b8b8235 |   React-RCTAnimation: e3cefa93c38c004c318f7ec04b883eb14b8b8235 | ||||||
|   React-RCTBlob: d26ac0e313fbf14e7203473fd593ccaaeee8329e |   React-RCTBlob: d26ac0e313fbf14e7203473fd593ccaaeee8329e | ||||||
|   | |||||||
| @@ -70,10 +70,6 @@ export default class App extends Component { | |||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   checkUpdate = async () => { |   checkUpdate = async () => { | ||||||
|     if (__DEV__) { |  | ||||||
|       // 开发模式不支持热更新,跳过检查 |  | ||||||
|       return; |  | ||||||
|     } |  | ||||||
|     let info; |     let info; | ||||||
|     try { |     try { | ||||||
|       info = await checkUpdate(appKey); |       info = await checkUpdate(appKey); | ||||||
|   | |||||||
| @@ -1,3 +1,5 @@ | |||||||
|  | int MILLIS_IN_MINUTE = 1000 * 60 | ||||||
|  | int minutesSinceEpoch = System.currentTimeMillis() / MILLIS_IN_MINUTE | ||||||
|  |  | ||||||
| def safeExtGet(prop, fallback) { | def safeExtGet(prop, fallback) { | ||||||
|     rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |     rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||||||
| @@ -22,6 +24,17 @@ android { | |||||||
|             jniLibs.srcDirs = ['./lib'] |             jniLibs.srcDirs = ['./lib'] | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     buildTypes { | ||||||
|  |         release { | ||||||
|  |             buildConfigField("String", "PUSHY_BUILD_TIME", "\"${minutesSinceEpoch}\"") | ||||||
|  |             resValue("string", "pushy_build_time", "${minutesSinceEpoch}") | ||||||
|  |         } | ||||||
|  |         debug { | ||||||
|  |             buildConfigField("String", "PUSHY_BUILD_TIME", "\"0\"") | ||||||
|  |             resValue("string", "pushy_build_time", "0") | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| repositories { | repositories { | ||||||
|   | |||||||
| @@ -59,6 +59,10 @@ public class UpdateContext { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public String getBuildTime() { | ||||||
|  |         return BuildConfig.PUSHY_BUILD_TIME; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public interface DownloadFileListener { |     public interface DownloadFileListener { | ||||||
|         void onDownloadCompleted(); |         void onDownloadCompleted(); | ||||||
|         void onDownloadFailed(Throwable error); |         void onDownloadFailed(Throwable error); | ||||||
|   | |||||||
| @@ -41,6 +41,7 @@ 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("buildTime", updateContext.getBuildTime()); | ||||||
|         boolean isFirstTime = updateContext.isFirstTime(); |         boolean isFirstTime = updateContext.isFirstTime(); | ||||||
|         constants.put("isFirstTime", isFirstTime); |         constants.put("isFirstTime", isFirstTime); | ||||||
|         if (isFirstTime) { |         if (isFirstTime) { | ||||||
|   | |||||||
| @@ -152,6 +152,7 @@ RCT_EXPORT_MODULE(RCTHotUpdate); | |||||||
|     NSMutableDictionary *ret = [NSMutableDictionary new]; |     NSMutableDictionary *ret = [NSMutableDictionary new]; | ||||||
|     ret[@"downloadRootDir"] = [RCTHotUpdate downloadDir]; |     ret[@"downloadRootDir"] = [RCTHotUpdate downloadDir]; | ||||||
|     ret[@"packageVersion"] = [RCTHotUpdate packageVersion]; |     ret[@"packageVersion"] = [RCTHotUpdate packageVersion]; | ||||||
|  |     ret[@"buildTime"] = [RCTHotUpdate buildTime]; | ||||||
|     ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; |     ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; | ||||||
|     ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked]; |     ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked]; | ||||||
|     NSDictionary *updateInfo = [defaults dictionaryForKey:keyUpdateInfo]; |     NSDictionary *updateInfo = [defaults dictionaryForKey:keyUpdateInfo]; | ||||||
| @@ -464,4 +465,15 @@ RCT_EXPORT_METHOD(markSuccess) | |||||||
|     return version; |     return version; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | + (NSString *)buildTime | ||||||
|  | { | ||||||
|  | #if DEBUG | ||||||
|  |     return @"0"; | ||||||
|  | #else | ||||||
|  |     // To be replaced by scripts/generateiOSBuildTime.sh | ||||||
|  |     NSString *pushy_build_time = 1570370091 | ||||||
|  |     return pushy_build_time; | ||||||
|  | #endif | ||||||
|  | } | ||||||
|  |  | ||||||
| @end | @end | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ export const packageVersion = HotUpdate.packageVersion; | |||||||
| export const currentVersion = HotUpdate.currentVersion; | export const currentVersion = HotUpdate.currentVersion; | ||||||
| export const isFirstTime = HotUpdate.isFirstTime; | export const isFirstTime = HotUpdate.isFirstTime; | ||||||
| export const isRolledBack = HotUpdate.isRolledBack; | export const isRolledBack = HotUpdate.isRolledBack; | ||||||
|  | export const buildTime = HotUpdate.buildTime; | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Return json: | Return json: | ||||||
| @@ -49,8 +50,9 @@ export async function checkUpdate(APPKEY) { | |||||||
|       'Content-Type': 'application/json', |       'Content-Type': 'application/json', | ||||||
|     }, |     }, | ||||||
|     body: JSON.stringify({ |     body: JSON.stringify({ | ||||||
|       packageVersion: packageVersion, |       packageVersion, | ||||||
|       hash: currentVersion, |       hash: currentVersion, | ||||||
|  |       buildTime, | ||||||
|     }), |     }), | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,6 +17,8 @@ Pod::Spec.new do |s| | |||||||
|   s.vendored_libraries = 'RCTHotUpdate/libRCTHotUpdate.a' |   s.vendored_libraries = 'RCTHotUpdate/libRCTHotUpdate.a' | ||||||
|   s.pod_target_xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"$(SRCROOT)/../node_modules/react-native-update/ios"' } |   s.pod_target_xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"$(SRCROOT)/../node_modules/react-native-update/ios"' } | ||||||
|  |  | ||||||
|  |   s.script_phase = { :name => 'Generate build time', :script => '../../node_modules/react-native-update/scripts/generateiOSBuildTime.sh', :execution_position => :before_compile } | ||||||
|  |  | ||||||
|   s.dependency 'React' |   s.dependency 'React' | ||||||
|   s.dependency 'SSZipArchive' |   s.dependency 'SSZipArchive' | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								scripts/generateiOSBuildTime.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										9
									
								
								scripts/generateiOSBuildTime.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  |    | ||||||
|  | #!/bin/bash | ||||||
|  | set -x | ||||||
|  | # DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH | ||||||
|  | # date +%s > "$DEST/pushy_build_time.txt" | ||||||
|  | OLD_TEXT="NSString \*pushy_build_time" | ||||||
|  | NEW_TEXT="    NSString \*pushy_build_time = $(date +%s)" | ||||||
|  | TARGET_FILE="../../node_modules/react-native-update/ios/RCTHotUpdate/RCTHotUpdate.m" | ||||||
|  | sed -i '' -e "s/.*$OLD_TEXT.*/$NEW_TEXT/" "$TARGET_FILE" | ||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm