Skip to content

Commit c075bca

Browse files
committed
fix: stop node onTimeOut only when is in BG
1 parent ea1f74a commit c075bca

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

app/src/main/java/to/bitkit/androidServices/LightningNodeService.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,25 +243,26 @@ class LightningNodeService : Service() {
243243
nodeServiceFgState.setForegroundServiceRunning(false)
244244
// Drop our event handler so it isn't retained by the repo singleton across service restarts.
245245
lightningRepo.removeEventHandler(nodeEventHandler)
246-
// Only stop the node when no activity is active; in the foreground WalletViewModel owns the
247-
// node lifecycle, so toggling off the foreground service must leave the node running.
248-
// Safe to call even if already stopped — guarded by lifecycleMutex + isStoppedOrStopping()
249-
if (App.currentActivity?.value == null) {
250-
serviceScope.launch { lightningRepo.stop() }
251-
} else {
252-
Logger.debug("Skipping node stop on foreground service destroy: activity is active", context = TAG)
253-
}
246+
stopNodeIfBackgrounded()
254247
super.onDestroy()
255248
}
256249

257250
@RequiresApi(VERSION_CODES.VANILLA_ICE_CREAM)
258251
override fun onTimeout(startId: Int, fgsType: Int) {
259252
Logger.warn("Reached foreground service timeout for type '$fgsType'", context = TAG)
260253
stopForegroundService(startId)
261-
serviceScope.launch { lightningRepo.stop() }
254+
stopNodeIfBackgrounded()
262255
super.onTimeout(startId, fgsType)
263256
}
264257

258+
private fun stopNodeIfBackgrounded() {
259+
if (App.currentActivity?.value == null) {
260+
serviceScope.launch { lightningRepo.stop() }
261+
} else {
262+
Logger.debug("Skipping node stop: activity is active", context = TAG)
263+
}
264+
}
265+
265266
override fun onBind(intent: Intent?): IBinder? = null
266267

267268
companion object {

0 commit comments

Comments
 (0)