From bea7e82c264db9dc66d920bd6f49996702db9223 Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Wed, 13 Mar 2024 10:55:56 +0100 Subject: [PATCH] Move setLogStream and connect into a thread to prevent UI lock --- Cargo.toml | 2 +- src/gen_kotlin/templates/module.kt | 38 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index baeef01..5553915 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "breez-sdk-rn-generator" -version = "0.0.12" +version = "0.0.13" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/gen_kotlin/templates/module.kt b/src/gen_kotlin/templates/module.kt index ba26993..a5196e9 100644 --- a/src/gen_kotlin/templates/module.kt +++ b/src/gen_kotlin/templates/module.kt @@ -63,14 +63,16 @@ class BreezSDKModule(reactContext: ReactApplicationContext) : ReactContextBaseJa {%- endfor %} @ReactMethod fun setLogStream(promise: Promise) { - try { - val emitter = reactApplicationContext.getJSModule(RCTDeviceEventEmitter::class.java) - - setLogStream(BreezSDKLogStream(emitter)) - promise.resolve(readableMapOf("status" to "ok")) - } catch (e: Exception) { - e.printStackTrace() - promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) + executor.execute { + try { + val emitter = reactApplicationContext.getJSModule(RCTDeviceEventEmitter::class.java) + + setLogStream(BreezSDKLogStream(emitter)) + promise.resolve(readableMapOf("status" to "ok")) + } catch (e: Exception) { + e.printStackTrace() + promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) + } } } @@ -81,17 +83,19 @@ class BreezSDKModule(reactContext: ReactApplicationContext) : ReactContextBaseJa return } - try { - val connectRequest = asConnectRequest(req) ?: run { throw SdkException.Generic(errMissingMandatoryField("req", "ConnectRequest")) } - val emitter = reactApplicationContext.getJSModule(RCTDeviceEventEmitter::class.java) + executor.execute { + try { + val connectRequest = asConnectRequest(req) ?: run { throw SdkException.Generic(errMissingMandatoryField("req", "ConnectRequest")) } + val emitter = reactApplicationContext.getJSModule(RCTDeviceEventEmitter::class.java) - ensureWorkingDir(connectRequest.config.workingDir) + ensureWorkingDir(connectRequest.config.workingDir) - breezServices = connect(connectRequest, BreezSDKListener(emitter)) - promise.resolve(readableMapOf("status" to "ok")) - } catch (e: Exception) { - e.printStackTrace() - promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) + breezServices = connect(connectRequest, BreezSDKListener(emitter)) + promise.resolve(readableMapOf("status" to "ok")) + } catch (e: Exception) { + e.printStackTrace() + promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e) + } } } {%- include "Objects.kt" %}