react-native-ota-hot-update 2.0.4 → 2.0.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.
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# react-native-ota-hot-update
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
This React Native module allows you to manage hot updates with minimal configuration, similar to Code Push. You can control versioning and host the JS bundle yourself. The library handles the installation of updates after the bundle is downloaded from your server or Git repository. With Code Push retiring soon, this library gives you full control over your update process, whether hosting the bundle on your own server or in a Git repository.
|
|
4
|
+
This React Native module allows you to manage hot updates (in-app update) with minimal configuration, similar to Code Push. You can control versioning and host the JS bundle yourself. The library handles the installation of updates after the bundle is downloaded from your server or Git repository. With Code Push retiring soon, this library gives you full control over your update process, whether hosting the bundle on your own server or in a Git repository.
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
1. **Demo via server**
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
package com.otahotupdate
|
|
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
|
import com.facebook.react.TurboReactPackage
|
|
5
8
|
import com.facebook.react.bridge.NativeModule
|
|
6
9
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
10
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
11
|
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
12
|
+
import com.rnhotupdate.Common.CURRENT_VERSION_NAME
|
|
9
13
|
import com.rnhotupdate.Common.DEFAULT_BUNDLE
|
|
10
14
|
import com.rnhotupdate.Common.PATH
|
|
11
15
|
import com.rnhotupdate.SharedPrefs
|
|
@@ -40,6 +44,14 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() {
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
companion object {
|
|
47
|
+
@Suppress("DEPRECATION")
|
|
48
|
+
fun Context.getPackageInfo(): PackageInfo {
|
|
49
|
+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
50
|
+
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
|
|
51
|
+
} else {
|
|
52
|
+
packageManager.getPackageInfo(packageName, 0)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
43
55
|
private var mContext: Context? = null
|
|
44
56
|
val bundleJS: String
|
|
45
57
|
get() {
|
|
@@ -48,7 +60,8 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() {
|
|
|
48
60
|
}
|
|
49
61
|
val sharedPrefs = SharedPrefs(mContext!!)
|
|
50
62
|
val pathBundle = sharedPrefs.getString(PATH)
|
|
51
|
-
|
|
63
|
+
val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_NAME)
|
|
64
|
+
if (pathBundle == "" || (!currentVersionName.isNullOrEmpty() && currentVersionName != mContext?.getPackageInfo()?.versionName)) {
|
|
52
65
|
return DEFAULT_BUNDLE
|
|
53
66
|
}
|
|
54
67
|
return pathBundle!!
|
|
@@ -6,6 +6,8 @@ import com.facebook.react.bridge.Promise
|
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
7
|
import com.facebook.react.bridge.ReactMethod
|
|
8
8
|
import com.jakewharton.processphoenix.ProcessPhoenix
|
|
9
|
+
import com.otahotupdate.OtaHotUpdate.Companion.getPackageInfo
|
|
10
|
+
import com.rnhotupdate.Common.CURRENT_VERSION_NAME
|
|
9
11
|
import com.rnhotupdate.Common.PATH
|
|
10
12
|
import com.rnhotupdate.Common.VERSION
|
|
11
13
|
import com.rnhotupdate.SharedPrefs
|
|
@@ -93,6 +95,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
93
95
|
file.delete()
|
|
94
96
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
95
97
|
sharedPrefs.putString(PATH, fileUnzip)
|
|
98
|
+
sharedPrefs.putString(CURRENT_VERSION_NAME, reactApplicationContext?.getPackageInfo()?.versionName)
|
|
96
99
|
promise.resolve(true)
|
|
97
100
|
} else {
|
|
98
101
|
file.delete()
|
|
@@ -145,6 +148,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
145
148
|
override fun setExactBundlePath(path: String?, promise: Promise) {
|
|
146
149
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
147
150
|
sharedPrefs.putString(PATH, path)
|
|
151
|
+
sharedPrefs.putString(CURRENT_VERSION_NAME, reactApplicationContext?.getPackageInfo()?.versionName)
|
|
148
152
|
promise.resolve(true)
|
|
149
153
|
}
|
|
150
154
|
companion object {
|
|
@@ -26,6 +26,7 @@ class SharedPrefs internal constructor(context: Context) {
|
|
|
26
26
|
object Common {
|
|
27
27
|
val PATH = "PATH"
|
|
28
28
|
val VERSION = "VERSION"
|
|
29
|
+
val CURRENT_VERSION_NAME = "CURRENT_VERSION_NAME"
|
|
29
30
|
val SHARED_PREFERENCE_NAME = "HOT-UPDATE-REACT_NATIVE"
|
|
30
31
|
val DEFAULT_BUNDLE = "assets://index.android.bundle"
|
|
31
32
|
}
|
package/ios/OtaHotUpdate.mm
CHANGED
|
@@ -88,7 +88,10 @@ RCT_EXPORT_MODULE()
|
|
|
88
88
|
+ (NSURL *)getBundle {
|
|
89
89
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
90
90
|
NSString *retrievedString = [defaults stringForKey:@"PATH"];
|
|
91
|
-
|
|
91
|
+
NSString *currentVersionName = [defaults stringForKey:@"VERSION_NAME"];
|
|
92
|
+
NSString *versionName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
|
93
|
+
|
|
94
|
+
if (retrievedString && [self isFilePathExist:retrievedString] && [currentVersionName isEqualToString:versionName]) {
|
|
92
95
|
NSURL *fileURL = [NSURL fileURLWithPath:retrievedString];
|
|
93
96
|
return fileURL;
|
|
94
97
|
} else {
|
|
@@ -175,6 +178,7 @@ RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extensi
|
|
|
175
178
|
NSLog(@"file extraction----- %@", extractedFilePath);
|
|
176
179
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
177
180
|
[defaults setObject:extractedFilePath forKey:@"PATH"];
|
|
181
|
+
[defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"];
|
|
178
182
|
[defaults synchronize];
|
|
179
183
|
resolve(@(YES));
|
|
180
184
|
} else {
|
|
@@ -224,6 +228,7 @@ RCT_EXPORT_METHOD(setExactBundlePath:(NSString *)path
|
|
|
224
228
|
if (path) {
|
|
225
229
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
226
230
|
[defaults setObject:path forKey:@"PATH"];
|
|
231
|
+
[defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"];
|
|
227
232
|
[defaults synchronize];
|
|
228
233
|
resolve(@(YES));
|
|
229
234
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-ota-hot-update",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Hot update for react native",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"buffer": "^6.0.3",
|
|
74
|
-
"isomorphic-git": "
|
|
74
|
+
"isomorphic-git": "1.27.3"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@commitlint/config-conventional": "^17.0.2",
|