load network connection after app initialization
@@ -3,6 +3,7 @@ package fr.acinq.phoenix.app
import fr.acinq.eklair.blockchain.electrum.ElectrumClient
import fr.acinq.eklair.io.Peer
import fr.acinq.eklair.utils.Connection
+import fr.acinq.phoenix.FakeDataStore
import fr.acinq.phoenix.utils.NetworkMonitor
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.ReceiveChannel
@@ -10,6 +11,7 @@ import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.consumeAsFlow
+import kotlinx.coroutines.flow.single
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.direct
@@ -24,6 +26,9 @@ import kotlin.time.seconds
@OptIn(ExperimentalCoroutinesApi::class, ExperimentalTime::class)
class Daemon(override val di: DI) : DIAware {
+ // TODO to be replaced by a real DB
+ private val dataStore: FakeDataStore by instance()
+
private val monitor: NetworkMonitor by instance()
private val peer: Peer by instance()
private val electrumClient: ElectrumClient by instance()
@@ -31,7 +36,11 @@ class Daemon(override val di: DI) : DIAware {
private val logger = direct.instance<LoggerFactory>().newLogger(Daemon::class)
init {
- MainScope().launch { networkStateMonitoring() }
+ MainScope().launch {
+ dataStore.openTriggerSubscription().consumeEach {
+ if (it) networkStateMonitoring()
+ }
+ }
}
private var connectionDaemonJob :Job? = null
