sforkowany z mirror/meshtastic-android
update coroutine scopes
rodzic
d42dbb7b04
commit
4ea17e36bc
|
@ -17,6 +17,7 @@ import androidx.activity.result.IntentSenderRequest
|
|||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.MainActivity
|
||||
|
@ -34,8 +35,6 @@ import com.geeksville.mesh.util.anonymize
|
|||
import com.geeksville.mesh.util.exceptionReporter
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
@ -277,7 +276,7 @@ class BTScanModel @Inject constructor(
|
|||
// Start Network Service Discovery (find TCP devices)
|
||||
networkDiscovery = nsdRepository.networkDiscoveryFlow()
|
||||
.onEach { addDevice(TCPDeviceListEntry(it)) }
|
||||
.launchIn(CoroutineScope(Dispatchers.Main))
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
if (hasBluetoothPermission) {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S && hasCompanionDeviceApi)
|
||||
|
|
|
@ -32,7 +32,11 @@ import com.google.protobuf.ByteString
|
|||
import com.google.protobuf.InvalidProtocolBufferException
|
||||
import dagger.Lazy
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.serialization.json.Json
|
||||
|
@ -174,7 +178,8 @@ class MeshService : Service(), Logging {
|
|||
location.altitude.toInt(),
|
||||
(location.time / 1000).toInt(),
|
||||
)
|
||||
}.launchIn(CoroutineScope(Dispatchers.Default))
|
||||
}
|
||||
.launchIn(serviceScope)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,17 +252,12 @@ class MeshService : Service(), Logging {
|
|||
// We in turn need to use the radiointerface service
|
||||
radioInterfaceService.connect()
|
||||
}
|
||||
serviceScope.handledLaunch {
|
||||
radioInterfaceService.connectionState.collect(::onRadioConnectionState)
|
||||
}
|
||||
serviceScope.handledLaunch {
|
||||
radioInterfaceService.receivedData.collect(::onReceiveFromRadio)
|
||||
}
|
||||
serviceScope.handledLaunch {
|
||||
localConfigRepository.localConfigFlow.collect { config ->
|
||||
localConfig = config
|
||||
}
|
||||
}
|
||||
radioInterfaceService.connectionState.onEach(::onRadioConnectionState)
|
||||
.launchIn(serviceScope)
|
||||
radioInterfaceService.receivedData.onEach(::onReceiveFromRadio)
|
||||
.launchIn(serviceScope)
|
||||
localConfigRepository.localConfigFlow.onEach { localConfig = it }
|
||||
.launchIn(serviceScope)
|
||||
|
||||
// the rest of our init will happen once we are in radioConnection.onServiceConnected
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue