fix: option state crash (#1456)

Co-authored-by: Ax333l <main@axelen.xyz>
This commit is contained in:
Benjamin 2023-11-02 08:46:53 -07:00 committed by GitHub
parent 8df7f2992d
commit 5fff0a2923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,10 +59,11 @@ class SelectedAppInfoViewModel(input: Params) : ViewModel(), KoinComponent {
var options: Options by savedStateHandle.saveable {
val state = mutableStateOf<Options>(emptyMap())
viewModelScope.launch(Dispatchers.Default) {
viewModelScope.launch {
if (!persistConfiguration) return@launch // TODO: save options for patched apps.
state.value = optionsRepository.getOptions(selectedApp.packageName)
val packageName = selectedApp.packageName // Accessing this from another thread may cause crashes.
state.value = withContext(Dispatchers.Default) { optionsRepository.getOptions(packageName) }
}
state