react-native-ota-hot-update 2.2.0 → 2.2.2
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
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
|
|
4
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
|
+
### Key features:
|
|
7
|
+
|
|
8
|
+
- Host the bundle on your own server or in a Git repository.
|
|
9
|
+
- Rollback function
|
|
10
|
+
- Crash Handling: Handles crash exceptions when an incorrect bundle is updated and will automatically roll back to the previous bundle version.
|
|
6
11
|
|
|
7
12
|
1. **Demo via server**
|
|
8
13
|
|
|
@@ -41,7 +41,6 @@ class CrashHandler(private val context: Context) : Thread.UncaughtExceptionHandl
|
|
|
41
41
|
} else {
|
|
42
42
|
sharedPrefs.putString(PATH, "")
|
|
43
43
|
}
|
|
44
|
-
sharedPrefs.putString(VERSION, "0")
|
|
45
44
|
Toast.makeText(context, "Failed to load the update. Please try again.", Toast.LENGTH_LONG).show()
|
|
46
45
|
GlobalScope.launch(Dispatchers.IO) {
|
|
47
46
|
delay(1500)
|
|
@@ -10,6 +10,7 @@ import com.rnhotupdate.Common.CURRENT_VERSION_NAME
|
|
|
10
10
|
import com.rnhotupdate.Common.PATH
|
|
11
11
|
import com.rnhotupdate.Common.PREVIOUS_PATH
|
|
12
12
|
import com.rnhotupdate.Common.VERSION
|
|
13
|
+
import com.rnhotupdate.Common.PREVIOUS_VERSION
|
|
13
14
|
import com.rnhotupdate.Common.METADATA
|
|
14
15
|
import com.rnhotupdate.SharedPrefs
|
|
15
16
|
import java.io.File
|
|
@@ -86,6 +87,12 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
86
87
|
@ReactMethod
|
|
87
88
|
override fun setCurrentVersion(version: String?, promise: Promise) {
|
|
88
89
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
90
|
+
|
|
91
|
+
val currentVersion = sharedPrefs.getString(VERSION)
|
|
92
|
+
if (currentVersion != "" && currentVersion != version) {
|
|
93
|
+
sharedPrefs.putString(PREVIOUS_VERSION, currentVersion)
|
|
94
|
+
}
|
|
95
|
+
|
|
89
96
|
sharedPrefs.putString(VERSION, version)
|
|
90
97
|
promise.resolve(true)
|
|
91
98
|
}
|
|
@@ -124,11 +131,21 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
124
131
|
override fun rollbackToPreviousBundle(a: Double, promise: Promise) {
|
|
125
132
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
126
133
|
val oldPath = sharedPrefs.getString(PREVIOUS_PATH)
|
|
134
|
+
val previousVersion = sharedPrefs.getString(PREVIOUS_VERSION)
|
|
135
|
+
|
|
127
136
|
if (oldPath != "") {
|
|
128
137
|
val isDeleted = utils.deleteOldBundleIfneeded(PATH)
|
|
129
138
|
if (isDeleted) {
|
|
130
139
|
sharedPrefs.putString(PATH, oldPath)
|
|
131
140
|
sharedPrefs.putString(PREVIOUS_PATH, "")
|
|
141
|
+
|
|
142
|
+
if (previousVersion != "") {
|
|
143
|
+
sharedPrefs.putString(VERSION, previousVersion)
|
|
144
|
+
sharedPrefs.putString(PREVIOUS_VERSION, "")
|
|
145
|
+
} else {
|
|
146
|
+
sharedPrefs.putString(VERSION, "")
|
|
147
|
+
}
|
|
148
|
+
|
|
132
149
|
promise.resolve(true)
|
|
133
150
|
} else {
|
|
134
151
|
promise.resolve(false)
|
|
@@ -27,6 +27,7 @@ object Common {
|
|
|
27
27
|
val PATH = "PATH"
|
|
28
28
|
val PREVIOUS_PATH = "PREVIOUS_PATH"
|
|
29
29
|
val VERSION = "VERSION"
|
|
30
|
+
val PREVIOUS_VERSION = "PREVIOUS_VERSION"
|
|
30
31
|
val CURRENT_VERSION_NAME = "CURRENT_VERSION_NAME"
|
|
31
32
|
val SHARED_PREFERENCE_NAME = "HOT-UPDATE-REACT_NATIVE"
|
|
32
33
|
val DEFAULT_BUNDLE = "assets://index.android.bundle"
|
package/ios/OtaHotUpdate.mm
CHANGED
|
@@ -34,7 +34,6 @@ void OTAExceptionHandler(NSException *exception) {
|
|
|
34
34
|
} else {
|
|
35
35
|
[defaults removeObjectForKey:@"PATH"];
|
|
36
36
|
}
|
|
37
|
-
[defaults removeObjectForKey:@"VERSION"];
|
|
38
37
|
[defaults synchronize];
|
|
39
38
|
} else if (previousHandler) {
|
|
40
39
|
previousHandler(exception);
|
|
@@ -283,6 +282,14 @@ RCT_EXPORT_METHOD(rollbackToPreviousBundle:(double)i
|
|
|
283
282
|
if (oldPath && [OtaHotUpdate isFilePathValid:oldPath]) {
|
|
284
283
|
BOOL isDeleted = [OtaHotUpdate removeBundleIfNeeded:@"PATH"];
|
|
285
284
|
if (isDeleted) {
|
|
285
|
+
NSString *previousVersion = [defaults stringForKey:@"PREVIOUS_VERSION"];
|
|
286
|
+
if (previousVersion) {
|
|
287
|
+
[defaults setObject:previousVersion forKey:@"VERSION"];
|
|
288
|
+
[defaults removeObjectForKey:@"PREVIOUS_VERSION"];
|
|
289
|
+
} else {
|
|
290
|
+
[defaults removeObjectForKey:@"VERSION"];
|
|
291
|
+
}
|
|
292
|
+
|
|
286
293
|
[defaults setObject:oldPath forKey:@"PATH"];
|
|
287
294
|
[defaults removeObjectForKey:@"OLD_PATH"];
|
|
288
295
|
[defaults synchronize];
|
|
@@ -311,8 +318,14 @@ RCT_EXPORT_METHOD(getCurrentVersion:(double)a
|
|
|
311
318
|
RCT_EXPORT_METHOD(setCurrentVersion:(NSString *)version
|
|
312
319
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
313
320
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
321
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
322
|
+
NSString *currentVersion = [defaults stringForKey:@"VERSION"];
|
|
323
|
+
|
|
314
324
|
if (version) {
|
|
315
|
-
|
|
325
|
+
if (currentVersion && currentVersion != version) {
|
|
326
|
+
[defaults setObject:currentVersion forKey:@"PREVIOUS_VERSION"];
|
|
327
|
+
}
|
|
328
|
+
|
|
316
329
|
[defaults setObject:version forKey:@"VERSION"];
|
|
317
330
|
[defaults synchronize];
|
|
318
331
|
resolve(@(YES));
|