Fixed concurrency errors when trying to update recent repositories
This commit is contained in:
parent
b399947734
commit
9bf5fc4663
@ -1,6 +1,7 @@
|
||||
package app
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
@ -11,6 +12,8 @@ import javax.inject.Singleton
|
||||
class AppStateManager @Inject constructor(
|
||||
private val appPreferences: AppPreferences,
|
||||
) {
|
||||
private val mutex = Mutex()
|
||||
|
||||
private val _openRepositoriesPaths = mutableMapOf<Int, String>()
|
||||
val openRepositoriesPathsTabs: Map<Int, String>
|
||||
get() = _openRepositoriesPaths
|
||||
@ -25,6 +28,8 @@ class AppStateManager @Inject constructor(
|
||||
get() = _latestOpenedRepositoriesPaths.firstOrNull() ?: ""
|
||||
|
||||
fun repositoryTabChanged(key: Int, path: String) = appStateScope.launch(Dispatchers.IO) {
|
||||
mutex.lock()
|
||||
try {
|
||||
// Do not save already saved repos
|
||||
if (!_openRepositoriesPaths.containsValue(path))
|
||||
_openRepositoriesPaths[key] = path
|
||||
@ -40,6 +45,9 @@ class AppStateManager @Inject constructor(
|
||||
|
||||
updateSavedRepositoryTabs()
|
||||
updateLatestRepositoryTabs()
|
||||
} finally {
|
||||
mutex.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
fun repositoryTabRemoved(key: Int) = appStateScope.launch(Dispatchers.IO) {
|
||||
|
Loading…
Reference in New Issue
Block a user