Skip to content

Commit

Permalink
Fix sync log crash
Browse files Browse the repository at this point in the history
Was updating UI off main thread
  • Loading branch information
Wavesonics committed Sep 2, 2023
1 parent ef41d3d commit 63b784c
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,25 @@ class ProjectsListComponent(
}
}

private fun syncProgressStatus(projectName: String, status: ProjectsList.Status, progress: Float? = null) {
_state.getAndUpdate {
val projStatus = it.syncState.projectsStatus[projectName]!!
private suspend fun syncProgressStatus(projectName: String, status: ProjectsList.Status, progress: Float? = null) =
withContext(mainDispatcher) {
_state.getAndUpdate {
val projStatus = it.syncState.projectsStatus[projectName]!!

val map = it.syncState.projectsStatus.toMutableMap()
val updatedMap = projStatus.copy(
status = status,
progress = progress ?: projStatus.progress
)
map[projectName] = updatedMap
val map = it.syncState.projectsStatus.toMutableMap()
val updatedMap = projStatus.copy(
status = status,
progress = progress ?: projStatus.progress
)
map[projectName] = updatedMap

it.copy(
syncState = it.syncState.copy(
projectsStatus = map
it.copy(
syncState = it.syncState.copy(
projectsStatus = map
)
)
)
}
}
}

override fun syncProjects(callback: (Boolean) -> Unit) {
syncProjectsJob?.cancel(CancellationException("Started another sync"))
Expand Down

0 comments on commit 63b784c

Please sign in to comment.