chore: improve performance #41

Merged
reya merged 9 commits from fix-perf into master 2026-07-11 12:45:54 +00:00
2 changed files with 10 additions and 9 deletions
Showing only changes of commit 9a8d3c06fa - Show all commits

View File

@@ -29,16 +29,14 @@ class UniversalSigner(initialSigner: AsyncNostrSigner) : AsyncNostrSigner {
/** /**
* Switch to a new signer. * Switch to a new signer.
*/ */
suspend fun switch(newSigner: AsyncNostrSigner) = mutex.withLock { suspend fun switch(newSigner: AsyncNostrSigner) {
val pubkey = try { val pubkey = withTimeoutOrNull(20.seconds) { newSigner.getPublicKeyAsync() }
withTimeoutOrNull(20.seconds) { ?: throw IllegalStateException("Failed to get public key from signer")
newSigner.getPublicKeyAsync()
} mutex.withLock {
} catch (e: Exception) { signer = newSigner
throw IllegalStateException("Failed to get public key from signer", e) _publicKeyFlow.value = pubkey
} }
signer = newSigner
_publicKeyFlow.value = pubkey
} }
override suspend fun getPublicKeyAsync(): PublicKey? { override suspend fun getPublicKeyAsync(): PublicKey? {

View File

@@ -1,6 +1,7 @@
package su.reya.coop.viewmodel package su.reya.coop.viewmodel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
@@ -145,6 +146,8 @@ class ChatViewModel(
rooms.forEach { room -> newMap[room.id] = room } rooms.forEach { room -> newMap[room.id] = room }
currentState.copy(rooms = newMap) currentState.copy(rooms = newMap)
} }
} catch (e: CancellationException) {
throw e
} catch (e: Exception) { } catch (e: Exception) {
showError("Error: ${e.message}") showError("Error: ${e.message}")
} }