fix: occasional splash screen hang (#15)

Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
2026-06-06 07:30:47 +00:00
parent b8b3b83952
commit 74a37320fe
2 changed files with 23 additions and 5 deletions

View File

@@ -76,6 +76,11 @@ class NostrViewModel(
private val seenPublicKeys = mutableSetOf<PublicKey>()
init {
// Skip the splash screen if a user is already logged in
if (nostr.signer.currentUser != null) {
_signerRequired.value = false
}
// Check if the notification banner has been dismissed
checkNotificationBannerDismissedStatus()
@@ -216,7 +221,9 @@ class NostrViewModel(
private fun login() {
viewModelScope.launch {
try {
val secret = secretStore.get("user_signer")
val secret = withTimeoutOrNull(3.seconds) {
secretStore.get("user_signer")
}
if (secret == null) {
_signerRequired.value = true

View File

@@ -2,31 +2,42 @@ package su.reya.coop
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withTimeoutOrNull
import rust.nostr.sdk.AsyncNostrSigner
import rust.nostr.sdk.Event
import rust.nostr.sdk.PublicKey
import rust.nostr.sdk.UnsignedEvent
import kotlin.concurrent.Volatile
import kotlin.time.Duration.Companion.seconds
class UniversalSigner(initialSigner: AsyncNostrSigner) : AsyncNostrSigner {
private val mutex = Mutex()
@Volatile
private var signer: AsyncNostrSigner = initialSigner
@Volatile
var currentUser: PublicKey? = null
private set
/**
* Get the current signer.
*/
suspend fun get(): AsyncNostrSigner = mutex.withLock {
signer
}
fun get(): AsyncNostrSigner = signer
/**
* Switch to a new signer.
*/
suspend fun switch(newSigner: AsyncNostrSigner) = mutex.withLock {
val pubkey = try {
withTimeoutOrNull(20.seconds) {
newSigner.getPublicKeyAsync()
}
} catch (e: Exception) {
throw IllegalStateException("Failed to get public key from signer", e)
}
signer = newSigner
currentUser = newSigner.getPublicKeyAsync()
currentUser = pubkey
}
override suspend fun getPublicKeyAsync(): PublicKey? {