Removed done TODO tasks and added appScope cancellation on app exit

This commit is contained in:
Abdelilah El Aissaoui 2022-04-06 20:02:56 +02:00
parent ab9c8ce2df
commit 51ea75c033
4 changed files with 8 additions and 8 deletions

View File

@ -44,8 +44,6 @@ class App {
@Inject @Inject
lateinit var appPreferences: AppPreferences lateinit var appPreferences: AppPreferences
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
init { init {
appComponent.inject(this) appComponent.inject(this)
} }
@ -92,7 +90,7 @@ class App {
} }
} }
} else { } else {
appScope.cancel("Closing app") appStateManager.cancelCoroutines()
this.exitApplication() 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 // Stop any running jobs
val tabs = tabsFlow.value val tabs = tabsFlow.value
val tabToRemove = tabs.firstOrNull { it.key == key } ?: return@launch val tabToRemove = tabs.firstOrNull { it.key == key } ?: return@launch
@ -164,7 +162,7 @@ class App {
tabsFlow.value = tabsFlow.value.filter { tab -> tab.key != key } 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) } tabsFlow.value = tabsFlow.value.toMutableList().apply { add(tabInformation) }
} }

View File

@ -19,7 +19,7 @@ class AppStateManager @Inject constructor(
val latestOpenedRepositoriesPaths: List<String> val latestOpenedRepositoriesPaths: List<String>
get() = _latestOpenedRepositoriesPaths 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 val latestOpenedRepositoryPath: String
get() = _latestOpenedRepositoriesPaths.firstOrNull() ?: "" get() = _latestOpenedRepositoriesPaths.firstOrNull() ?: ""
@ -74,4 +74,8 @@ class AppStateManager @Inject constructor(
_latestOpenedRepositoriesPaths.addAll(repositories) _latestOpenedRepositoriesPaths.addAll(repositories)
} }
} }
fun cancelCoroutines() {
appStateScope.cancel("Closing app")
}
} }

View File

@ -15,7 +15,6 @@ class DiffViewModel @Inject constructor(
private val diffManager: DiffManager, private val diffManager: DiffManager,
private val statusManager: StatusManager, 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>(ViewDiffResult.Loading) private val _diffResult = MutableStateFlow<ViewDiffResult>(ViewDiffResult.Loading)
val diffResult: StateFlow<ViewDiffResult?> = _diffResult val diffResult: StateFlow<ViewDiffResult?> = _diffResult

View File

@ -65,7 +65,6 @@ class LogViewModel @Inject constructor(
_logStatus.value = LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statusSummary) _logStatus.value = LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statusSummary)
// Remove search filter if the log has been updated // Remove search filter if the log has been updated
// TODO: Should we just update the search instead of closing it?
_logSearchFilterResults.value = LogSearch.NotSearching _logSearchFilterResults.value = LogSearch.NotSearching
} }