From 51ea75c033fefa4bbe5bae4110be60c9cf4e0f65 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Wed, 6 Apr 2022 20:02:56 +0200 Subject: [PATCH] Removed done TODO tasks and added appScope cancellation on app exit --- src/main/kotlin/app/App.kt | 8 +++----- src/main/kotlin/app/AppStateManager.kt | 6 +++++- src/main/kotlin/app/viewmodels/DiffViewModel.kt | 1 - src/main/kotlin/app/viewmodels/LogViewModel.kt | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/app/App.kt b/src/main/kotlin/app/App.kt index 188520d..3a59664 100644 --- a/src/main/kotlin/app/App.kt +++ b/src/main/kotlin/app/App.kt @@ -44,8 +44,6 @@ class App { @Inject lateinit var appPreferences: AppPreferences - private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) - init { appComponent.inject(this) } @@ -92,7 +90,7 @@ class App { } } } else { - appScope.cancel("Closing app") + appStateManager.cancelCoroutines() this.exitApplication() } } @@ -151,7 +149,7 @@ class App { } } - private fun removeTab(key: Int) = appScope.launch(Dispatchers.IO) { + private fun removeTab(key: Int) = appStateManager.appStateScope.launch(Dispatchers.IO) { // Stop any running jobs val tabs = tabsFlow.value val tabToRemove = tabs.firstOrNull { it.key == key } ?: return@launch @@ -164,7 +162,7 @@ class App { tabsFlow.value = tabsFlow.value.filter { tab -> tab.key != key } } - fun addTab(tabInformation: TabInformation) = appScope.launch(Dispatchers.IO) { + fun addTab(tabInformation: TabInformation) = appStateManager.appStateScope.launch(Dispatchers.IO) { tabsFlow.value = tabsFlow.value.toMutableList().apply { add(tabInformation) } } diff --git a/src/main/kotlin/app/AppStateManager.kt b/src/main/kotlin/app/AppStateManager.kt index 1246267..79482a5 100644 --- a/src/main/kotlin/app/AppStateManager.kt +++ b/src/main/kotlin/app/AppStateManager.kt @@ -19,7 +19,7 @@ class AppStateManager @Inject constructor( val latestOpenedRepositoriesPaths: List get() = _latestOpenedRepositoriesPaths - private val appStateScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) // TODO Stop this when closing the app + val appStateScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) val latestOpenedRepositoryPath: String get() = _latestOpenedRepositoriesPaths.firstOrNull() ?: "" @@ -74,4 +74,8 @@ class AppStateManager @Inject constructor( _latestOpenedRepositoriesPaths.addAll(repositories) } } + + fun cancelCoroutines() { + appStateScope.cancel("Closing app") + } } \ No newline at end of file diff --git a/src/main/kotlin/app/viewmodels/DiffViewModel.kt b/src/main/kotlin/app/viewmodels/DiffViewModel.kt index 8d1e5c4..2a360f9 100644 --- a/src/main/kotlin/app/viewmodels/DiffViewModel.kt +++ b/src/main/kotlin/app/viewmodels/DiffViewModel.kt @@ -15,7 +15,6 @@ class DiffViewModel @Inject constructor( private val diffManager: DiffManager, private val statusManager: StatusManager, ) { - // TODO Maybe use a sealed class instead of a null to represent that a diff is not selected? private val _diffResult = MutableStateFlow(ViewDiffResult.Loading) val diffResult: StateFlow = _diffResult diff --git a/src/main/kotlin/app/viewmodels/LogViewModel.kt b/src/main/kotlin/app/viewmodels/LogViewModel.kt index e2faaf8..29adabd 100644 --- a/src/main/kotlin/app/viewmodels/LogViewModel.kt +++ b/src/main/kotlin/app/viewmodels/LogViewModel.kt @@ -65,7 +65,6 @@ class LogViewModel @Inject constructor( _logStatus.value = LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statusSummary) // Remove search filter if the log has been updated - // TODO: Should we just update the search instead of closing it? _logSearchFilterResults.value = LogSearch.NotSearching }