From 483a84c616e51696a9812ada3d76171bc8508761 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Tue, 9 Jun 2026 14:27:21 +0700 Subject: [PATCH] fix --- .../su/reya/coop/ExternalSignerLauncher.kt | 6 ----- .../kotlin/su/reya/coop/MainActivity.kt | 9 +++---- .../su/reya/coop/screens/OnboardingScreen.kt | 3 +-- .../kotlin/su/reya/coop/NostrViewModel.kt | 27 ++++++++++--------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/ExternalSignerLauncher.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/ExternalSignerLauncher.kt index c05f578..cbfb686 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/ExternalSignerLauncher.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/ExternalSignerLauncher.kt @@ -13,12 +13,6 @@ class ExternalSignerLauncher { this.launcher = launcher } - fun unregister() { - launcher = null - pendingResult?.cancel() - pendingResult = null - } - suspend fun launch(intent: Intent): ActivityResult { val deferred = CompletableDeferred() pendingResult = deferred diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt index 9e94a94..0fb8442 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt @@ -17,7 +17,9 @@ import su.reya.coop.coop.storage.SecretStore import kotlin.system.exitProcess class MainActivity : ComponentActivity() { - private val externalSignerLauncher = ExternalSignerLauncher() + companion object { + val externalSignerLauncher = ExternalSignerLauncher() + } private val viewModel: NostrViewModel by viewModels { object : ViewModelProvider.Factory { @@ -81,9 +83,4 @@ class MainActivity : ComponentActivity() { super.onNewIntent(intent) setIntent(intent) } - - override fun onDestroy() { - externalSignerLauncher.unregister() - super.onDestroy() - } } diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt index ca55709..17845be 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt @@ -160,10 +160,9 @@ fun OnboardingScreen() { if (viewModel.isExternalSignerAvailable()) { try { viewModel.connectExternalSigner() + navigator.navigate(Screen.Home) } catch (e: Exception) { e.message?.let { snackbarHostState.showSnackbar(it) } - } finally { - navigator.navigate(Screen.Home) } } else { val result = snackbarHostState.showSnackbar( diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index 0c40fe3..c7ae978 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -413,10 +413,10 @@ class NostrViewModel( val newMetadata = nostr.updateProfile(name, bio, avatarUrl) // Update the metadata state after successfully published updateMetadata(nostr.signer.currentUser!!, newMetadata) + // Update local state + _isBusy.value = false } catch (e: Exception) { showError("Error: ${e.message}") - } finally { - _isBusy.value = false } } @@ -435,12 +435,13 @@ class NostrViewModel( val avatarUrl = picture?.let { blossomUpload(it, contentType ?: "image/jpeg") } // Create identity nostr.createIdentity(keys = keys, name = name, bio, picture = avatarUrl) - } catch (e: Exception) { - showError("Error: ${e.message}") - } finally { + // Persist the secret in the secret storage secretStore.set("user_signer", secret) + // Update local states _isBusy.value = false _signerRequired.value = false + } catch (e: Exception) { + showError("Error: ${e.message}") } } @@ -489,13 +490,15 @@ class NostrViewModel( _isBusy.value = true try { val signer = createSigner(secret) + // Update signer nostr.setSigner(signer) - } catch (e: Exception) { - showError("Error: ${e.message}") - } finally { + // Persist the secret in the secret storage secretStore.set("user_signer", secret) + // Update local states _signerRequired.value = false _isBusy.value = false + } catch (e: Exception) { + showError("Error: ${e.message}") } } @@ -512,19 +515,19 @@ class NostrViewModel( SignerPermissions.nip44Decrypt(), ) ) + val result = handler.getPublicKey(permissions) ?: throw Exception("Rejected") val signer = ExternalSignerProxy(handler, result.pubkey) // Update signer nostr.setSigner(signer) - // Store the signer in the secret storage secretStore.set("user_signer", "nip55://${result.packageName}/${result.pubkey.toHex()}") - } catch (e: Exception) { - showError("Error: ${e.message}") - } finally { + // Update local states _signerRequired.value = false _isBusy.value = false + } catch (e: Exception) { + throw Exception("Notice: ${e.message}") } }