Fixed flickering when (un)staging many files due to file watcher updating
Commiting show progress bar
This commit is contained in:
parent
3f31cd2ac0
commit
7f6cc7c32a
@ -39,9 +39,7 @@ class FileChangesWatcher @Inject constructor() {
|
|||||||
var key: WatchKey
|
var key: WatchKey
|
||||||
while (watchService.take().also { key = it } != null) {
|
while (watchService.take().also { key = it } != null) {
|
||||||
this.emit(Unit)
|
this.emit(Unit)
|
||||||
for (event: WatchEvent<*> in key.pollEvents()) {
|
key.pollEvents()
|
||||||
println("Event kind: ${event.kind()}. File affected: ${event.context()}.")
|
|
||||||
}
|
|
||||||
key.reset()
|
key.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,13 @@ class GitManager @Inject constructor(
|
|||||||
val cloneStatus: StateFlow<CloneStatus> = remoteOperationsManager.cloneStatus
|
val cloneStatus: StateFlow<CloneStatus> = remoteOperationsManager.cloneStatus
|
||||||
val remotes: StateFlow<List<RemoteInfo>> = remotesManager.remotes
|
val remotes: StateFlow<List<RemoteInfo>> = remotesManager.remotes
|
||||||
|
|
||||||
|
|
||||||
private var git: Git? = null
|
private var git: Git? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property that indicates if a git operation is running
|
||||||
|
*/
|
||||||
|
@set:Synchronized private var operationRunning = false
|
||||||
|
|
||||||
private val safeGit: Git
|
private val safeGit: Git
|
||||||
get() {
|
get() {
|
||||||
val git = this.git
|
val git = this.git
|
||||||
@ -125,7 +129,7 @@ class GitManager @Inject constructor(
|
|||||||
pathStr = safeGit.repository.directory.parent,
|
pathStr = safeGit.repository.directory.parent,
|
||||||
ignoredDirsPath = ignored,
|
ignoredDirsPath = ignored,
|
||||||
).collect {
|
).collect {
|
||||||
if (!_processing.value) { // Only update if there isn't any process running
|
if (!operationRunning) { // Only update if there isn't any process running
|
||||||
safeProcessing(showError = false) {
|
safeProcessing(showError = false) {
|
||||||
println("Changes detected, loading status")
|
println("Changes detected, loading status")
|
||||||
statusManager.loadHasUncommitedChanges(safeGit)
|
statusManager.loadHasUncommitedChanges(safeGit)
|
||||||
@ -156,17 +160,23 @@ class GitManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stage(diffEntry: DiffEntry) = managerScope.launch {
|
fun stage(diffEntry: DiffEntry) = managerScope.launch {
|
||||||
|
runOperation {
|
||||||
statusManager.stage(safeGit, diffEntry)
|
statusManager.stage(safeGit, diffEntry)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun unstage(diffEntry: DiffEntry) = managerScope.launch {
|
fun unstage(diffEntry: DiffEntry) = managerScope.launch {
|
||||||
|
runOperation {
|
||||||
statusManager.unstage(safeGit, diffEntry)
|
statusManager.unstage(safeGit, diffEntry)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun commit(message: String) = managerScope.launch {
|
fun commit(message: String) = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
statusManager.commit(safeGit, message)
|
statusManager.commit(safeGit, message)
|
||||||
refreshRepositoryInfo()
|
refreshRepositoryInfo()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val hasUncommitedChanges: StateFlow<Boolean>
|
val hasUncommitedChanges: StateFlow<Boolean>
|
||||||
get() = statusManager.hasUncommitedChanges
|
get() = statusManager.hasUncommitedChanges
|
||||||
@ -251,10 +261,6 @@ class GitManager @Inject constructor(
|
|||||||
loadLog()
|
loadLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun statusShouldBeUpdated() {
|
|
||||||
_lastTimeChecked.value = System.currentTimeMillis()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun credentialsDenied() {
|
fun credentialsDenied() {
|
||||||
credentialsStateManager.updateState(CredentialsState.CredentialsDenied)
|
credentialsStateManager.updateState(CredentialsState.CredentialsDenied)
|
||||||
}
|
}
|
||||||
@ -272,12 +278,16 @@ class GitManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun unstageAll() = managerScope.launch {
|
fun unstageAll() = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
statusManager.unstageAll(safeGit)
|
statusManager.unstageAll(safeGit)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun stageAll() = managerScope.launch {
|
fun stageAll() = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
statusManager.stageAll(safeGit)
|
statusManager.stageAll(safeGit)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun checkoutCommit(revCommit: RevCommit) = managerScope.launch {
|
fun checkoutCommit(revCommit: RevCommit) = managerScope.launch {
|
||||||
safeProcessing {
|
safeProcessing {
|
||||||
@ -316,21 +326,6 @@ 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) {
|
|
||||||
_processing.value = true
|
|
||||||
try {
|
|
||||||
callback()
|
|
||||||
} catch (ex: Exception) {
|
|
||||||
ex.printStackTrace()
|
|
||||||
|
|
||||||
if (showError)
|
|
||||||
errorsManager.addError(newErrorNow(ex, ex.localizedMessage))
|
|
||||||
} finally {
|
|
||||||
_processing.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun checkoutRef(ref: Ref) = managerScope.launch {
|
fun checkoutRef(ref: Ref) = managerScope.launch {
|
||||||
safeProcessing {
|
safeProcessing {
|
||||||
logManager.checkoutRef(safeGit, ref)
|
logManager.checkoutRef(safeGit, ref)
|
||||||
@ -356,6 +351,33 @@ class GitManager @Inject constructor(
|
|||||||
fun findCommit(objectId: ObjectId): RevCommit {
|
fun findCommit(objectId: ObjectId): RevCommit {
|
||||||
return safeGit.repository.parseCommit(objectId)
|
return safeGit.repository.parseCommit(objectId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private suspend fun safeProcessing(showError: Boolean = true, callback: suspend () -> Unit) {
|
||||||
|
_processing.value = true
|
||||||
|
operationRunning = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
callback()
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
ex.printStackTrace()
|
||||||
|
|
||||||
|
if (showError)
|
||||||
|
errorsManager.addError(newErrorNow(ex, ex.localizedMessage))
|
||||||
|
} finally {
|
||||||
|
_processing.value = false
|
||||||
|
operationRunning = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun runOperation(block: () -> Unit) {
|
||||||
|
operationRunning = true
|
||||||
|
try {
|
||||||
|
block()
|
||||||
|
} finally {
|
||||||
|
operationRunning = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user