Fix LwaClient issing incorrect root url.

This commit is contained in:
Thomas Andres Gomez 2025-04-22 11:36:54 +02:00
parent 7818070f2f
commit edf58fd215
2 changed files with 28 additions and 15 deletions

View file

@ -9,11 +9,13 @@ import com.pixelized.desktop.lwa.repository.item.ItemRepository
import com.pixelized.desktop.lwa.repository.network.NetworkRepository import com.pixelized.desktop.lwa.repository.network.NetworkRepository
import com.pixelized.desktop.lwa.repository.settings.SettingsRepository import com.pixelized.desktop.lwa.repository.settings.SettingsRepository
import com.pixelized.desktop.lwa.repository.tag.TagRepository import com.pixelized.desktop.lwa.repository.tag.TagRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -47,28 +49,39 @@ class DataSyncViewModel(
networkRepository.status networkRepository.status
.filter { status -> status == NetworkRepository.Status.CONNECTED } .filter { status -> status == NetworkRepository.Status.CONNECTED }
.flowOn(context = Dispatchers.IO)
.onEach { .onEach {
tagRepository.updateAlterationTags() try {
alterationRepository.updateAlterationFlow() tagRepository.updateAlterationTags()
tagRepository.updateCharacterTags() alterationRepository.updateAlterationFlow()
characterRepository.updateCharacterPreviews() tagRepository.updateCharacterTags()
campaignRepository.updateCampaign() characterRepository.updateCharacterPreviews()
tagRepository.updateItemTags() campaignRepository.updateCampaign()
itemRepository.updateItemFlow() tagRepository.updateItemTags()
itemRepository.updateItemFlow()
} catch (exception: Exception) {
println(exception.message) // TODO proper exception handling
}
} }
.launchIn(this) .launchIn(this)
networkRepository.status networkRepository.status
.filter { status -> status == NetworkRepository.Status.CONNECTED } .filter { status -> status == NetworkRepository.Status.CONNECTED }
.flowOn(context = Dispatchers.IO)
.flatMapLatest { campaignRepository.campaignFlow().map { it.instances } } .flatMapLatest { campaignRepository.campaignFlow().map { it.instances } }
.distinctUntilChanged()
.onEach { instances -> .onEach { instances ->
instances.forEach { characterSheetId -> instances.forEach { characterSheetId ->
characterRepository.updateCharacterSheet( try {
characterSheetId = characterSheetId, characterRepository.updateCharacterSheet(
) characterSheetId = characterSheetId,
inventoryRepository.updateInventoryFlow( )
characterSheetId = characterSheetId, inventoryRepository.updateInventoryFlow(
) characterSheetId = characterSheetId,
)
} catch (exception: Exception) {
println(exception.message) // TODO proper exception handling
}
} }
} }
.launchIn(this) .launchIn(this)

View file

@ -20,9 +20,9 @@ import io.ktor.http.contentType
class LwaClientImpl( class LwaClientImpl(
private val client: HttpClient, private val client: HttpClient,
setting: SettingsRepository, private val setting: SettingsRepository,
) : LwaClient { ) : LwaClient {
private val root = setting.settings().network.root private val root get() = setting.settings().network.root
@Throws @Throws
override suspend fun getAlterations(): APIResponse<List<AlterationJson>> = client override suspend fun getAlterations(): APIResponse<List<AlterationJson>> = client