From 35f2a0db673d4f40d28e8b23c0f35e47b5d742fc Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Wed, 26 Nov 2025 16:43:48 -0300 Subject: [PATCH] Fix close application logic - In `MultiEventHomeScreen`, determine `closeApp` status before processing bunker requests by checking if any request requires closing the application. - Move `EventNotificationConsumer.cancelAll()` and `finishActivity` to occur immediately after clearing requests, rather than after processing them. - In `BunkerRequestUtils`, add logic to clear requests, cancel notifications, and finish the activity if necessary when manually approving a permission. - Set `onLoading(true)` at the start of `acceptOrRejectPermission` in `BunkerRequestUtils`. --- .../nostrsigner/service/BunkerRequestUtils.kt | 9 +++++++++ .../nostrsigner/ui/components/MultiEventHomeScreen.kt | 11 +++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt index 799d0bb3..def9371d 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt @@ -404,6 +404,7 @@ object BunkerRequestUtils { kind: Int?, onLoading: (Boolean) -> Unit, ) { + onLoading(true) Amber.instance.applicationIOScope.launch(Dispatchers.IO) { val savedApplication = Amber.instance.getDatabase(account.npub).dao().getByKey(key) val defaultRelays = Amber.instance.settings.defaultRelays @@ -432,6 +433,14 @@ object BunkerRequestUtils { permissions = mutableListOf(), ) + clearRequests() + EventNotificationConsumer(Amber.instance).notificationManager().cancelAll() + val activity = Amber.instance.getMainActivity() + activity?.intent = null + if (application.application.closeApplication) { + activity?.finish() + } + if (rememberType != RememberType.NEVER) { AmberUtils.acceptOrRejectPermission( application, diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt index dc9b4604..3ae2fe7c 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/MultiEventHomeScreen.kt @@ -663,9 +663,10 @@ fun BunkerMultiEventHomeScreen( Amber.instance.applicationIOScope.launch(Dispatchers.IO) { try { reconnectToRelays() - var closeApp = true - + val closeApp = bunkerRequests.any { it.closeApplication } BunkerRequestUtils.clearRequests() + EventNotificationConsumer(context).notificationManager().cancelAll() + finishActivity(closeApp) for (request in bunkerRequests) { val thisAccount = if (request.currentAccount.isNotBlank()) { @@ -709,10 +710,6 @@ fun BunkerMultiEventHomeScreen( permissions = mutableListOf(), ) - if (!application.application.closeApplication) { - closeApp = false - } - if (request.request is BunkerRequestSign) { val localEvent = request.signedEvent!! @@ -923,8 +920,6 @@ fun BunkerMultiEventHomeScreen( } } } - EventNotificationConsumer(context).notificationManager().cancelAll() - finishActivity(closeApp) } finally { onLoading(false) }