Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: ignore exception while reading opened files cache (fixes #1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Dec 16, 2023
1 parent 7aa4a8f commit c9f346e
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.io.IOException
import java.util.Collections

/** ViewModel for data used in [com.itsaky.androidide.activities.editor.EditorActivityKt] */
Expand Down Expand Up @@ -230,10 +231,15 @@ class EditorViewModel : ViewModel() {
inline fun getOrReadOpenedFilesCache(crossinline result: (OpenedFilesCache?) -> Unit) {
return openedFilesCache?.let(result) ?: run {
viewModelScope.launch(Dispatchers.IO) {
val cache = getOpenedFilesCache(false).takeIf { it.exists() && it.length() > 0L }
?.bufferedReader()?.use { reader ->
OpenedFilesCache.parse(reader)
}
val cache = try {
val cacheFile = getOpenedFilesCache(false)
if (cacheFile.exists() && cacheFile.length() > 0L) {
cacheFile.bufferedReader().use(OpenedFilesCache::parse)
} else null
} catch (err: IOException) {
// ignore exception
null
}

withContext(Dispatchers.Main) {
result(cache)
Expand Down

0 comments on commit c9f346e

Please sign in to comment.