react-native-ota-hot-update 2.1.42 → 2.2.0
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 +14 -3
- package/android/src/main/java/com/otahotupdate/CrashHandler.kt +55 -0
- package/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt +15 -23
- package/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt +16 -95
- package/android/src/main/java/com/otahotupdate/Utils.kt +94 -0
- package/ios/OtaHotUpdate.mm +49 -10
- package/lib/commonjs/index.js +10 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +10 -8
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +1 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +1 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/build/index.js +1 -1
- package/plugin/src/index.ts +1 -1
- package/plugin/tsconfig.tsbuildinfo +1 -1
- package/react-native.config.js +1 -1
- package/src/index.tsx +13 -14
package/README.md
CHANGED
|
@@ -35,6 +35,17 @@ Auto linking already, need pod install for ios:
|
|
|
35
35
|
cd ios && pod install
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Expo
|
|
39
|
+
|
|
40
|
+
Modify `app.json`:
|
|
41
|
+
|
|
42
|
+
```angular2html
|
|
43
|
+
"plugins": [
|
|
44
|
+
"react-native-ota-hot-update",
|
|
45
|
+
...
|
|
46
|
+
]
|
|
47
|
+
```
|
|
48
|
+
|
|
38
49
|
### IOS
|
|
39
50
|
Open `AppDelegate.m` and add this:
|
|
40
51
|
|
|
@@ -132,7 +143,7 @@ Open `MainApplication.kt` and add these codes bellow:
|
|
|
132
143
|
import com.otahotupdate.OtaHotUpdate
|
|
133
144
|
...
|
|
134
145
|
override fun getJSBundleFile(): String? {
|
|
135
|
-
return OtaHotUpdate.bundleJS
|
|
146
|
+
return OtaHotUpdate.bundleJS(this@MainApplication)
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
```
|
|
@@ -142,11 +153,11 @@ MainApplication.java:
|
|
|
142
153
|
@Nullable
|
|
143
154
|
@Override
|
|
144
155
|
protected String getJSBundleFile() {
|
|
145
|
-
return OtaHotUpdate.getBundleJS();
|
|
156
|
+
return OtaHotUpdate.getBundleJS(this);
|
|
146
157
|
}
|
|
147
158
|
```
|
|
148
159
|
|
|
149
|
-
For
|
|
160
|
+
For java it maybe can be like: `OtaHotUpdate.Companion.getBundleJS(this)` depend on kotlin / jdk version on your project, you can use android studio to get the correct format coding.
|
|
150
161
|
|
|
151
162
|
Open `AndroidManifest.xml` :
|
|
152
163
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.otahotupdate
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.widget.Toast
|
|
7
|
+
import androidx.appcompat.app.AlertDialog
|
|
8
|
+
import com.jakewharton.processphoenix.ProcessPhoenix
|
|
9
|
+
import com.rnhotupdate.Common.PATH
|
|
10
|
+
import com.rnhotupdate.Common.PREVIOUS_PATH
|
|
11
|
+
import com.rnhotupdate.Common.VERSION
|
|
12
|
+
import com.rnhotupdate.SharedPrefs
|
|
13
|
+
import kotlinx.coroutines.Dispatchers
|
|
14
|
+
import kotlinx.coroutines.GlobalScope
|
|
15
|
+
import kotlinx.coroutines.delay
|
|
16
|
+
import kotlinx.coroutines.launch
|
|
17
|
+
|
|
18
|
+
class CrashHandler(private val context: Context) : Thread.UncaughtExceptionHandler {
|
|
19
|
+
private val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
|
|
20
|
+
private val utils: Utils = Utils(context)
|
|
21
|
+
private var beginning = true
|
|
22
|
+
init {
|
|
23
|
+
GlobalScope.launch(Dispatchers.IO) {
|
|
24
|
+
delay(2000)
|
|
25
|
+
beginning = false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
override fun uncaughtException(thread: Thread, throwable: Throwable) {
|
|
29
|
+
if (beginning) {
|
|
30
|
+
//begin remove and using previous bundle
|
|
31
|
+
val sharedPrefs = SharedPrefs(context)
|
|
32
|
+
val oldPath = sharedPrefs.getString(PREVIOUS_PATH)
|
|
33
|
+
if (oldPath != "") {
|
|
34
|
+
val isDeleted = utils.deleteOldBundleIfneeded(PATH)
|
|
35
|
+
if (isDeleted) {
|
|
36
|
+
sharedPrefs.putString(PATH, oldPath)
|
|
37
|
+
sharedPrefs.putString(PREVIOUS_PATH, "")
|
|
38
|
+
} else {
|
|
39
|
+
sharedPrefs.putString(PATH, "")
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
sharedPrefs.putString(PATH, "")
|
|
43
|
+
}
|
|
44
|
+
sharedPrefs.putString(VERSION, "0")
|
|
45
|
+
Toast.makeText(context, "Failed to load the update. Please try again.", Toast.LENGTH_LONG).show()
|
|
46
|
+
GlobalScope.launch(Dispatchers.IO) {
|
|
47
|
+
delay(1500)
|
|
48
|
+
ProcessPhoenix.triggerRebirth(context)
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
defaultHandler?.uncaughtException(thread, throwable)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
@@ -4,7 +4,7 @@ import android.content.Context
|
|
|
4
4
|
import android.content.pm.PackageInfo
|
|
5
5
|
import android.content.pm.PackageManager
|
|
6
6
|
import android.os.Build
|
|
7
|
-
import com.facebook.react.
|
|
7
|
+
import com.facebook.react.BaseReactPackage
|
|
8
8
|
import com.facebook.react.bridge.NativeModule
|
|
9
9
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
10
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
@@ -16,10 +16,7 @@ import com.rnhotupdate.Common.VERSION
|
|
|
16
16
|
import com.rnhotupdate.SharedPrefs
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
class OtaHotUpdate
|
|
20
|
-
init {
|
|
21
|
-
mContext = context
|
|
22
|
-
}
|
|
19
|
+
class OtaHotUpdate : BaseReactPackage() {
|
|
23
20
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
24
21
|
return if (name == OtaHotUpdateModule.NAME) {
|
|
25
22
|
OtaHotUpdateModule(reactContext)
|
|
@@ -37,7 +34,6 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() {
|
|
|
37
34
|
OtaHotUpdateModule.NAME,
|
|
38
35
|
false, // canOverrideExistingModule
|
|
39
36
|
false, // needsEagerInit
|
|
40
|
-
true, // hasConstants
|
|
41
37
|
false, // isCxxModule
|
|
42
38
|
isTurboModule // isTurboModule
|
|
43
39
|
)
|
|
@@ -53,24 +49,20 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() {
|
|
|
53
49
|
packageManager.getPackageInfo(packageName, 0)
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (pathBundle == "" || (currentVersionName != mContext?.getPackageInfo()?.versionName)) {
|
|
67
|
-
if (version != "") {
|
|
68
|
-
// reset version number because bundle is wrong version, need download from new version
|
|
69
|
-
sharedPrefs.putString(VERSION, "")
|
|
70
|
-
}
|
|
71
|
-
return DEFAULT_BUNDLE
|
|
52
|
+
fun bundleJS(context: Context): String {
|
|
53
|
+
Thread.setDefaultUncaughtExceptionHandler(CrashHandler(context))
|
|
54
|
+
val sharedPrefs = SharedPrefs(context)
|
|
55
|
+
val pathBundle = sharedPrefs.getString(PATH)
|
|
56
|
+
val version = sharedPrefs.getString(VERSION)
|
|
57
|
+
val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_NAME)
|
|
58
|
+
if (pathBundle == "" || (currentVersionName != context.getPackageInfo().versionName)) {
|
|
59
|
+
if (version != "") {
|
|
60
|
+
// reset version number because bundle is wrong version, need download from new version
|
|
61
|
+
sharedPrefs.putString(VERSION, "")
|
|
72
62
|
}
|
|
73
|
-
return
|
|
63
|
+
return DEFAULT_BUNDLE
|
|
74
64
|
}
|
|
65
|
+
return pathBundle!!
|
|
66
|
+
}
|
|
75
67
|
}
|
|
76
68
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
package com.otahotupdate
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
-
import android.icu.text.SimpleDateFormat
|
|
5
|
-
import android.util.Log
|
|
6
4
|
import com.facebook.react.bridge.Promise
|
|
7
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
6
|
import com.facebook.react.bridge.ReactMethod
|
|
@@ -15,105 +13,22 @@ import com.rnhotupdate.Common.VERSION
|
|
|
15
13
|
import com.rnhotupdate.Common.METADATA
|
|
16
14
|
import com.rnhotupdate.SharedPrefs
|
|
17
15
|
import java.io.File
|
|
18
|
-
import java.util.Date
|
|
19
|
-
import java.util.Locale
|
|
20
|
-
import java.util.zip.ZipFile
|
|
21
16
|
|
|
22
17
|
class OtaHotUpdateModule internal constructor(context: ReactApplicationContext) :
|
|
23
18
|
OtaHotUpdateSpec(context) {
|
|
24
|
-
|
|
19
|
+
private val utils: Utils = Utils(context)
|
|
25
20
|
override fun getName(): String {
|
|
26
21
|
return NAME
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
private fun deleteDirectory(directory: File): Boolean {
|
|
30
|
-
if (directory.isDirectory) {
|
|
31
|
-
// List all files and directories in the current directory
|
|
32
|
-
val files = directory.listFiles()
|
|
33
|
-
if (files != null) {
|
|
34
|
-
// Recursively delete all files and directories
|
|
35
|
-
for (file in files) {
|
|
36
|
-
if (!deleteDirectory(file)) {
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Finally, delete the empty directory or file
|
|
43
|
-
return directory.delete()
|
|
44
|
-
}
|
|
45
|
-
private fun deleteOldBundleIfneeded(pathKey: String?): Boolean {
|
|
46
|
-
val pathName = if (pathKey != null) pathKey else PREVIOUS_PATH
|
|
47
|
-
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
48
|
-
val path = sharedPrefs.getString(pathName)
|
|
49
|
-
val file = File(path)
|
|
50
|
-
if (file.exists() && file.isFile) {
|
|
51
|
-
val isDeleted = deleteDirectory(file.parentFile)
|
|
52
|
-
sharedPrefs.putString(pathName, "")
|
|
53
|
-
return isDeleted
|
|
54
|
-
} else {
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
private fun extractZipFile(
|
|
59
|
-
zipFile: File,extension: String
|
|
60
|
-
): String? {
|
|
61
|
-
return try {
|
|
62
|
-
val outputDir = zipFile.parentFile
|
|
63
|
-
val timestamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
|
|
64
|
-
var topLevelFolder: String? = null
|
|
65
|
-
var bundlePath: String? = null
|
|
66
|
-
ZipFile(zipFile).use { zip ->
|
|
67
|
-
zip.entries().asSequence().forEach { entry ->
|
|
68
|
-
zip.getInputStream(entry).use { input ->
|
|
69
|
-
if (topLevelFolder == null) {
|
|
70
|
-
// Get root folder of zip file after unzip
|
|
71
|
-
val parts = entry.name.split("/")
|
|
72
|
-
if (parts.size > 1) {
|
|
73
|
-
topLevelFolder = parts.first()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
val outputFile = File(outputDir, entry.name)
|
|
77
|
-
if (entry.isDirectory) {
|
|
78
|
-
if (!outputFile.exists()) outputFile.mkdirs()
|
|
79
|
-
} else {
|
|
80
|
-
if (outputFile.parentFile?.exists() != true) outputFile.parentFile?.mkdirs()
|
|
81
|
-
outputFile.outputStream().use { output ->
|
|
82
|
-
input.copyTo(output)
|
|
83
|
-
}
|
|
84
|
-
if (outputFile.absolutePath.endsWith(extension)) {
|
|
85
|
-
bundlePath = outputFile.absolutePath
|
|
86
|
-
return@use // Exit early if found
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// Rename the detected top-level folder
|
|
93
|
-
if (topLevelFolder != null) {
|
|
94
|
-
val extractedFolder = File(outputDir, topLevelFolder)
|
|
95
|
-
val renamedFolder = File(outputDir, "output_$timestamp")
|
|
96
|
-
if (extractedFolder.exists()) {
|
|
97
|
-
extractedFolder.renameTo(renamedFolder)
|
|
98
|
-
// Update bundlePath if the file was inside the renamed folder
|
|
99
|
-
bundlePath = bundlePath?.replace(extractedFolder.absolutePath, renamedFolder.absolutePath)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
bundlePath
|
|
103
|
-
} catch (e: Exception) {
|
|
104
|
-
e.printStackTrace()
|
|
105
|
-
null
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
24
|
|
|
110
25
|
@ReactMethod
|
|
111
26
|
override fun setupBundlePath(path: String?, extension: String?, promise: Promise) {
|
|
112
27
|
if (path != null) {
|
|
113
28
|
val file = File(path)
|
|
114
29
|
if (file.exists() && file.isFile) {
|
|
115
|
-
deleteOldBundleIfneeded(null)
|
|
116
|
-
val fileUnzip = extractZipFile(file, extension ?: ".bundle")
|
|
30
|
+
utils.deleteOldBundleIfneeded(null)
|
|
31
|
+
val fileUnzip = utils.extractZipFile(file, extension ?: ".bundle")
|
|
117
32
|
if (fileUnzip != null) {
|
|
118
33
|
file.delete()
|
|
119
34
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
@@ -122,11 +37,14 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
122
37
|
sharedPrefs.putString(PREVIOUS_PATH, oldPath)
|
|
123
38
|
}
|
|
124
39
|
sharedPrefs.putString(PATH, fileUnzip)
|
|
125
|
-
sharedPrefs.putString(
|
|
40
|
+
sharedPrefs.putString(
|
|
41
|
+
CURRENT_VERSION_NAME,
|
|
42
|
+
reactApplicationContext?.getPackageInfo()?.versionName
|
|
43
|
+
)
|
|
126
44
|
promise.resolve(true)
|
|
127
45
|
} else {
|
|
128
46
|
file.delete()
|
|
129
|
-
deleteDirectory(file.parentFile)
|
|
47
|
+
utils.deleteDirectory(file.parentFile)
|
|
130
48
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
131
49
|
sharedPrefs.putString(PATH, "")
|
|
132
50
|
promise.resolve(false)
|
|
@@ -141,8 +59,8 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
141
59
|
|
|
142
60
|
@ReactMethod
|
|
143
61
|
override fun deleteBundle(i: Double, promise: Promise) {
|
|
144
|
-
val isDeleted = deleteOldBundleIfneeded(PATH)
|
|
145
|
-
val isDeletedOldPath = deleteOldBundleIfneeded(PREVIOUS_PATH)
|
|
62
|
+
val isDeleted = utils.deleteOldBundleIfneeded(PATH)
|
|
63
|
+
val isDeletedOldPath = utils.deleteOldBundleIfneeded(PREVIOUS_PATH)
|
|
146
64
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
147
65
|
sharedPrefs.putString(VERSION, "0")
|
|
148
66
|
promise.resolve(isDeleted && isDeletedOldPath)
|
|
@@ -151,7 +69,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
151
69
|
@ReactMethod
|
|
152
70
|
override fun restart() {
|
|
153
71
|
val context: Context? = currentActivity
|
|
154
|
-
ProcessPhoenix.triggerRebirth(context)
|
|
72
|
+
ProcessPhoenix.triggerRebirth(context)
|
|
155
73
|
}
|
|
156
74
|
|
|
157
75
|
@ReactMethod
|
|
@@ -195,7 +113,10 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
195
113
|
override fun setExactBundlePath(path: String?, promise: Promise) {
|
|
196
114
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
197
115
|
sharedPrefs.putString(PATH, path)
|
|
198
|
-
sharedPrefs.putString(
|
|
116
|
+
sharedPrefs.putString(
|
|
117
|
+
CURRENT_VERSION_NAME,
|
|
118
|
+
reactApplicationContext?.getPackageInfo()?.versionName
|
|
119
|
+
)
|
|
199
120
|
promise.resolve(true)
|
|
200
121
|
}
|
|
201
122
|
|
|
@@ -204,7 +125,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
204
125
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
205
126
|
val oldPath = sharedPrefs.getString(PREVIOUS_PATH)
|
|
206
127
|
if (oldPath != "") {
|
|
207
|
-
val isDeleted = deleteOldBundleIfneeded(PATH)
|
|
128
|
+
val isDeleted = utils.deleteOldBundleIfneeded(PATH)
|
|
208
129
|
if (isDeleted) {
|
|
209
130
|
sharedPrefs.putString(PATH, oldPath)
|
|
210
131
|
sharedPrefs.putString(PREVIOUS_PATH, "")
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
package com.otahotupdate
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.icu.text.SimpleDateFormat
|
|
5
|
+
import com.rnhotupdate.Common.PREVIOUS_PATH
|
|
6
|
+
import com.rnhotupdate.SharedPrefs
|
|
7
|
+
import java.io.File
|
|
8
|
+
import java.util.Date
|
|
9
|
+
import java.util.Locale
|
|
10
|
+
import java.util.zip.ZipFile
|
|
11
|
+
|
|
12
|
+
class Utils internal constructor(private val context: Context) {
|
|
13
|
+
|
|
14
|
+
fun deleteDirectory(directory: File): Boolean {
|
|
15
|
+
if (directory.isDirectory) {
|
|
16
|
+
// List all files and directories in the current directory
|
|
17
|
+
val files = directory.listFiles()
|
|
18
|
+
if (files != null) {
|
|
19
|
+
// Recursively delete all files and directories
|
|
20
|
+
for (file in files) {
|
|
21
|
+
if (!deleteDirectory(file)) {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Finally, delete the empty directory or file
|
|
28
|
+
return directory.delete()
|
|
29
|
+
}
|
|
30
|
+
fun deleteOldBundleIfneeded(pathKey: String?): Boolean {
|
|
31
|
+
val pathName = if (pathKey != null) pathKey else PREVIOUS_PATH
|
|
32
|
+
val sharedPrefs = SharedPrefs(context)
|
|
33
|
+
val path = sharedPrefs.getString(pathName)
|
|
34
|
+
val file = File(path)
|
|
35
|
+
if (file.exists() && file.isFile) {
|
|
36
|
+
val isDeleted = deleteDirectory(file.parentFile)
|
|
37
|
+
sharedPrefs.putString(pathName, "")
|
|
38
|
+
return isDeleted
|
|
39
|
+
} else {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun extractZipFile(
|
|
45
|
+
zipFile: File,extension: String
|
|
46
|
+
): String? {
|
|
47
|
+
return try {
|
|
48
|
+
val outputDir = zipFile.parentFile
|
|
49
|
+
val timestamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
|
|
50
|
+
var topLevelFolder: String? = null
|
|
51
|
+
var bundlePath: String? = null
|
|
52
|
+
ZipFile(zipFile).use { zip ->
|
|
53
|
+
zip.entries().asSequence().forEach { entry ->
|
|
54
|
+
zip.getInputStream(entry).use { input ->
|
|
55
|
+
if (topLevelFolder == null) {
|
|
56
|
+
// Get root folder of zip file after unzip
|
|
57
|
+
val parts = entry.name.split("/")
|
|
58
|
+
if (parts.size > 1) {
|
|
59
|
+
topLevelFolder = parts.first()
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
val outputFile = File(outputDir, entry.name)
|
|
63
|
+
if (entry.isDirectory) {
|
|
64
|
+
if (!outputFile.exists()) outputFile.mkdirs()
|
|
65
|
+
} else {
|
|
66
|
+
if (outputFile.parentFile?.exists() != true) outputFile.parentFile?.mkdirs()
|
|
67
|
+
outputFile.outputStream().use { output ->
|
|
68
|
+
input.copyTo(output)
|
|
69
|
+
}
|
|
70
|
+
if (outputFile.absolutePath.endsWith(extension)) {
|
|
71
|
+
bundlePath = outputFile.absolutePath
|
|
72
|
+
return@use // Exit early if found
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Rename the detected top-level folder
|
|
79
|
+
if (topLevelFolder != null) {
|
|
80
|
+
val extractedFolder = File(outputDir, topLevelFolder)
|
|
81
|
+
val renamedFolder = File(outputDir, "output_$timestamp")
|
|
82
|
+
if (extractedFolder.exists()) {
|
|
83
|
+
extractedFolder.renameTo(renamedFolder)
|
|
84
|
+
// Update bundlePath if the file was inside the renamed folder
|
|
85
|
+
bundlePath = bundlePath?.replace(extractedFolder.absolutePath, renamedFolder.absolutePath)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
bundlePath
|
|
89
|
+
} catch (e: Exception) {
|
|
90
|
+
e.printStackTrace()
|
|
91
|
+
null
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
package/ios/OtaHotUpdate.mm
CHANGED
|
@@ -1,10 +1,48 @@
|
|
|
1
1
|
#import "OtaHotUpdate.h"
|
|
2
2
|
#import <SSZipArchive/SSZipArchive.h>
|
|
3
|
+
static NSUncaughtExceptionHandler *previousHandler = NULL;
|
|
4
|
+
static BOOL isBeginning = YES;
|
|
3
5
|
@implementation OtaHotUpdate
|
|
4
6
|
RCT_EXPORT_MODULE()
|
|
5
7
|
|
|
8
|
+
|
|
9
|
+
- (instancetype)init {
|
|
10
|
+
self = [super init];
|
|
11
|
+
if (self) {
|
|
12
|
+
previousHandler = NSGetUncaughtExceptionHandler();
|
|
13
|
+
NSSetUncaughtExceptionHandler(&OTAExceptionHandler);
|
|
14
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
15
|
+
isBeginning = NO;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return self;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void OTAExceptionHandler(NSException *exception) {
|
|
22
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
23
|
+
if (isBeginning) {
|
|
24
|
+
NSString *oldPath = [defaults stringForKey:@"OLD_PATH"];
|
|
25
|
+
if (oldPath) {
|
|
26
|
+
BOOL isDeleted = [OtaHotUpdate removeBundleIfNeeded:@"PATH"];
|
|
27
|
+
if (isDeleted) {
|
|
28
|
+
[defaults setObject:oldPath forKey:@"PATH"];
|
|
29
|
+
[defaults removeObjectForKey:@"OLD_PATH"];
|
|
30
|
+
} else {
|
|
31
|
+
[defaults removeObjectForKey:@"OLD_PATH"];
|
|
32
|
+
[defaults removeObjectForKey:@"PATH"];
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
[defaults removeObjectForKey:@"PATH"];
|
|
36
|
+
}
|
|
37
|
+
[defaults removeObjectForKey:@"VERSION"];
|
|
38
|
+
[defaults synchronize];
|
|
39
|
+
} else if (previousHandler) {
|
|
40
|
+
previousHandler(exception);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
6
44
|
// Check if a file path is valid
|
|
7
|
-
|
|
45
|
+
+ (BOOL)isFilePathValid:(NSString *)path {
|
|
8
46
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
9
47
|
return [fileManager fileExistsAtPath:path];
|
|
10
48
|
}
|
|
@@ -19,7 +57,7 @@ RCT_EXPORT_MODULE()
|
|
|
19
57
|
}
|
|
20
58
|
return success;
|
|
21
59
|
}
|
|
22
|
-
|
|
60
|
+
+ (BOOL)deleteAllContentsOfParentDirectoryOfFile:(NSString *)filePath error:(NSError **)error {
|
|
23
61
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
24
62
|
|
|
25
63
|
// Get the parent directory of the file
|
|
@@ -66,12 +104,12 @@ RCT_EXPORT_MODULE()
|
|
|
66
104
|
return success;
|
|
67
105
|
}
|
|
68
106
|
|
|
69
|
-
|
|
107
|
+
+ (BOOL)removeBundleIfNeeded:(NSString *)pathKey {
|
|
70
108
|
NSString *keyToUse = pathKey ? pathKey : @"OLD_PATH";
|
|
71
109
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
72
110
|
NSString *retrievedString = [defaults stringForKey:keyToUse];
|
|
73
111
|
NSError *error = nil;
|
|
74
|
-
|
|
112
|
+
if (retrievedString && [self isFilePathValid:retrievedString]) {
|
|
75
113
|
BOOL isDeleted = [self deleteAllContentsOfParentDirectoryOfFile:retrievedString error:&error];
|
|
76
114
|
[defaults removeObjectForKey:keyToUse];
|
|
77
115
|
[defaults synchronize];
|
|
@@ -203,8 +241,8 @@ RCT_EXPORT_MODULE()
|
|
|
203
241
|
RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extension
|
|
204
242
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
205
243
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
206
|
-
if ([
|
|
207
|
-
[
|
|
244
|
+
if ([OtaHotUpdate isFilePathValid:path]) {
|
|
245
|
+
[OtaHotUpdate removeBundleIfNeeded:nil];
|
|
208
246
|
//Unzip file
|
|
209
247
|
NSString *extractedFilePath = [self unzipFileAtPath:path extension:(extension != nil) ? extension : @".jsbundle"];
|
|
210
248
|
if (extractedFilePath) {
|
|
@@ -216,6 +254,7 @@ RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extensi
|
|
|
216
254
|
[defaults setObject:extractedFilePath forKey:@"PATH"];
|
|
217
255
|
[defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"];
|
|
218
256
|
[defaults synchronize];
|
|
257
|
+
isBeginning = YES;
|
|
219
258
|
resolve(@(YES));
|
|
220
259
|
} else {
|
|
221
260
|
resolve(@(NO));
|
|
@@ -227,8 +266,8 @@ RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extensi
|
|
|
227
266
|
RCT_EXPORT_METHOD(deleteBundle:(double)i
|
|
228
267
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
229
268
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
230
|
-
BOOL isDeleted = [
|
|
231
|
-
BOOL isDeletedOld = [
|
|
269
|
+
BOOL isDeleted = [OtaHotUpdate removeBundleIfNeeded:@"PATH"];
|
|
270
|
+
BOOL isDeletedOld = [OtaHotUpdate removeBundleIfNeeded:nil];
|
|
232
271
|
if (isDeleted && isDeletedOld) {
|
|
233
272
|
resolve(@(YES));
|
|
234
273
|
} else {
|
|
@@ -241,8 +280,8 @@ RCT_EXPORT_METHOD(rollbackToPreviousBundle:(double)i
|
|
|
241
280
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
242
281
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
243
282
|
NSString *oldPath = [defaults stringForKey:@"OLD_PATH"];
|
|
244
|
-
if (oldPath && [
|
|
245
|
-
BOOL isDeleted = [
|
|
283
|
+
if (oldPath && [OtaHotUpdate isFilePathValid:oldPath]) {
|
|
284
|
+
BOOL isDeleted = [OtaHotUpdate removeBundleIfNeeded:@"PATH"];
|
|
246
285
|
if (isDeleted) {
|
|
247
286
|
[defaults setObject:oldPath forKey:@"PATH"];
|
|
248
287
|
[defaults removeObjectForKey:@"OLD_PATH"];
|
package/lib/commonjs/index.js
CHANGED
|
@@ -22,7 +22,8 @@ const RNhotupdate = OtaHotUpdateModule ? OtaHotUpdateModule : new Proxy({}, {
|
|
|
22
22
|
});
|
|
23
23
|
const downloadBundleFile = async (downloadManager, uri, headers, callback) => {
|
|
24
24
|
const res = await downloadManager.config({
|
|
25
|
-
fileCache: _reactNative.Platform.OS === 'android'
|
|
25
|
+
fileCache: _reactNative.Platform.OS === 'android',
|
|
26
|
+
path: !!downloadManager?.fs?.dirs?.LibraryDir && _reactNative.Platform.OS === 'ios' ? `${downloadManager.fs.dirs.LibraryDir}/${new Date().valueOf()}_hotupdate.zip` : undefined
|
|
26
27
|
}).fetch('GET', uri, {
|
|
27
28
|
...headers
|
|
28
29
|
}).progress((received, total) => {
|
|
@@ -94,12 +95,11 @@ async function downloadBundleUri(downloadManager, uri, version, option) {
|
|
|
94
95
|
if (!uri) {
|
|
95
96
|
return installFail(option, 'Please give a valid URL!');
|
|
96
97
|
}
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return installFail(option, 'Please give a bigger version than the current version, the current version now has setted by: ' + currentVersion);
|
|
98
|
+
if (version) {
|
|
99
|
+
const currentVersion = await getVersionAsNumber();
|
|
100
|
+
if (version <= currentVersion) {
|
|
101
|
+
return installFail(option, 'Please give a bigger version than the current version, the current version now has setted by: ' + currentVersion);
|
|
102
|
+
}
|
|
103
103
|
}
|
|
104
104
|
try {
|
|
105
105
|
const path = await downloadBundleFile(downloadManager, uri, option?.headers, option?.progress);
|
|
@@ -110,7 +110,9 @@ async function downloadBundleUri(downloadManager, uri, version, option) {
|
|
|
110
110
|
if (!success) {
|
|
111
111
|
return installFail(option);
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
if (version) {
|
|
114
|
+
setCurrentVersion(version);
|
|
115
|
+
}
|
|
114
116
|
if (option?.metadata) {
|
|
115
117
|
setUpdateMetadata(option.metadata);
|
|
116
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_index","_interopRequireDefault","e","__esModule","default","LINKING_ERROR","Platform","select","ios","isTurboModuleEnabled","global","__turboModuleProxy","OtaHotUpdateModule","NativeModules","OtaHotUpdate","RNhotupdate","Proxy","get","Error","downloadBundleFile","downloadManager","uri","headers","callback","res","config","fileCache","OS","fetch","progress","received","total","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_index","_interopRequireDefault","e","__esModule","default","LINKING_ERROR","Platform","select","ios","isTurboModuleEnabled","global","__turboModuleProxy","OtaHotUpdateModule","NativeModules","OtaHotUpdate","RNhotupdate","Proxy","get","Error","downloadBundleFile","downloadManager","uri","headers","callback","res","config","fileCache","OS","path","fs","dirs","LibraryDir","Date","valueOf","undefined","fetch","progress","received","total","setupBundlePath","extension","setupExactBundlePath","setExactBundlePath","deleteBundlePath","deleteBundle","getCurrentVersion","getUpdateMetadata","then","metadataString","JSON","parse","error","Promise","reject","rollbackToPreviousBundle","getVersionAsNumber","rawVersion","setCurrentVersion","version","setUpdateMetadata","metadata","stringify","resetApp","restart","removeBundle","restartAfterRemoved","data","setTimeout","installFail","option","updateFail","console","downloadBundleUri","currentVersion","success","extensionBundle","updateSuccess","restartAfterInstall","restartDelay","checkForGitUpdate","options","url","bundlePath","branch","all","git","getConfig","getBranchName","pull","pullUpdate","onProgress","folderName","onPullSuccess","onPullFailed","msg","clone","cloneRepo","bundle","onCloneSuccess","onCloneFailed","toString","onFinishProgress","_default","exports","removeUpdate","removeGitUpdate","folder"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAyB,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEzB,MAAMG,aAAa,GACjB,sFAAsF,GACtFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMK,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,kBAAkB,GAAGH,oBAAoB,GAC3CV,OAAO,CAAC,sBAAsB,CAAC,CAACK,OAAO,GACvCS,0BAAa,CAACC,YAAY;AAE9B,MAAMC,WAAW,GAAGH,kBAAkB,GAClCA,kBAAkB,GAClB,IAAII,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CA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":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -17,7 +17,8 @@ const RNhotupdate = OtaHotUpdateModule ? OtaHotUpdateModule : new Proxy({}, {
|
|
|
17
17
|
});
|
|
18
18
|
const downloadBundleFile = async (downloadManager, uri, headers, callback) => {
|
|
19
19
|
const res = await downloadManager.config({
|
|
20
|
-
fileCache: Platform.OS === 'android'
|
|
20
|
+
fileCache: Platform.OS === 'android',
|
|
21
|
+
path: !!downloadManager?.fs?.dirs?.LibraryDir && Platform.OS === 'ios' ? `${downloadManager.fs.dirs.LibraryDir}/${new Date().valueOf()}_hotupdate.zip` : undefined
|
|
21
22
|
}).fetch('GET', uri, {
|
|
22
23
|
...headers
|
|
23
24
|
}).progress((received, total) => {
|
|
@@ -89,12 +90,11 @@ async function downloadBundleUri(downloadManager, uri, version, option) {
|
|
|
89
90
|
if (!uri) {
|
|
90
91
|
return installFail(option, 'Please give a valid URL!');
|
|
91
92
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return installFail(option, 'Please give a bigger version than the current version, the current version now has setted by: ' + currentVersion);
|
|
93
|
+
if (version) {
|
|
94
|
+
const currentVersion = await getVersionAsNumber();
|
|
95
|
+
if (version <= currentVersion) {
|
|
96
|
+
return installFail(option, 'Please give a bigger version than the current version, the current version now has setted by: ' + currentVersion);
|
|
97
|
+
}
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
100
|
const path = await downloadBundleFile(downloadManager, uri, option?.headers, option?.progress);
|
|
@@ -105,7 +105,9 @@ async function downloadBundleUri(downloadManager, uri, version, option) {
|
|
|
105
105
|
if (!success) {
|
|
106
106
|
return installFail(option);
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
if (version) {
|
|
109
|
+
setCurrentVersion(version);
|
|
110
|
+
}
|
|
109
111
|
if (option?.metadata) {
|
|
110
112
|
setUpdateMetadata(option.metadata);
|
|
111
113
|
}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","git","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","OtaHotUpdateModule","require","OtaHotUpdate","RNhotupdate","Proxy","get","Error","downloadBundleFile","downloadManager","uri","headers","callback","res","config","fileCache","OS","fetch","progress","received","total","
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","git","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","OtaHotUpdateModule","require","OtaHotUpdate","RNhotupdate","Proxy","get","Error","downloadBundleFile","downloadManager","uri","headers","callback","res","config","fileCache","OS","path","fs","dirs","LibraryDir","Date","valueOf","undefined","fetch","progress","received","total","setupBundlePath","extension","setupExactBundlePath","setExactBundlePath","deleteBundlePath","deleteBundle","getCurrentVersion","getUpdateMetadata","then","metadataString","JSON","parse","error","Promise","reject","rollbackToPreviousBundle","getVersionAsNumber","rawVersion","setCurrentVersion","version","setUpdateMetadata","metadata","stringify","resetApp","restart","removeBundle","restartAfterRemoved","data","setTimeout","installFail","option","e","updateFail","console","downloadBundleUri","currentVersion","success","extensionBundle","updateSuccess","restartAfterInstall","restartDelay","checkForGitUpdate","options","url","bundlePath","branch","all","getConfig","getBranchName","pull","pullUpdate","onProgress","folderName","onPullSuccess","onPullFailed","msg","clone","cloneRepo","bundle","onCloneSuccess","onCloneFailed","toString","onFinishProgress","removeUpdate","removeGitUpdate","folder"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAGtD,OAAOC,GAAG,MAAM,iBAAQ;AAExB,MAAMC,aAAa,GACjB,sFAAsF,GACtFF,QAAQ,CAACG,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,I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;IACjB,GAAG5E,GAAG;IACNmG,eAAe,EAAGC,MAAe,IAAK;MACpCzF,WAAW,CAAC2B,kBAAkB,CAAC,EAAE,CAAC;MAClCtC,GAAG,CAACmG,eAAe,CAACC,MAAM,CAAC;IAC7B;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -9,7 +9,7 @@ declare function setCurrentVersion(version: number): Promise<boolean>;
|
|
|
9
9
|
declare function setUpdateMetadata(metadata: any): Promise<boolean>;
|
|
10
10
|
declare function resetApp(): Promise<void>;
|
|
11
11
|
declare function removeBundle(restartAfterRemoved?: boolean): void;
|
|
12
|
-
declare function downloadBundleUri(downloadManager: DownloadManager, uri: string, version
|
|
12
|
+
declare function downloadBundleUri(downloadManager: DownloadManager, uri: string, version?: number, option?: UpdateOption): Promise<void>;
|
|
13
13
|
declare const _default: {
|
|
14
14
|
setupBundlePath: typeof setupBundlePath;
|
|
15
15
|
setupExactBundlePath: typeof setupExactBundlePath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAgD5D,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3E;AACD,iBAAS,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5D;AAOD,iBAAS,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASnD;AACD,iBAAS,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC,CAEpD;AACD,iBAAe,kBAAkB,oBAGhC;AACD,iBAAS,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5D;AACD,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1D;AACD,iBAAe,QAAQ,kBAEtB;AACD,iBAAS,YAAY,CAAC,mBAAmB,CAAC,EAAE,OAAO,QAWlD;AAKD,iBAAe,iBAAiB,CAC9B,eAAe,EAAE,eAAe,EAChC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,YAAY,iBA+CtB;;;;;;;;;;;;;mCAkE8B,MAAM;;;;;;;;;;;;;;;;oBAlNX,CAAC;iBAEd,CAAC;;;qCA+I4B,eAAe;;;AAmDzD,wBAmBE"}
|
|
@@ -9,7 +9,7 @@ declare function setCurrentVersion(version: number): Promise<boolean>;
|
|
|
9
9
|
declare function setUpdateMetadata(metadata: any): Promise<boolean>;
|
|
10
10
|
declare function resetApp(): Promise<void>;
|
|
11
11
|
declare function removeBundle(restartAfterRemoved?: boolean): void;
|
|
12
|
-
declare function downloadBundleUri(downloadManager: DownloadManager, uri: string, version
|
|
12
|
+
declare function downloadBundleUri(downloadManager: DownloadManager, uri: string, version?: number, option?: UpdateOption): Promise<void>;
|
|
13
13
|
declare const _default: {
|
|
14
14
|
setupBundlePath: typeof setupBundlePath;
|
|
15
15
|
setupExactBundlePath: typeof setupExactBundlePath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAgD5D,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3E;AACD,iBAAS,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5D;AAOD,iBAAS,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASnD;AACD,iBAAS,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC,CAEpD;AACD,iBAAe,kBAAkB,oBAGhC;AACD,iBAAS,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5D;AACD,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAO1D;AACD,iBAAe,QAAQ,kBAEtB;AACD,iBAAS,YAAY,CAAC,mBAAmB,CAAC,EAAE,OAAO,QAWlD;AAKD,iBAAe,iBAAiB,CAC9B,eAAe,EAAE,eAAe,EAChC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,YAAY,iBA+CtB;;;;;;;;;;;;;mCAkE8B,MAAM;;;;;;;;;;;;;;;;oBAlNX,CAAC;iBAEd,CAAC;;;qCA+I4B,eAAe;;;AAmDzD,wBAmBE"}
|
package/package.json
CHANGED
package/plugin/build/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const withAndroidAction = (config) => {
|
|
|
6
6
|
config.modResults.contents = config.modResults.contents.replace(/override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED/g, `
|
|
7
7
|
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
8
8
|
|
|
9
|
-
override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS`);
|
|
9
|
+
override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`);
|
|
10
10
|
config.modResults.contents = config.modResults.contents.replace(/import expo.modules.ReactNativeHostWrapper/g, `
|
|
11
11
|
import expo.modules.ReactNativeHostWrapper
|
|
12
12
|
import com.otahotupdate.OtaHotUpdate`);
|
package/plugin/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ const withAndroidAction: any = (config: any) => {
|
|
|
6
6
|
`
|
|
7
7
|
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
8
8
|
|
|
9
|
-
override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS`
|
|
9
|
+
override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`
|
|
10
10
|
);
|
|
11
11
|
config.modResults.contents = config.modResults.contents.replace(
|
|
12
12
|
/import expo.modules.ReactNativeHostWrapper/g,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/index.ts"],"version":"5.7.2"}
|
|
1
|
+
{"root":["./src/index.ts"],"version":"5.7.2"}
|
package/react-native.config.js
CHANGED
package/src/index.tsx
CHANGED
|
@@ -36,6 +36,7 @@ const downloadBundleFile = async (
|
|
|
36
36
|
const res = await downloadManager
|
|
37
37
|
.config({
|
|
38
38
|
fileCache: Platform.OS === 'android',
|
|
39
|
+
path: !!downloadManager?.fs?.dirs?.LibraryDir && Platform.OS === 'ios' ? `${downloadManager.fs.dirs.LibraryDir}/${new Date().valueOf()}_hotupdate.zip` : undefined
|
|
39
40
|
})
|
|
40
41
|
.fetch('GET', uri, {
|
|
41
42
|
...headers,
|
|
@@ -109,23 +110,21 @@ const installFail = (option?: UpdateOption, e?: any) => {
|
|
|
109
110
|
async function downloadBundleUri(
|
|
110
111
|
downloadManager: DownloadManager,
|
|
111
112
|
uri: string,
|
|
112
|
-
version
|
|
113
|
+
version?: number,
|
|
113
114
|
option?: UpdateOption
|
|
114
115
|
) {
|
|
115
116
|
if (!uri) {
|
|
116
117
|
return installFail(option, 'Please give a valid URL!');
|
|
117
118
|
}
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return installFail(
|
|
125
|
-
option,
|
|
126
|
-
'Please give a bigger version than the current version, the current version now has setted by: ' +
|
|
119
|
+
if (version) {
|
|
120
|
+
const currentVersion = await getVersionAsNumber();
|
|
121
|
+
if (version <= currentVersion) {
|
|
122
|
+
return installFail(
|
|
123
|
+
option,
|
|
124
|
+
'Please give a bigger version than the current version, the current version now has setted by: ' +
|
|
127
125
|
currentVersion
|
|
128
|
-
|
|
126
|
+
);
|
|
127
|
+
}
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
try {
|
|
@@ -135,7 +134,6 @@ async function downloadBundleUri(
|
|
|
135
134
|
option?.headers,
|
|
136
135
|
option?.progress
|
|
137
136
|
);
|
|
138
|
-
|
|
139
137
|
if (!path) {
|
|
140
138
|
return installFail(option);
|
|
141
139
|
}
|
|
@@ -144,8 +142,9 @@ async function downloadBundleUri(
|
|
|
144
142
|
if (!success) {
|
|
145
143
|
return installFail(option);
|
|
146
144
|
}
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
if (version) {
|
|
146
|
+
setCurrentVersion(version);
|
|
147
|
+
}
|
|
149
148
|
if (option?.metadata) {
|
|
150
149
|
setUpdateMetadata(option.metadata);
|
|
151
150
|
}
|