mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-08 20:08:06 +02:00
support for sending/receiving multiple events from external signer
This commit is contained in:
parent
ad52855f5a
commit
8a18781048
@ -5,10 +5,13 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.util.LruCache
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.vitorpamplona.quartz.encoders.HexKey
|
||||
import com.vitorpamplona.quartz.events.EventInterface
|
||||
import com.vitorpamplona.quartz.events.LnZapRequestEvent
|
||||
|
||||
|
||||
enum class SignerType {
|
||||
SIGN_EVENT,
|
||||
NIP04_ENCRYPT,
|
||||
@ -28,6 +31,15 @@ class Permission(
|
||||
}
|
||||
}
|
||||
|
||||
class Result(
|
||||
@JsonProperty("package")
|
||||
val `package`: String?,
|
||||
@JsonProperty("signature")
|
||||
val signature: String?,
|
||||
@JsonProperty("id")
|
||||
val id: String?
|
||||
)
|
||||
|
||||
class ExternalSignerLauncher(
|
||||
private val npub: String,
|
||||
val signerPackageName: String = "com.greenart7c3.nostrsigner"
|
||||
@ -57,16 +69,36 @@ class ExternalSignerLauncher(
|
||||
}
|
||||
|
||||
fun newResult(data: Intent) {
|
||||
val signature = data.getStringExtra("signature") ?: ""
|
||||
val packageName = data.getStringExtra("package") ?: ""
|
||||
val id = data.getStringExtra("id") ?: ""
|
||||
if (id.isNotBlank()) {
|
||||
val result = if (packageName.isNotBlank()) "$signature-$packageName" else signature
|
||||
contentCache.get(id)?.invoke(result)
|
||||
val results = data.getStringExtra("results")
|
||||
if (results != null) {
|
||||
val objectMapper = ObjectMapper()
|
||||
val localResults: Array<Result> = objectMapper.readValue(
|
||||
results,
|
||||
Array<Result>::class.java
|
||||
)
|
||||
|
||||
localResults.forEach {
|
||||
val signature = it.signature ?: ""
|
||||
val packageName = it.`package` ?: ""
|
||||
val id = it.id ?: ""
|
||||
if (id.isNotBlank()) {
|
||||
val result = if (packageName.isNotBlank()) "$signature-$packageName" else signature
|
||||
val contentCache = contentCache.get(id)
|
||||
contentCache?.invoke(result)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val signature = data.getStringExtra("signature") ?: ""
|
||||
val packageName = data.getStringExtra("package") ?: ""
|
||||
val id = data.getStringExtra("id") ?: ""
|
||||
if (id.isNotBlank()) {
|
||||
val result = if (packageName.isNotBlank()) "$signature-$packageName" else signature
|
||||
val contentCache = contentCache.get(id)
|
||||
contentCache?.invoke(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun openSignerApp(
|
||||
data: String,
|
||||
type: SignerType,
|
||||
@ -145,6 +177,8 @@ class ExternalSignerLauncher(
|
||||
intent.`package` = signerPackageName
|
||||
}
|
||||
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
|
||||
contentCache.put(id, onReady)
|
||||
|
||||
intentLauncher(intent)
|
||||
|
Loading…
x
Reference in New Issue
Block a user