diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt index 75cda65a1..62fb453cb 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/AmberUtils.kt @@ -1,13 +1,38 @@ package com.vitorpamplona.amethyst.service +import android.content.Intent +import android.net.Uri +import androidx.activity.result.ActivityResultLauncher +import com.vitorpamplona.amethyst.ServiceManager import com.vitorpamplona.amethyst.ui.actions.SignerType -import com.vitorpamplona.amethyst.ui.actions.openAmber import com.vitorpamplona.quartz.encoders.HexKey object AmberUtils { var content: String = "" var isActivityRunning: Boolean = false + fun openAmber( + data: String, + type: SignerType, + intentResult: ActivityResultLauncher, + pubKey: HexKey + ) { + ServiceManager.shouldPauseService = false + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data")) + val signerType = when (type) { + SignerType.SIGN_EVENT -> "sign_event" + SignerType.NIP04_ENCRYPT -> "nip04_encrypt" + SignerType.NIP04_DECRYPT -> "nip04_decrypt" + SignerType.NIP44_ENCRYPT -> "nip44_encrypt" + SignerType.NIP44_DECRYPT -> "nip44_decrypt" + SignerType.GET_PUBLIC_KEY -> "get_public_key" + } + intent.putExtra("type", signerType) + intent.putExtra("pubKey", pubKey) + intent.`package` = "com.greenart7c3.nostrsigner.debug" + intentResult.launch(intent) + } + fun decryptBookmark(encryptedContent: String, pubKey: HexKey) { if (content.isBlank()) { isActivityRunning = true diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt index 7a92d4ffc..c1edd934d 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt @@ -1,6 +1,5 @@ package com.vitorpamplona.amethyst.service -import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES @@ -10,7 +9,6 @@ import com.vitorpamplona.amethyst.service.relays.JsonFilter import com.vitorpamplona.amethyst.service.relays.Relay import com.vitorpamplona.amethyst.service.relays.TypedFilter import com.vitorpamplona.amethyst.ui.actions.SignerType -import com.vitorpamplona.amethyst.ui.actions.openAmber import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent import com.vitorpamplona.quartz.events.BadgeAwardEvent import com.vitorpamplona.quartz.events.BadgeProfilesEvent @@ -192,13 +190,12 @@ object NostrAccountDataSource : NostrDataSource("AccountData") { super.auth(relay, challenge) if (this::account.isInitialized) { - val context = Amethyst.instance val loggedInWithAmber = account.loginWithAmber val event = account.createAuthEvent(relay, challenge, loggedInWithAmber) if (loggedInWithAmber && !account.isWriteable()) { if (event != null) { - openAmber( + AmberUtils.openAmber( event.toJson(), SignerType.SIGN_EVENT, IntentUtils.authActivityResultLauncher, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt index 2e0c9ae8e..e348da44f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt @@ -4,10 +4,10 @@ import android.util.Log import com.vitorpamplona.amethyst.AccountInfo import com.vitorpamplona.amethyst.BuildConfig import com.vitorpamplona.amethyst.LocalPreferences +import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.service.HttpClient import com.vitorpamplona.amethyst.service.IntentUtils import com.vitorpamplona.amethyst.ui.actions.SignerType -import com.vitorpamplona.amethyst.ui.actions.openAmber import com.vitorpamplona.quartz.events.RelayAuthEvent import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -74,7 +74,7 @@ class RegisterAccounts( Log.d("fcm register", account.npub) val events = signEventsToProveControlOfAccounts(listOf(account), notificationToken, account.loggedInWithAmber) if (events.isNotEmpty()) { - openAmber( + AmberUtils.openAmber( events.first().toJson(), SignerType.SIGN_EVENT, IntentUtils.activityResultLauncher, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/SignerDialog.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/SignerDialog.kt index 099c910bf..3708d59e8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/SignerDialog.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/SignerDialog.kt @@ -1,11 +1,8 @@ package com.vitorpamplona.amethyst.ui.actions import android.app.Activity.RESULT_OK -import android.content.Intent -import android.net.Uri import android.widget.Toast import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -39,6 +36,7 @@ import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.ServiceManager +import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer import com.vitorpamplona.quartz.encoders.HexKey @@ -56,28 +54,6 @@ enum class SignerType { GET_PUBLIC_KEY } -fun openAmber( - data: String, - type: SignerType, - intentResult: ActivityResultLauncher, - pubKey: HexKey -) { - ServiceManager.shouldPauseService = false - val intent = Intent(Intent.ACTION_VIEW, Uri.parse("nostrsigner:$data")) - val signerType = when (type) { - SignerType.SIGN_EVENT -> "sign_event" - SignerType.NIP04_ENCRYPT -> "nip04_encrypt" - SignerType.NIP04_DECRYPT -> "nip04_decrypt" - SignerType.NIP44_ENCRYPT -> "nip44_encrypt" - SignerType.NIP44_DECRYPT -> "nip44_decrypt" - SignerType.GET_PUBLIC_KEY -> "get_public_key" - } - intent.putExtra("type", signerType) - intent.putExtra("pubKey", pubKey) - intent.`package` = "com.greenart7c3.nostrsigner.debug" - intentResult.launch(intent) -} - @Composable fun SignerDialog( onClose: () -> Unit, @@ -114,7 +90,7 @@ fun SignerDialog( ) LaunchedEffect(Unit) { - openAmber(data, type, intentResult, pubKey) + AmberUtils.openAmber(data, type, intentResult, pubKey) } Dialog( @@ -205,7 +181,7 @@ fun SignerDialog( ) Button( shape = ButtonBorder, - onClick = { openAmber(data, type, intentResult, pubKey) } + onClick = { AmberUtils.openAmber(data, type, intentResult, pubKey) } ) { Text("Open Amber") } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index ba102608d..7316d9891 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -90,12 +90,12 @@ import com.vitorpamplona.amethyst.model.ConnectivityType import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.User +import com.vitorpamplona.amethyst.service.AmberUtils import com.vitorpamplona.amethyst.service.OnlineChecker import com.vitorpamplona.amethyst.service.ReverseGeoLocationUtil import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus import com.vitorpamplona.amethyst.ui.actions.NewRelayListView import com.vitorpamplona.amethyst.ui.actions.SignerType -import com.vitorpamplona.amethyst.ui.actions.openAmber import com.vitorpamplona.amethyst.ui.components.ClickableUrl import com.vitorpamplona.amethyst.ui.components.CreateClickableTextWithEmoji import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji @@ -1608,7 +1608,7 @@ private fun RenderPrivateMessage( if (accountViewModel.loggedInWithAmber()) { val event = note.event SideEffect { - openAmber( + AmberUtils.openAmber( event?.content() ?: "", SignerType.NIP04_DECRYPT, activityLauncher,