fix: add explicit DI binds and ensure scans start after DataStore load (#5319)

This commit is contained in:
James Rich
2026-05-01 10:39:40 -05:00
committed by GitHub
parent 56e095a076
commit 68a1c578a7
7 changed files with 15 additions and 11 deletions

View File

@@ -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<BleDevice> {
val scanner = Scanner {

View File

@@ -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<Boolean> = connectivityManager.networkAvailable()
}

View File

@@ -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<List<DiscoveredService>> =
nsdManager.serviceList(NetworkConstants.SERVICE_TYPE).map { list ->

View File

@@ -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<Boolean> = flowOf(true)
}

View File

@@ -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<List<DiscoveredService>> =

View File

@@ -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,

View File

@@ -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 */