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`.
This commit is contained in:
greenart7c3
2025-11-26 16:43:48 -03:00
parent 581a35cde9
commit 35f2a0db67
2 changed files with 12 additions and 8 deletions
@@ -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,
@@ -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)
}