mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	Record local hash info
This commit is contained in:
		| @@ -15,7 +15,6 @@ import org.json.JSONException; | ||||
| import org.json.JSONObject; | ||||
| import org.json.JSONTokener; | ||||
|  | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.ByteArrayOutputStream; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| @@ -32,9 +31,8 @@ import okio.BufferedSink; | ||||
| import okio.BufferedSource; | ||||
| import okio.Okio; | ||||
| import static cn.reactnative.modules.update.UpdateModule.sendEvent; | ||||
| /** | ||||
|  * Created by tdzl2003 on 3/31/16. | ||||
|  */ | ||||
|  | ||||
|  | ||||
| class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | ||||
|     final int DOWNLOAD_CHUNK_SIZE = 4096; | ||||
|  | ||||
|   | ||||
| @@ -17,9 +17,6 @@ import java.util.concurrent.Executors; | ||||
|  | ||||
| import java.io.File; | ||||
|  | ||||
| /** | ||||
|  * Created by tdzl2003 on 3/31/16. | ||||
|  */ | ||||
| public class UpdateContext { | ||||
|     private Context context; | ||||
|     private File rootDir; | ||||
| @@ -72,10 +69,6 @@ public class UpdateContext { | ||||
|         return context.getString(R.string.pushy_build_time); | ||||
|     } | ||||
|  | ||||
|     public String getUuid() { | ||||
|         return sp.getString("uuid", null); | ||||
|     } | ||||
|  | ||||
|     public Map getBlockUpdate() { | ||||
|         return new HashMap<String, Object>() {{ | ||||
|             put("until", sp.getInt("blockUntil", 0)); | ||||
| @@ -163,12 +156,16 @@ public class UpdateContext { | ||||
|         editor.apply(); | ||||
|     } | ||||
|  | ||||
|     public void setUuid(String uuid) { | ||||
|     public void setKv(String key, String value) { | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putString("uuid", uuid); | ||||
|         editor.putString(key, value); | ||||
|         editor.apply(); | ||||
|     } | ||||
|  | ||||
|     public String getKv(String key) { | ||||
|         return sp.getString(key, null); | ||||
|     } | ||||
|  | ||||
|     public void setBlockUpdate(int until, String reason) { | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putInt("blockUntil", until); | ||||
| @@ -191,7 +188,11 @@ public class UpdateContext { | ||||
|     public void markSuccess() { | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putBoolean("firstTimeOk", true); | ||||
|         String lastVersion = sp.getString("lastVersion", null); | ||||
|         if (lastVersion != null) { | ||||
|             editor.remove("lastVersion"); | ||||
|             editor.remove("hash_" + lastVersion); | ||||
|         } | ||||
|         editor.apply(); | ||||
|  | ||||
|         this.cleanUp(); | ||||
|   | ||||
| @@ -22,15 +22,11 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| import static android.support.v4.content.FileProvider.getUriForFile; | ||||
|  | ||||
| /** | ||||
|  * Created by tdzl2003 on 3/31/16. | ||||
|  */ | ||||
| public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|     UpdateContext updateContext; | ||||
|     public static ReactApplicationContext mContext; | ||||
| @@ -64,7 +60,7 @@ public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|             updateContext.clearRollbackMark(); | ||||
|         } | ||||
|         constants.put("blockUpdate", updateContext.getBlockUpdate()); | ||||
|         constants.put("uuid", updateContext.getUuid()); | ||||
|         constants.put("uuid", updateContext.getKv("uuid")); | ||||
|         return constants; | ||||
|     } | ||||
|  | ||||
| @@ -264,11 +260,27 @@ public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|         UiThreadUtil.runOnUiThread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 updateContext.setUuid(uuid); | ||||
|                 updateContext.setKv("uuid", uuid); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @ReactMethod | ||||
|     public void setLocalHashInfo(final String hash, final String info) { | ||||
|         UiThreadUtil.runOnUiThread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 updateContext.setKv("hash_" + hash, info); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @ReactMethod | ||||
|     public void getLocalHashInfo(final String hash, final Promise promise) { | ||||
|         promise.resolve(updateContext.getKv("hash_" + hash)); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     /* 发送事件*/ | ||||
|     public static void sendEvent(String eventName, WritableMap params) { | ||||
|         ((ReactContext) mContext).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, | ||||
|   | ||||
							
								
								
									
										6
									
								
								lib/index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								lib/index.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -72,6 +72,12 @@ export function setCustomEndpoints({ | ||||
|   backupQueryUrl?: string; | ||||
| }): void; | ||||
|  | ||||
| export function getCurrentVersionInfo(): Promise<{ | ||||
|   name?: string; | ||||
|   description?: string; | ||||
|   metaInfo?: string; | ||||
| }>; | ||||
|  | ||||
| interface ProgressData { | ||||
|   hash: string; | ||||
|   received: number; | ||||
|   | ||||
							
								
								
									
										22
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								lib/index.js
									
									
									
									
									
								
							| @@ -21,11 +21,6 @@ if (!Pushy) { | ||||
|   throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。'); | ||||
| } | ||||
|  | ||||
| // TODO: save and export current version info | ||||
| // name | ||||
| // description | ||||
| // metaInfo | ||||
|  | ||||
| export const downloadRootDir = Pushy.downloadRootDir; | ||||
| export const packageVersion = Pushy.packageVersion; | ||||
| export const currentVersion = Pushy.currentVersion; | ||||
| @@ -41,6 +36,18 @@ if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) { | ||||
|   ); | ||||
| } | ||||
|  | ||||
| function setLocalHashInfo(hash, info) { | ||||
|   Pushy.setLocalHashInfo(hash, JSON.stringify(info)); | ||||
| } | ||||
|  | ||||
| async function getLocalHashInfo(hash) { | ||||
|   return JSON.parse(await Pushy.getLocalHashInfo(hash)); | ||||
| } | ||||
|  | ||||
| export async function getCurrentVersionInfo() { | ||||
|   return currentVersion ? getLocalHashInfo(currentVersion) : {}; | ||||
| } | ||||
|  | ||||
| const eventEmitter = new NativeEventEmitter(Pushy); | ||||
|  | ||||
| if (!uuid) { | ||||
| @@ -219,6 +226,11 @@ export async function downloadUpdate(options, eventListeners) { | ||||
|       hash: options.hash, | ||||
|     }); | ||||
|   } | ||||
|   setLocalHashInfo(options.hash, { | ||||
|     name: options.name, | ||||
|     description: options.description, | ||||
|     metaInfo: options.metaInfo, | ||||
|   }); | ||||
|   progressHandler && progressHandler.remove(); | ||||
|   downloadedHash = options.hash; | ||||
|   return options.hash; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm