react-native-ota-hot-update 2.2.53 → 2.2.71
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/android/build.gradle +2 -0
- package/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt +3 -2
- package/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt +39 -13
- package/android/src/main/java/com/otahotupdate/Utils.kt +12 -8
- package/ios/OtaHotUpdate.modulemap +6 -0
- package/package.json +1 -1
- package/react-native-ota-hot-update.podspec +5 -0
package/android/build.gradle
CHANGED
|
@@ -116,6 +116,8 @@ dependencies {
|
|
|
116
116
|
implementation "com.facebook.react:react-native:+"
|
|
117
117
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
118
118
|
implementation 'com.jakewharton:process-phoenix:3.0.0'
|
|
119
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
|
|
120
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
if (isNewArchitectureEnabled()) {
|
|
@@ -3,7 +3,7 @@ package com.otahotupdate
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.content.pm.PackageManager
|
|
5
5
|
import android.os.Build
|
|
6
|
-
import com.facebook.react.
|
|
6
|
+
import com.facebook.react.TurboReactPackage
|
|
7
7
|
import com.facebook.react.bridge.NativeModule
|
|
8
8
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
9
9
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
@@ -15,7 +15,7 @@ import com.rnhotupdate.Common.VERSION
|
|
|
15
15
|
import com.rnhotupdate.SharedPrefs
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
class OtaHotUpdate :
|
|
18
|
+
class OtaHotUpdate : TurboReactPackage() {
|
|
19
19
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
20
20
|
return if (name == OtaHotUpdateModule.NAME) {
|
|
21
21
|
OtaHotUpdateModule(reactContext)
|
|
@@ -33,6 +33,7 @@ class OtaHotUpdate : BaseReactPackage() {
|
|
|
33
33
|
OtaHotUpdateModule.NAME,
|
|
34
34
|
false, // canOverrideExistingModule
|
|
35
35
|
false, // needsEagerInit
|
|
36
|
+
true, // hasConstants
|
|
36
37
|
false, // isCxxModule
|
|
37
38
|
isTurboModule // isTurboModule
|
|
38
39
|
)
|
|
@@ -13,18 +13,29 @@ import com.rnhotupdate.Common.VERSION
|
|
|
13
13
|
import com.rnhotupdate.Common.PREVIOUS_VERSION
|
|
14
14
|
import com.rnhotupdate.Common.METADATA
|
|
15
15
|
import com.rnhotupdate.SharedPrefs
|
|
16
|
+
import kotlinx.coroutines.CoroutineScope
|
|
17
|
+
import kotlinx.coroutines.Dispatchers
|
|
18
|
+
import kotlinx.coroutines.SupervisorJob
|
|
19
|
+
import kotlinx.coroutines.cancel
|
|
20
|
+
import kotlinx.coroutines.launch
|
|
21
|
+
import kotlinx.coroutines.withContext
|
|
16
22
|
import java.io.File
|
|
17
23
|
|
|
18
24
|
class OtaHotUpdateModule internal constructor(context: ReactApplicationContext) :
|
|
19
25
|
OtaHotUpdateSpec(context) {
|
|
20
26
|
private val utils: Utils = Utils(context)
|
|
27
|
+
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
|
28
|
+
|
|
21
29
|
override fun getName(): String {
|
|
22
30
|
return NAME
|
|
23
31
|
}
|
|
24
32
|
|
|
33
|
+
override fun invalidate() {
|
|
34
|
+
super.invalidate()
|
|
35
|
+
scope.cancel()
|
|
36
|
+
}
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
override fun setupBundlePath(path: String?, extension: String?, promise: Promise) {
|
|
38
|
+
private fun processBundleFile(path: String?, extension: String?): Boolean {
|
|
28
39
|
if (path != null) {
|
|
29
40
|
val file = File(path)
|
|
30
41
|
if (file.exists() && file.isFile) {
|
|
@@ -34,7 +45,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
34
45
|
utils.deleteOldBundleIfneeded(null)
|
|
35
46
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
36
47
|
val oldPath = sharedPrefs.getString(PATH)
|
|
37
|
-
if (!oldPath.
|
|
48
|
+
if (!oldPath.isNullOrEmpty()) {
|
|
38
49
|
sharedPrefs.putString(PREVIOUS_PATH, oldPath)
|
|
39
50
|
}
|
|
40
51
|
sharedPrefs.putString(PATH, fileUnzip)
|
|
@@ -42,16 +53,31 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
42
53
|
CURRENT_VERSION_CODE,
|
|
43
54
|
reactApplicationContext.getVersionCode()
|
|
44
55
|
)
|
|
45
|
-
|
|
56
|
+
return true
|
|
46
57
|
} else {
|
|
47
58
|
file.delete()
|
|
48
|
-
|
|
59
|
+
throw Exception("File unzip failed or path is invalid: $file")
|
|
49
60
|
}
|
|
50
61
|
} else {
|
|
51
|
-
|
|
62
|
+
throw Exception("File not exist: $file")
|
|
52
63
|
}
|
|
53
64
|
} else {
|
|
54
|
-
|
|
65
|
+
throw Exception("Invalid path: $path")
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
@ReactMethod
|
|
69
|
+
override fun setupBundlePath(path: String?, extension: String?, promise: Promise) {
|
|
70
|
+
scope.launch {
|
|
71
|
+
try {
|
|
72
|
+
val result = processBundleFile(path, extension)
|
|
73
|
+
withContext(Dispatchers.Main) {
|
|
74
|
+
promise.resolve(result)
|
|
75
|
+
}
|
|
76
|
+
} catch (e: Exception) {
|
|
77
|
+
withContext(Dispatchers.Main) {
|
|
78
|
+
promise.reject("SET_ERROR", e)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
55
81
|
}
|
|
56
82
|
}
|
|
57
83
|
|
|
@@ -87,7 +113,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
87
113
|
|
|
88
114
|
val currentVersion = sharedPrefs.getString(VERSION)
|
|
89
115
|
if (currentVersion != "" && currentVersion != version) {
|
|
90
|
-
|
|
116
|
+
sharedPrefs.putString(PREVIOUS_VERSION, currentVersion)
|
|
91
117
|
}
|
|
92
118
|
|
|
93
119
|
sharedPrefs.putString(VERSION, version)
|
|
@@ -99,9 +125,9 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
99
125
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
100
126
|
val metadata = sharedPrefs.getString(METADATA)
|
|
101
127
|
if (metadata != "") {
|
|
102
|
-
|
|
128
|
+
promise.resolve(metadata);
|
|
103
129
|
} else {
|
|
104
|
-
|
|
130
|
+
promise.resolve(null);
|
|
105
131
|
}
|
|
106
132
|
}
|
|
107
133
|
|
|
@@ -137,10 +163,10 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
137
163
|
sharedPrefs.putString(PREVIOUS_PATH, "")
|
|
138
164
|
|
|
139
165
|
if (previousVersion != "") {
|
|
140
|
-
|
|
141
|
-
|
|
166
|
+
sharedPrefs.putString(VERSION, previousVersion)
|
|
167
|
+
sharedPrefs.putString(PREVIOUS_VERSION, "")
|
|
142
168
|
} else {
|
|
143
|
-
|
|
169
|
+
sharedPrefs.putString(VERSION, "")
|
|
144
170
|
}
|
|
145
171
|
|
|
146
172
|
promise.resolve(true)
|
|
@@ -28,15 +28,19 @@ class Utils internal constructor(private val context: Context) {
|
|
|
28
28
|
return directory.delete()
|
|
29
29
|
}
|
|
30
30
|
fun deleteOldBundleIfneeded(pathKey: String?): Boolean {
|
|
31
|
-
val pathName =
|
|
31
|
+
val pathName = pathKey ?: PREVIOUS_PATH
|
|
32
32
|
val sharedPrefs = SharedPrefs(context)
|
|
33
|
-
val
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
val bundlePath = sharedPrefs.getString(pathName)
|
|
34
|
+
|
|
35
|
+
if (!bundlePath.isNullOrEmpty()) {
|
|
36
|
+
val bundleFile = File(bundlePath)
|
|
37
|
+
if (bundleFile.exists() && bundleFile.isFile) {
|
|
38
|
+
val outputFolder = bundleFile.parentFile
|
|
39
|
+
if (outputFolder != null && outputFolder.exists() && outputFolder.isDirectory) {
|
|
40
|
+
val isDeleted = deleteDirectory(outputFolder)
|
|
41
|
+
sharedPrefs.putString(pathName, "")
|
|
42
|
+
return isDeleted
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
return false
|
package/package.json
CHANGED
|
@@ -13,7 +13,12 @@ Pod::Spec.new do |s|
|
|
|
13
13
|
|
|
14
14
|
s.platforms = { :ios => min_ios_version_supported }
|
|
15
15
|
s.source = { :git => "https://github.com/vantuan88291/react-native-ota-hot-update.git", :tag => "#{s.version}" }
|
|
16
|
+
s.pod_target_xcconfig = {
|
|
17
|
+
'SWIFT_VERSION' => '5.0',
|
|
18
|
+
'DEFINES_MODULE' => 'YES'
|
|
19
|
+
}
|
|
16
20
|
|
|
21
|
+
s.module_map = 'ios/OtaHotUpdate.modulemap'
|
|
17
22
|
s.source_files = "ios/**/*.{h,m,mm,cpp}"
|
|
18
23
|
s.dependency 'SSZipArchive', '~> 2.4.3'
|
|
19
24
|
if ENV['RCT_NEW_ARCH_ENABLED'] == '0'
|