Skip to content

Commit

Permalink
Merge pull request #22 from breez/savage-connect-lock-fix
Browse files Browse the repository at this point in the history
Prevent UI thread lock on calling connect
  • Loading branch information
dangeross authored Mar 13, 2024
2 parents 1b0eb85 + bea7e82 commit 59b4ba2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 21 additions & 17 deletions src/gen_kotlin/templates/module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand All @@ -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" %}
Expand Down

0 comments on commit 59b4ba2

Please sign in to comment.