fix: 未联网打开 App 闪退

This commit is contained in:
HuanCheng65 2023-02-18 14:13:33 +08:00
parent a9115bb520
commit d0c3017b67
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
1 changed files with 9 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.dataStore import com.huanchengfly.tieba.post.dataStore
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -42,10 +43,13 @@ object ClientUtils {
} }
private suspend fun sync(context: Context) { private suspend fun sync(context: Context) {
TiebaApi.getInstance().syncFlow(clientId).collect { TiebaApi.getInstance()
clientId = it.client.clientId .syncFlow(clientId)
sampleId = it.wlConfig.sampleId .catch { it.printStackTrace() }
save(context, it.client.clientId, it.wlConfig.sampleId) .collect {
} clientId = it.client.clientId
sampleId = it.wlConfig.sampleId
save(context, it.client.clientId, it.wlConfig.sampleId)
}
} }
} }