This commit is contained in:
2026-06-12 10:21:56 +07:00
parent 28550f8e25
commit 8e7a1e6d7c
3 changed files with 23 additions and 23 deletions

View File

@@ -61,7 +61,7 @@ class AndroidExternalSigner(
): String? { ): String? {
// Try Content Resolver first // Try Content Resolver first
queryContentResolver(type, payload, pubkey, currentUser)?.let { queryContentResolver(type, payload, pubkey, currentUser)?.let {
return it.result return if (resultKey == "event") it.event else it.result
} }
// Fall back to Intent // Fall back to Intent

View File

@@ -4,22 +4,29 @@ import android.content.Intent
import androidx.activity.result.ActivityResult import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
class ExternalSignerLauncher { class ExternalSignerLauncher {
private var launcher: ActivityResultLauncher<Intent>? = null private var launcher: ActivityResultLauncher<Intent>? = null
private var pendingResult: CompletableDeferred<ActivityResult>? = null private var pendingResult: CompletableDeferred<ActivityResult>? = null
private val mutex = Mutex()
fun register(launcher: ActivityResultLauncher<Intent>) { fun register(launcher: ActivityResultLauncher<Intent>) {
this.launcher = launcher this.launcher = launcher
} }
suspend fun launch(intent: Intent): ActivityResult { suspend fun launch(intent: Intent): ActivityResult = mutex.withLock {
withContext(Dispatchers.Main) {
val deferred = CompletableDeferred<ActivityResult>() val deferred = CompletableDeferred<ActivityResult>()
pendingResult = deferred pendingResult = deferred
launcher?.launch(intent) launcher?.launch(intent) ?: throw IllegalStateException("Signer not registered")
?: throw IllegalStateException("ExternalSignerLauncher not registered") deferred.await()
return deferred.await()
} }
}
fun onResult(result: ActivityResult) { fun onResult(result: ActivityResult) {
pendingResult?.complete(result) pendingResult?.complete(result)

View File

@@ -412,12 +412,7 @@ class Nostr {
val cachedRumor = getCachedRumor(event.id()) val cachedRumor = getCachedRumor(event.id())
if (cachedRumor != null) return cachedRumor if (cachedRumor != null) return cachedRumor
// Get all signers
val signers = listOfNotNull(signer, deviceSigner)
if (signers.isEmpty()) return null
// Try to unwrap the gift with each signer // Try to unwrap the gift with each signer
for (signer in signers) {
try { try {
val gift = UnwrappedGift.fromGiftWrapAsync(signer = signer, giftWrap = event) val gift = UnwrappedGift.fromGiftWrapAsync(signer = signer, giftWrap = event)
val rumor = gift.rumor() val rumor = gift.rumor()
@@ -427,8 +422,6 @@ class Nostr {
return rumor return rumor
} catch (e: Exception) { } catch (e: Exception) {
println("Failed to unwrap gift: ${e.message}") println("Failed to unwrap gift: ${e.message}")
continue
}
} }
return null return null