react-native-ota-hot-update 2.2.51 → 2.2.52
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.
|
@@ -13,28 +13,39 @@ 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) {
|
|
31
|
-
utils.deleteOldBundleIfneeded(null)
|
|
32
42
|
val fileUnzip = utils.extractZipFile(file, extension ?: ".bundle")
|
|
33
43
|
if (fileUnzip != null) {
|
|
34
44
|
file.delete()
|
|
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
|
|
|
@@ -31,14 +31,15 @@ class Utils internal constructor(private val context: Context) {
|
|
|
31
31
|
val pathName = if (pathKey != null) pathKey else PREVIOUS_PATH
|
|
32
32
|
val sharedPrefs = SharedPrefs(context)
|
|
33
33
|
val path = sharedPrefs.getString(pathName)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
if (!path.isNullOrEmpty()) {
|
|
35
|
+
val file = File(path)
|
|
36
|
+
if (file.exists() && file.isFile) {
|
|
37
|
+
val isDeleted = deleteDirectory(file.parentFile)
|
|
38
|
+
sharedPrefs.putString(pathName, "")
|
|
39
|
+
return isDeleted
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
|
+
return false
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
fun extractZipFile(
|