mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	Back compatibility
This commit is contained in:
		| @@ -31,13 +31,14 @@ import static android.support.v4.content.FileProvider.getUriForFile; | |||||||
| /** | /** | ||||||
|  * Created by tdzl2003 on 3/31/16. |  * Created by tdzl2003 on 3/31/16. | ||||||
|  */ |  */ | ||||||
| public class UpdateModule extends ReactContextBaseJavaModule{ | public class UpdateModule extends ReactContextBaseJavaModule { | ||||||
|     UpdateContext updateContext; |     UpdateContext updateContext; | ||||||
|     public static ReactApplicationContext mContext; |     public static ReactApplicationContext mContext; | ||||||
|  |  | ||||||
|     public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) { |     public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) { | ||||||
|         super(reactContext); |         super(reactContext); | ||||||
|         this.updateContext = updateContext; |         this.updateContext = updateContext; | ||||||
|         mContext=reactContext; |         mContext = reactContext; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public UpdateModule(ReactApplicationContext reactContext) { |     public UpdateModule(ReactApplicationContext reactContext) { | ||||||
| @@ -73,7 +74,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void downloadUpdate(ReadableMap options, final Promise promise){ |     public void downloadUpdate(ReadableMap options, final Promise promise) { | ||||||
|         String url = options.getString("updateUrl"); |         String url = options.getString("updateUrl"); | ||||||
|         String hash = options.getString("hash"); |         String hash = options.getString("hash"); | ||||||
|         updateContext.downloadFullUpdate(url, hash, new UpdateContext.DownloadFileListener() { |         updateContext.downloadFullUpdate(url, hash, new UpdateContext.DownloadFileListener() { | ||||||
| @@ -90,7 +91,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void downloadAndInstallApk(ReadableMap options, final Promise promise){ |     public void downloadAndInstallApk(ReadableMap options, final Promise promise) { | ||||||
|         String url = options.getString("url"); |         String url = options.getString("url"); | ||||||
|         String hash = options.getString("hash"); |         String hash = options.getString("hash"); | ||||||
|         String target = options.getString("target"); |         String target = options.getString("target"); | ||||||
| @@ -136,9 +137,12 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|  |  | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void downloadPatchFromPackage(ReadableMap options, final Promise promise){ |     public void downloadPatchFromPackage(ReadableMap options, final Promise promise) { | ||||||
|         String url = options.getString("updateUrl"); |         String url = options.getString("updateUrl"); | ||||||
|         String hash = options.getString("hash"); |         String hash = options.getString("hash"); | ||||||
|  |         if (hash == null) { | ||||||
|  |             hash = options.getString("hashName"); | ||||||
|  |         } | ||||||
|         updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() { |         updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() { | ||||||
|             @Override |             @Override | ||||||
|             public void onDownloadCompleted(DownloadTaskParams params) { |             public void onDownloadCompleted(DownloadTaskParams params) { | ||||||
| @@ -153,10 +157,16 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void downloadPatchFromPpk(ReadableMap options, final Promise promise){ |     public void downloadPatchFromPpk(ReadableMap options, final Promise promise) { | ||||||
|         String url = options.getString("updateUrl"); |         String url = options.getString("updateUrl"); | ||||||
|         String hash = options.getString("hash"); |         String hash = options.getString("hash"); | ||||||
|  |         if (hash == null) { | ||||||
|  |             hash = options.getString("hashName"); | ||||||
|  |         } | ||||||
|         String originHash = options.getString("originHash"); |         String originHash = options.getString("originHash"); | ||||||
|  |         if (originHash == null) { | ||||||
|  |             originHash = options.getString(("originHashName")); | ||||||
|  |         } | ||||||
|         updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() { |         updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() { | ||||||
|             @Override |             @Override | ||||||
|             public void onDownloadCompleted(DownloadTaskParams params) { |             public void onDownloadCompleted(DownloadTaskParams params) { | ||||||
| @@ -172,7 +182,8 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void reloadUpdate(ReadableMap options) { |     public void reloadUpdate(ReadableMap options) { | ||||||
|         final String hash = options.getString("hash"); |         final String hash = options.getString("hash") == null ? | ||||||
|  |                 options.getString("hashName") : options.getString("hash"); | ||||||
|  |  | ||||||
|         UiThreadUtil.runOnUiThread(new Runnable() { |         UiThreadUtil.runOnUiThread(new Runnable() { | ||||||
|             @Override |             @Override | ||||||
| @@ -200,7 +211,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|  |  | ||||||
|                     try { |                     try { | ||||||
|                         instanceManager.recreateReactContextInBackground(); |                         instanceManager.recreateReactContextInBackground(); | ||||||
|                     } catch(Throwable err) { |                     } catch (Throwable err) { | ||||||
|                         activity.recreate(); |                         activity.recreate(); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
| @@ -213,7 +224,8 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|     public void setNeedUpdate(ReadableMap options) { |     public void setNeedUpdate(ReadableMap options) { | ||||||
|         final String hash = options.getString("hash"); |         final String hash = options.getString("hash") == null ? | ||||||
|  |                 options.getString("hashName") : options.getString("hash"); | ||||||
|  |  | ||||||
|         UiThreadUtil.runOnUiThread(new Runnable() { |         UiThreadUtil.runOnUiThread(new Runnable() { | ||||||
|             @Override |             @Override | ||||||
| @@ -260,7 +272,7 @@ public class UpdateModule extends ReactContextBaseJavaModule{ | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* 发送事件*/ |     /* 发送事件*/ | ||||||
|     public static void sendEvent(String eventName,  WritableMap params) { |     public static void sendEvent(String eventName, WritableMap params) { | ||||||
|         ((ReactContext) mContext).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, |         ((ReactContext) mContext).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, | ||||||
|                 params); |                 params); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -256,6 +256,9 @@ RCT_EXPORT_METHOD(downloadPatchFromPpk:(NSDictionary *)options | |||||||
| RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options) | RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options) | ||||||
| { | { | ||||||
|     NSString *hash = options[@"hash"]; |     NSString *hash = options[@"hash"]; | ||||||
|  |     if (hash.length <= 0) { | ||||||
|  |         hash = options[@"hashName"]; | ||||||
|  |     } | ||||||
|     if (hash.length) { |     if (hash.length) { | ||||||
|         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | ||||||
|         NSString *lastVersion = nil; |         NSString *lastVersion = nil; | ||||||
| @@ -279,6 +282,9 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options) | |||||||
| RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options) | RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options) | ||||||
| { | { | ||||||
|     NSString *hash = options[@"hash"]; |     NSString *hash = options[@"hash"]; | ||||||
|  |     if (hash.length <= 0) { | ||||||
|  |         hash = options[@"hashName"]; | ||||||
|  |     } | ||||||
|     if (hash.length) { |     if (hash.length) { | ||||||
|         [self setNeedUpdate:options]; |         [self setNeedUpdate:options]; | ||||||
|          |          | ||||||
| @@ -335,6 +341,9 @@ RCT_EXPORT_METHOD(markSuccess) | |||||||
| { | { | ||||||
|     NSString *updateUrl = [RCTConvert NSString:options[@"updateUrl"]]; |     NSString *updateUrl = [RCTConvert NSString:options[@"updateUrl"]]; | ||||||
|     NSString *hash = [RCTConvert NSString:options[@"hash"]]; |     NSString *hash = [RCTConvert NSString:options[@"hash"]]; | ||||||
|  |     if (hash.length <= 0) { | ||||||
|  |         hash = [RCTConvert NSString:options[@"hashName"]];; | ||||||
|  |     } | ||||||
|     if (updateUrl.length <= 0 || hash.length <= 0) { |     if (updateUrl.length <= 0 || hash.length <= 0) { | ||||||
|         callback([self errorWithMessage:ERROR_OPTIONS]); |         callback([self errorWithMessage:ERROR_OPTIONS]); | ||||||
|         return; |         return; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm