react-native-ota-hot-update 2.2.52 → 2.2.53

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,29 +13,18 @@ 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
22
16
  import java.io.File
23
17
 
24
18
  class OtaHotUpdateModule internal constructor(context: ReactApplicationContext) :
25
19
  OtaHotUpdateSpec(context) {
26
20
  private val utils: Utils = Utils(context)
27
- private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
28
-
29
21
  override fun getName(): String {
30
22
  return NAME
31
23
  }
32
24
 
33
- override fun invalidate() {
34
- super.invalidate()
35
- scope.cancel()
36
- }
37
25
 
38
- private fun processBundleFile(path: String?, extension: String?): Boolean {
26
+ @ReactMethod
27
+ override fun setupBundlePath(path: String?, extension: String?, promise: Promise) {
39
28
  if (path != null) {
40
29
  val file = File(path)
41
30
  if (file.exists() && file.isFile) {
@@ -45,7 +34,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
45
34
  utils.deleteOldBundleIfneeded(null)
46
35
  val sharedPrefs = SharedPrefs(reactApplicationContext)
47
36
  val oldPath = sharedPrefs.getString(PATH)
48
- if (!oldPath.isNullOrEmpty()) {
37
+ if (!oldPath.equals("")) {
49
38
  sharedPrefs.putString(PREVIOUS_PATH, oldPath)
50
39
  }
51
40
  sharedPrefs.putString(PATH, fileUnzip)
@@ -53,31 +42,16 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
53
42
  CURRENT_VERSION_CODE,
54
43
  reactApplicationContext.getVersionCode()
55
44
  )
56
- return true
45
+ promise.resolve(true)
57
46
  } else {
58
47
  file.delete()
59
- throw Exception("File unzip failed or path is invalid: $file")
48
+ promise.reject("E_UNZIP_FAIL", "File unzip failed or path is invalid file: $file")
60
49
  }
61
50
  } else {
62
- throw Exception("File not exist: $file")
51
+ promise.reject("E_INVALID_PATH", "File not exist: $file")
63
52
  }
64
53
  } else {
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
- }
54
+ promise.reject("E_INVALID_PATH", "File not exist: $path")
81
55
  }
82
56
  }
83
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "2.2.52",
3
+ "version": "2.2.53",
4
4
  "description": "Hot update for react native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",