Changed how status is refreshed
Now LaunchEffect is used instead of starting the coroutine from the gitmanager. This way compose will take care of cancelling the coroutine if needed
This commit is contained in:
parent
3cde9d44ad
commit
fcea394f35
@ -4,13 +4,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.diff.DiffEntry
|
||||
import org.eclipse.jgit.diff.DiffFormatter
|
||||
import org.eclipse.jgit.dircache.DirCacheIterator
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
||||
import org.eclipse.jgit.treewalk.FileTreeIterator
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
|
||||
|
||||
@ -33,6 +29,10 @@ class GitManager {
|
||||
val processing: StateFlow<Boolean>
|
||||
get() = _processing
|
||||
|
||||
private val _lastTimeChecked = MutableStateFlow(System.currentTimeMillis())
|
||||
val lastTimeChecked: StateFlow<Long>
|
||||
get() = _lastTimeChecked
|
||||
|
||||
val stageStatus: StateFlow<StageStatus>
|
||||
get() = statusManager.stageStatus
|
||||
|
||||
@ -104,7 +104,7 @@ class GitManager {
|
||||
logManager.loadLog(safeGit)
|
||||
}
|
||||
|
||||
fun loadStatus() = managerScope.launch {
|
||||
suspend fun loadStatus() {
|
||||
statusManager.loadStatus(safeGit)
|
||||
}
|
||||
|
||||
@ -168,6 +168,10 @@ class GitManager {
|
||||
fun resetUnstaged(diffEntry: DiffEntry) = managerScope.launch {
|
||||
statusManager.reset(safeGit, diffEntry, staged = false)
|
||||
}
|
||||
|
||||
fun statusShouldBeUpdated() {
|
||||
_lastTimeChecked.value = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,9 +51,7 @@ fun RepositorySelected(gitManager: GitManager, repository: Repository) {
|
||||
gitManager = gitManager,
|
||||
selectedIndex = selectedIndexCommitLog,
|
||||
onRevCommitSelected = { commit ->
|
||||
uncommitedChangesSelected = false
|
||||
// TODO Move all this code to tree manager
|
||||
gitManager.loadStatus()
|
||||
|
||||
val parent = if (commit.parentCount == 0) {
|
||||
null
|
||||
@ -76,10 +74,13 @@ fun RepositorySelected(gitManager: GitManager, repository: Repository) {
|
||||
|
||||
selectedRevCommit = commit to diffs
|
||||
}
|
||||
|
||||
|
||||
uncommitedChangesSelected = false
|
||||
},
|
||||
onUncommitedChangesSelected = {
|
||||
gitManager.statusShouldBeUpdated()
|
||||
uncommitedChangesSelected = true
|
||||
gitManager.loadStatus()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -45,6 +45,11 @@ fun UncommitedChanges(
|
||||
) {
|
||||
val stageStatusState = gitManager.stageStatus.collectAsState()
|
||||
val stageStatus = stageStatusState.value
|
||||
val lastCheck by gitManager.lastTimeChecked.collectAsState()
|
||||
|
||||
LaunchedEffect(lastCheck) {
|
||||
gitManager.loadStatus()
|
||||
}
|
||||
|
||||
val (staged, unstaged) = if (stageStatus is StageStatus.Loaded) {
|
||||
stageStatus.staged to stageStatus.unstaged
|
||||
|
Loading…
Reference in New Issue
Block a user