From 68a1c578a72294f8dd9317bee5755bd97a5cc19c Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Fri, 1 May 2026 10:39:40 -0500 Subject: [PATCH] fix: add explicit DI binds and ensure scans start after DataStore load (#5319) --- .../org/meshtastic/core/ble/KableBleScanner.kt | 2 +- .../network/repository/AndroidNetworkMonitor.kt | 2 +- .../network/repository/AndroidServiceDiscovery.kt | 2 +- .../core/network/repository/JvmNetworkMonitor.kt | 2 +- .../core/network/repository/JvmServiceDiscovery.kt | 2 +- .../usecase/AndroidGetDiscoveredDevicesUseCase.kt | 2 +- .../feature/connections/ui/ConnectionsScreen.kt | 14 +++++++++----- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/ble/src/commonMain/kotlin/org/meshtastic/core/ble/KableBleScanner.kt b/core/ble/src/commonMain/kotlin/org/meshtastic/core/ble/KableBleScanner.kt index 875978ceb..22f0101d9 100644 --- a/core/ble/src/commonMain/kotlin/org/meshtastic/core/ble/KableBleScanner.kt +++ b/core/ble/src/commonMain/kotlin/org/meshtastic/core/ble/KableBleScanner.kt @@ -24,7 +24,7 @@ import org.koin.core.annotation.Single import kotlin.time.Duration import kotlin.uuid.Uuid -@Single +@Single(binds = [BleScanner::class]) class KableBleScanner(private val loggingConfig: BleLoggingConfig) : BleScanner { override fun scan(timeout: Duration, serviceUuid: Uuid?, address: String?): Flow { val scanner = Scanner { diff --git a/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidNetworkMonitor.kt b/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidNetworkMonitor.kt index e11c4fba5..cc78c4160 100644 --- a/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidNetworkMonitor.kt +++ b/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidNetworkMonitor.kt @@ -20,7 +20,7 @@ import android.net.ConnectivityManager import kotlinx.coroutines.flow.Flow import org.koin.core.annotation.Single -@Single +@Single(binds = [NetworkMonitor::class]) class AndroidNetworkMonitor(private val connectivityManager: ConnectivityManager) : NetworkMonitor { override val networkAvailable: Flow = connectivityManager.networkAvailable() } diff --git a/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidServiceDiscovery.kt b/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidServiceDiscovery.kt index e00ab8c60..603d5c70c 100644 --- a/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidServiceDiscovery.kt +++ b/core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidServiceDiscovery.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import org.koin.core.annotation.Single -@Single +@Single(binds = [ServiceDiscovery::class]) class AndroidServiceDiscovery(private val nsdManager: NsdManager) : ServiceDiscovery { override val resolvedServices: Flow> = nsdManager.serviceList(NetworkConstants.SERVICE_TYPE).map { list -> diff --git a/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmNetworkMonitor.kt b/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmNetworkMonitor.kt index e464979f2..61c400091 100644 --- a/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmNetworkMonitor.kt +++ b/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmNetworkMonitor.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf import org.koin.core.annotation.Single -@Single +@Single(binds = [NetworkMonitor::class]) class JvmNetworkMonitor : NetworkMonitor { override val networkAvailable: Flow = flowOf(true) } diff --git a/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmServiceDiscovery.kt b/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmServiceDiscovery.kt index 34b9e49a3..aeef1a42f 100644 --- a/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmServiceDiscovery.kt +++ b/core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmServiceDiscovery.kt @@ -30,7 +30,7 @@ import javax.jmdns.JmDNS import javax.jmdns.ServiceEvent import javax.jmdns.ServiceListener -@Single +@Single(binds = [ServiceDiscovery::class]) class JvmServiceDiscovery(private val dispatchers: CoroutineDispatchers) : ServiceDiscovery { @Suppress("TooGenericExceptionCaught") override val resolvedServices: Flow> = diff --git a/feature/connections/src/androidMain/kotlin/org/meshtastic/feature/connections/domain/usecase/AndroidGetDiscoveredDevicesUseCase.kt b/feature/connections/src/androidMain/kotlin/org/meshtastic/feature/connections/domain/usecase/AndroidGetDiscoveredDevicesUseCase.kt index 80702a7f0..280834f24 100644 --- a/feature/connections/src/androidMain/kotlin/org/meshtastic/feature/connections/domain/usecase/AndroidGetDiscoveredDevicesUseCase.kt +++ b/feature/connections/src/androidMain/kotlin/org/meshtastic/feature/connections/domain/usecase/AndroidGetDiscoveredDevicesUseCase.kt @@ -42,7 +42,7 @@ import org.meshtastic.feature.connections.model.getMeshtasticShortName import java.util.Locale @Suppress("LongParameterList") -@Single +@Single(binds = [GetDiscoveredDevicesUseCase::class]) class AndroidGetDiscoveredDevicesUseCase( private val bluetoothRepository: BluetoothRepository, private val recentAddressesDataSource: RecentAddressesDataSource, diff --git a/feature/connections/src/commonMain/kotlin/org/meshtastic/feature/connections/ui/ConnectionsScreen.kt b/feature/connections/src/commonMain/kotlin/org/meshtastic/feature/connections/ui/ConnectionsScreen.kt index 06aa7cf9c..dae1683f9 100644 --- a/feature/connections/src/commonMain/kotlin/org/meshtastic/feature/connections/ui/ConnectionsScreen.kt +++ b/feature/connections/src/commonMain/kotlin/org/meshtastic/feature/connections/ui/ConnectionsScreen.kt @@ -138,13 +138,17 @@ fun ConnectionsScreen( // Auto-start scans on screen entry when the user has previously opted in via the toggle. Stop on exit so we don't // drain battery in the background. Network auto-start is additionally gated on the runtime local-network grant so // we don't trigger the system picker for users who declined the permission. - DisposableEffect(localNetworkPermissionGranted) { + // + // Keys include bleAutoScan/networkAutoScan so the effect re-fires once DataStore delivers the persisted `true` + // value (initial composition sees `false` from the Eagerly-seeded StateFlow before the disk read completes). + DisposableEffect(bleAutoScan) { if (bleAutoScan) scanModel.startBleScan() + onDispose { scanModel.stopBleScan() } + } + + DisposableEffect(networkAutoScan, localNetworkPermissionGranted) { if (networkAutoScan && localNetworkPermissionGranted) scanModel.startNetworkScan() - onDispose { - scanModel.stopBleScan() - scanModel.stopNetworkScan() - } + onDispose { scanModel.stopNetworkScan() } } /* Animate waiting for the configurations */