From 89121d4cefc59ce9d3723c7e1c099ccd0dff8a4e Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Tue, 14 Apr 2026 05:50:13 -0300 Subject: [PATCH] Fix SignerActivity reopening after accepting an intent request Two related races caused the "nothing to approve yet" flash / reopen: 1. IntentUtils.clear() in onDestroy was wiping intents added by a concurrently-created new SignerActivity instance. Fix: track intent IDs added by each MainViewModel instance (addedIntentIds) and remove only those in onDestroy, leaving any intents owned by the new instance untouched. 2. LaunchedEffect(intent) in AccountScreen received a new IntentWrapper reference on every recomposition (created inline), so it re-ran after onRemoveIntentData emptied _intents, re-adding the just- accepted intent before finishAndRemoveTask() could close the activity. Fix: wrap with remember(intent) { IntentWrapper(intent) } so the effect only re-runs when the actual Intent reference changes (i.e. a genuine new intent from onNewIntent). Co-Authored-By: Claude Sonnet 4.6 --- .../java/com/greenart7c3/nostrsigner/MainActivity.kt | 9 ++++++--- .../java/com/greenart7c3/nostrsigner/MainViewModel.kt | 6 ++++++ .../java/com/greenart7c3/nostrsigner/SignerActivity.kt | 9 ++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/MainActivity.kt b/app/src/main/java/com/greenart7c3/nostrsigner/MainActivity.kt index 12a99d36..9093a46f 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/MainActivity.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/MainActivity.kt @@ -146,7 +146,7 @@ class MainActivity : AppCompatActivity() { AccountScreen( accountStateViewModel = accountStateViewModel, - intent = IntentWrapper(intent), + intent = remember(intent) { IntentWrapper(intent) }, packageName = packageName, appName = appName, bunkerRequests = bunkerRequests.value, @@ -189,8 +189,11 @@ class MainActivity : AppCompatActivity() { } override fun onDestroy() { - IntentUtils.clear() - + val ownedIds = mainViewModel.addedIntentIds + val toRemove = IntentUtils.intents.value.filter { it.id in ownedIds } + if (toRemove.isNotEmpty()) { + IntentUtils.removeAll(toRemove) + } super.onDestroy() } } diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/MainViewModel.kt b/app/src/main/java/com/greenart7c3/nostrsigner/MainViewModel.kt index 88f50187..93c6e87c 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/MainViewModel.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/MainViewModel.kt @@ -25,6 +25,11 @@ import kotlinx.coroutines.launch class MainViewModel(val context: Context) : ViewModel() { var navController: NavHostController? = null + // Intent IDs added by this ViewModel instance — used by onDestroy to remove only + // the intents owned by this activity, avoiding races with a new SignerActivity + // instance that may have already added its own intents. + val addedIntentIds = mutableSetOf() + fun getAccount(userFromIntent: String?): String? { val currentAccount = LocalPreferences.currentAccount(context) try { @@ -128,6 +133,7 @@ class MainViewModel(val context: Context) : ViewModel() { val intentData = IntentUtils.getIntentData(context, intent, callingPackage, intent.getStringExtra("route"), acc) if (intentData != null) { IntentUtils.addAll(listOf(intentData)) + addedIntentIds.add(intentData.id) } intent.getStringExtra("route")?.let { route -> diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/SignerActivity.kt b/app/src/main/java/com/greenart7c3/nostrsigner/SignerActivity.kt index 94e753d7..f3302343 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/SignerActivity.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/SignerActivity.kt @@ -162,7 +162,7 @@ class SignerActivity : AppCompatActivity() { AccountScreen( accountStateViewModel = accountStateViewModel, - intent = IntentWrapper(intent), + intent = remember(intent) { IntentWrapper(intent) }, packageName = packageName, appName = appName, bunkerRequests = bunkerRequests.value, @@ -207,8 +207,11 @@ class SignerActivity : AppCompatActivity() { } override fun onDestroy() { - IntentUtils.clear() - + val ownedIds = mainViewModel.addedIntentIds + val toRemove = IntentUtils.intents.value.filter { it.id in ownedIds } + if (toRemove.isNotEmpty()) { + IntentUtils.removeAll(toRemove) + } super.onDestroy() } }