Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 2585753

Browse files
committed
fix early exception handling
1 parent 8d070c9 commit 2585753

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

app/src/main/java/com/github/capntrips/devinfopatcher/MainViewModel.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlinx.coroutines.launch
1111

1212
class MainViewModel constructor(context: Context) : ViewModel(), MainViewModelInterface {
1313
private val _isRefreshing: MutableStateFlow<Boolean> = MutableStateFlow(false)
14-
private var _uiState: MutableStateFlow<DeviceStateInterface> = MutableStateFlow(DeviceState(context, _isRefreshing))
14+
private lateinit var _uiState: MutableStateFlow<DeviceStateInterface>
1515
private var _error: String? = null
1616

1717
override val isRefreshing: StateFlow<Boolean>
@@ -23,6 +23,14 @@ class MainViewModel constructor(context: Context) : ViewModel(), MainViewModelIn
2323
val error: String
2424
get() = _error ?: "Unknown Error"
2525

26+
init {
27+
try {
28+
_uiState = MutableStateFlow(DeviceState(context, _isRefreshing))
29+
} catch (e: Exception) {
30+
_error = e.message
31+
}
32+
}
33+
2634
private fun launch(block: suspend () -> Unit) {
2735
viewModelScope.launch(Dispatchers.IO) {
2836
_isRefreshing.emit(true)

0 commit comments

Comments
 (0)