react-native-ota-hot-update 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ package com.rnhotupdate;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.content.Intent;
5
+ import android.content.pm.PackageInfo;
5
6
  import android.util.Log;
6
7
 
7
8
  import com.facebook.react.bridge.Promise;
@@ -101,6 +102,12 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
101
102
  file.delete();
102
103
  SharedPrefs sharedPrefs = new SharedPrefs(getReactApplicationContext());
103
104
  sharedPrefs.putString(Common.INSTANCE.getPATH(), fileUnzip);
105
+ PackageInfo info = OtaHotUpdate.packageInfo(getReactApplicationContext());
106
+ String latestVer = null;
107
+ if (info != null) {
108
+ latestVer = info.versionName;
109
+ }
110
+ sharedPrefs.putString(Common.INSTANCE.getCURRENT_VERSION_NAME(), latestVer);
104
111
  promise.resolve(true);
105
112
  } else {
106
113
  file.delete();
@@ -161,6 +168,12 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
161
168
  public void setExactBundlePath(String path, Promise promise) {
162
169
  SharedPrefs sharedPrefs = new SharedPrefs(getReactApplicationContext());
163
170
  sharedPrefs.putString(Common.INSTANCE.getPATH(), path);
171
+ PackageInfo info = OtaHotUpdate.packageInfo(getReactApplicationContext());
172
+ String latestVer = null;
173
+ if (info != null) {
174
+ latestVer = info.versionName;
175
+ }
176
+ sharedPrefs.putString(Common.INSTANCE.getCURRENT_VERSION_NAME(), latestVer);
164
177
  promise.resolve(true);
165
178
  }
166
179
 
@@ -1,6 +1,9 @@
1
1
  package com.rnhotupdate;
2
2
 
3
3
  import android.content.Context;
4
+ import android.content.pm.PackageInfo;
5
+ import android.content.pm.PackageManager;
6
+ import android.os.Build;
4
7
 
5
8
  import com.facebook.react.ReactPackage;
6
9
  import com.facebook.react.bridge.NativeModule;
@@ -31,13 +34,30 @@ public class OtaHotUpdate implements ReactPackage {
31
34
  public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactApplicationContext) {
32
35
  return Collections.emptyList();
33
36
  }
37
+ public static PackageInfo packageInfo (Context context) {
38
+ try {
39
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
40
+ return context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.PackageInfoFlags.of(0));
41
+ } else {
42
+ return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
43
+ }
44
+ } catch (Exception e) {
45
+ return null;
46
+ }
47
+ }
34
48
  public static String getBundleJS() {
35
49
  if (mContext == null) {
36
50
  return Common.INSTANCE.getDEFAULT_BUNDLE();
37
51
  }
38
52
  SharedPrefs sharedPrefs = new SharedPrefs(mContext);
53
+ PackageInfo info = OtaHotUpdate.packageInfo(mContext);
54
+ String latestVer = null;
55
+ if (info != null) {
56
+ latestVer = info.versionName;
57
+ }
39
58
  String pathBundle = sharedPrefs.getString(Common.INSTANCE.getPATH());
40
- if (pathBundle.equals("")) {
59
+ String currentVer = sharedPrefs.getString(Common.INSTANCE.getCURRENT_VERSION_NAME());
60
+ if (pathBundle.equals("") || (info != null && !currentVer.equals("") && !latestVer.equals(currentVer))) {
41
61
  return Common.INSTANCE.getDEFAULT_BUNDLE();
42
62
  }
43
63
  return pathBundle;
@@ -27,5 +27,6 @@ object Common {
27
27
  val PATH = "PATH"
28
28
  val VERSION = "VERSION"
29
29
  val SHARED_PREFERENCE_NAME = "HOT-UPDATE-REACT_NATIVE"
30
+ val CURRENT_VERSION_NAME = "CURRENT_VERSION_NAME"
30
31
  val DEFAULT_BUNDLE = "assets://index.android.bundle"
31
32
  }
package/ios/RNhotupdate.m CHANGED
@@ -90,7 +90,10 @@ RCT_EXPORT_MODULE()
90
90
  + (NSURL *)getBundle {
91
91
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
92
92
  NSString *retrievedString = [defaults stringForKey:@"PATH"];
93
- if (retrievedString && [self isFilePathExist:retrievedString]) {
93
+ NSString *currentVersionName = [defaults stringForKey:@"VERSION_NAME"];
94
+ NSString *versionName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
95
+
96
+ if (retrievedString && [self isFilePathExist:retrievedString] && [currentVersionName isEqualToString:versionName]) {
94
97
  NSURL *fileURL = [NSURL fileURLWithPath:retrievedString];
95
98
  return fileURL;
96
99
  } else {
@@ -174,6 +177,7 @@ RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extensi
174
177
  NSLog(@"file extraction----- %@", extractedFilePath);
175
178
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
176
179
  [defaults setObject:extractedFilePath forKey:@"PATH"];
180
+ [defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"];
177
181
  [defaults synchronize];
178
182
  resolve(@(YES));
179
183
  } else {
@@ -217,6 +221,7 @@ RCT_EXPORT_METHOD(setExactBundlePath:(NSString *)path
217
221
  if (path) {
218
222
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
219
223
  [defaults setObject:path forKey:@"PATH"];
224
+ [defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"];
220
225
  [defaults synchronize];
221
226
  resolve(@(YES));
222
227
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Hot update for react native",
5
5
  "main": "src/index",
6
6
  "repository": "https://github.com/vantuan88291/react-native-ota-hot-update",
@@ -12,7 +12,7 @@
12
12
  "homepage": "https://github.com/vantuan88291/react-native-ota-hot-update",
13
13
  "dependencies": {
14
14
  "buffer": "^6.0.3",
15
- "isomorphic-git": "git+https://github.com/vantuan88291/isomorphic-git.git"
15
+ "isomorphic-git": "1.27.3"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react-native": ">=0.63.4",