Added delayed state change to processing state

This commit is contained in:
Abdelilah El Aissaoui 2022-06-11 13:37:09 +02:00
parent 878f6704d6
commit 1dff1d66b5

View file

@ -2,6 +2,7 @@ package app.git
import app.ErrorsManager
import app.di.TabScope
import app.extensions.delayedStateChange
import app.newErrorNow
import app.ui.SelectedItem
import kotlinx.coroutines.*
@ -61,10 +62,17 @@ class TabState @Inject constructor(
managerScope.launch(Dispatchers.IO) {
mutex.withLock {
var hasProcessFailed = false
_processing.value = true
operationRunning = true
try {
callback(safeGit)
delayedStateChange(
delayMs = 300,
onDelayTriggered = {
_processing.value = true
}
) {
callback(safeGit)
}
} catch (ex: Exception) {
hasProcessFailed = true
ex.printStackTrace()
@ -73,6 +81,7 @@ class TabState @Inject constructor(
errorsManager.addError(newErrorNow(ex, ex.message.orEmpty()))
} finally {
_processing.value = false
operationRunning = false
if (refreshType != RefreshType.NONE && (!hasProcessFailed || refreshEvenIfCrashes))
_refreshData.emit(refreshType)