Skip to content

Commit 13dc30f

Browse files
committed
fix:race condition when click in the push notification
1 parent d98f7eb commit 13dc30f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/src/main/java/to/bitkit/fcm/WakeNodeWorker.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.work.workDataOf
88
import dagger.assisted.Assisted
99
import dagger.assisted.AssistedInject
1010
import kotlinx.coroutines.CompletableDeferred
11+
import kotlinx.coroutines.delay
1112
import kotlinx.coroutines.flow.first
1213
import kotlinx.coroutines.withTimeout
1314
import kotlinx.serialization.json.JsonObject
@@ -241,6 +242,15 @@ class WakeNodeWorker @AssistedInject constructor(
241242
}
242243

243244
private suspend fun deliver() {
245+
// Send notification first
246+
bestAttemptContent?.run {
247+
appContext.pushNotification(title, body)
248+
Logger.info("Delivered notification", context = TAG)
249+
}
250+
251+
// Delay briefly to allow app to come to foreground if user clicked notification
252+
delay(500)
253+
244254
// Only stop node if app is not in foreground
245255
// LightningNodeService will keep node running in background when notifications are enabled
246256
if (App.currentActivity?.value == null) {
@@ -250,11 +260,6 @@ class WakeNodeWorker @AssistedInject constructor(
250260
Logger.debug("App in foreground, keeping node running", context = TAG)
251261
}
252262

253-
bestAttemptContent?.run {
254-
appContext.pushNotification(title, body)
255-
Logger.info("Delivered notification", context = TAG)
256-
}
257-
258263
deliverSignal.complete(Unit)
259264
}
260265

0 commit comments

Comments
 (0)