@onekeyfe/react-native-background-thread 1.1.50 → 1.1.51

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.
@@ -253,30 +253,45 @@ class BackgroundThreadManager private constructor() {
253
253
  * @throws IllegalStateException if background runtime is not started
254
254
  * @throws IllegalArgumentException if segment file does not exist
255
255
  */
256
- fun registerSegmentInBackground(segmentId: Int, path: String) {
256
+ /**
257
+ * Register a HBC segment in the background runtime with completion callback.
258
+ * Dispatches to the background JS queue thread and invokes the callback
259
+ * only after registerSegment has actually executed.
260
+ *
261
+ * @param segmentId The segment ID to register
262
+ * @param path Absolute file path to the .seg.hbc file
263
+ * @param onComplete Called with null on success, or an Exception on failure
264
+ */
265
+ fun registerSegmentInBackground(segmentId: Int, path: String, onComplete: (Exception?) -> Unit) {
257
266
  if (!isStarted) {
258
- throw IllegalStateException("Background runtime not started")
267
+ onComplete(IllegalStateException("Background runtime not started"))
268
+ return
259
269
  }
260
270
 
261
271
  val file = File(path)
262
272
  if (!file.exists()) {
263
- throw IllegalArgumentException("Segment file not found: $path")
273
+ onComplete(IllegalArgumentException("Segment file not found: $path"))
274
+ return
264
275
  }
265
276
 
266
277
  val context = bgReactHost?.currentReactContext
267
- ?: throw IllegalStateException("Background ReactContext not available")
278
+ if (context == null) {
279
+ onComplete(IllegalStateException("Background ReactContext not available"))
280
+ return
281
+ }
268
282
 
269
283
  context.runOnJSQueueThread {
270
284
  try {
271
285
  if (context.hasCatalystInstance()) {
272
286
  context.catalystInstance.registerSegment(segmentId, path)
273
287
  BTLogger.info("Segment registered in background runtime: id=$segmentId, path=$path")
288
+ onComplete(null)
274
289
  } else {
275
- BTLogger.error("Background CatalystInstance not available for segment registration")
290
+ onComplete(IllegalStateException("Background CatalystInstance not available for segment registration"))
276
291
  }
277
292
  } catch (e: Exception) {
278
293
  BTLogger.error("Failed to register segment in background runtime: ${e.message}")
279
- throw e
294
+ onComplete(e)
280
295
  }
281
296
  }
282
297
  }
@@ -29,12 +29,13 @@ class BackgroundThreadModule(reactContext: ReactApplicationContext) :
29
29
  }
30
30
 
31
31
  override fun loadSegmentInBackground(segmentId: Double, path: String, promise: Promise) {
32
- try {
33
- BackgroundThreadManager.getInstance()
34
- .registerSegmentInBackground(segmentId.toInt(), path)
35
- promise.resolve(null)
36
- } catch (e: Exception) {
37
- promise.reject("BG_SEGMENT_LOAD_ERROR", e.message, e)
38
- }
32
+ BackgroundThreadManager.getInstance()
33
+ .registerSegmentInBackground(segmentId.toInt(), path) { error ->
34
+ if (error != null) {
35
+ promise.reject("BG_SEGMENT_LOAD_ERROR", error.message, error)
36
+ } else {
37
+ promise.resolve(null)
38
+ }
39
+ }
39
40
  }
40
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-background-thread",
3
- "version": "1.1.50",
3
+ "version": "1.1.51",
4
4
  "description": "react-native-background-thread",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",