fix: don't start interfaces until MeshService starts

pull/784/head
andrekir 2023-11-28 18:18:36 -03:00
rodzic 79b98c84b2
commit 1a24ebc9d5
1 zmienionych plików z 4 dodań i 3 usunięć

Wyświetl plik

@ -43,8 +43,8 @@ import javax.inject.Singleton
class RadioInterfaceService @Inject constructor( class RadioInterfaceService @Inject constructor(
private val context: Application, private val context: Application,
private val dispatchers: CoroutineDispatchers, private val dispatchers: CoroutineDispatchers,
bluetoothRepository: BluetoothRepository, private val bluetoothRepository: BluetoothRepository,
networkRepository: NetworkRepository, private val networkRepository: NetworkRepository,
private val processLifecycle: Lifecycle, private val processLifecycle: Lifecycle,
@RadioRepositoryQualifier private val prefs: SharedPreferences, @RadioRepositoryQualifier private val prefs: SharedPreferences,
private val interfaceFactory: InterfaceFactory, private val interfaceFactory: InterfaceFactory,
@ -93,7 +93,7 @@ class RadioInterfaceService @Inject constructor(
/// true if our interface is currently connected to a device /// true if our interface is currently connected to a device
private var isConnected = false private var isConnected = false
init { private fun initStateListeners() {
bluetoothRepository.state.onEach { state -> bluetoothRepository.state.onEach { state ->
if (state.enabled) startInterface() if (state.enabled) startInterface()
else if (radioIf is BluetoothInterface) stopInterface() else if (radioIf is BluetoothInterface) stopInterface()
@ -291,6 +291,7 @@ class RadioInterfaceService @Inject constructor(
// We don't start actually talking to our device until MeshService binds to us - this prevents // We don't start actually talking to our device until MeshService binds to us - this prevents
// broadcasting connection events before MeshService is ready to receive them // broadcasting connection events before MeshService is ready to receive them
startInterface() startInterface()
initStateListeners()
} }
fun sendToRadio(a: ByteArray) { fun sendToRadio(a: ByteArray) {