Added try catch to dir opening to avoid crash if the dir has been removed

This commit is contained in:
Abdelilah El Aissaoui 2022-01-31 23:42:42 +01:00
parent ef1e18fb91
commit edbb095246
2 changed files with 7 additions and 3 deletions

View File

@ -95,13 +95,18 @@ class TabState @Inject constructor(
}
}
fun runOperation(block: suspend (git: Git) -> RefreshType) = managerScope.launch(Dispatchers.IO) {
fun runOperation(showError: Boolean = false, block: suspend (git: Git) -> RefreshType) = managerScope.launch(Dispatchers.IO) {
operationRunning = true
try {
val refreshType = block(safeGit)
if (refreshType != RefreshType.NONE)
_refreshData.emit(refreshType)
} catch (ex: Exception) {
ex.printStackTrace()
if (showError)
errorsManager.addError(newErrorNow(ex, ex.localizedMessage))
} finally {
operationRunning = false
}

View File

@ -5,7 +5,6 @@ import app.git.RemoteOperationsManager
import app.git.StashManager
import app.git.TabState
import java.awt.Desktop
import java.io.File
import javax.inject.Inject
class MenuViewModel @Inject constructor(
@ -41,7 +40,7 @@ class MenuViewModel @Inject constructor(
return@safeProcessing RefreshType.UNCOMMITED_CHANGES
}
fun openFolderInFileExplorer() = tabState.runOperation { git ->
fun openFolderInFileExplorer() = tabState.runOperation (showError = true) { git ->
Desktop.getDesktop().open(git.repository.directory.parentFile)
return@runOperation RefreshType.NONE