Fixed FileWatcher triggering status update while an operation is running

This commit is contained in:
Abdelilah El Aissaoui 2021-12-14 13:40:01 +01:00
parent cd19a62ae9
commit 23a6b741b8

View File

@ -121,15 +121,16 @@ class GitManager @Inject constructor(
private suspend fun watchRepositoryChanges() { private suspend fun watchRepositoryChanges() {
val ignored = safeGit.status().call().ignoredNotInIndex.toList() val ignored = safeGit.status().call().ignoredNotInIndex.toList()
fileChangesWatcher.watchDirectoryPath( fileChangesWatcher.watchDirectoryPath(
pathStr = safeGit.repository.directory.parent, pathStr = safeGit.repository.directory.parent,
ignoredDirsPath = ignored, ignoredDirsPath = ignored,
).collect { ).collect {
safeProcessing(showError = false) { if (!_processing.value) { // Only update if there isn't any process running
println("Changes detected, loading status") safeProcessing(showError = false) {
statusManager.loadHasUncommitedChanges(safeGit) println("Changes detected, loading status")
statusManager.loadStatus(safeGit) statusManager.loadHasUncommitedChanges(safeGit)
statusManager.loadStatus(safeGit)
}
} }
} }
} }
@ -315,6 +316,7 @@ class GitManager @Inject constructor(
var onRepositoryChanged: (path: String?) -> Unit = {} var onRepositoryChanged: (path: String?) -> Unit = {}
@Synchronized
private suspend fun safeProcessing(showError: Boolean = true, callback: suspend () -> Unit) { private suspend fun safeProcessing(showError: Boolean = true, callback: suspend () -> Unit) {
_processing.value = true _processing.value = true
try { try {