fix(settings): write the no-dictionaries seed only after a completed scan
A racing SettingsViewModel whose scan short-circuits with an in-progress error persisted hadNoDictionaries from a still-empty list, forcing the Settings screen on the next cold start despite existing dictionaries.
This commit is contained in:
1 parent
bd253e3e37
commit
a2079a37a1
1 file changed
+7
-4
@@ -274,9 +274,10 @@ class SettingsViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initialize() {
|
private fun initialize() {
|
||||||
|
var scanCompleted = false
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
scanDirectoryInternal(preferencesManager.dictionaryPath)
|
scanCompleted = scanDirectoryInternal(preferencesManager.dictionaryPath) is OperationResult.Success
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.e("SettingsViewModel", "Initial scan failed", e)
|
android.util.Log.e("SettingsViewModel", "Initial scan failed", e)
|
||||||
dictionaryStatus.value = if (localDictionaryRepository.dictionaries.value.isEmpty()) {
|
dictionaryStatus.value = if (localDictionaryRepository.dictionaries.value.isEmpty()) {
|
||||||
@@ -299,9 +300,11 @@ class SettingsViewModel(
|
|||||||
}
|
}
|
||||||
hasLoadedPreferences.value = true
|
hasLoadedPreferences.value = true
|
||||||
hasCompletedStartupScan.value = true
|
hasCompletedStartupScan.value = true
|
||||||
preferencesManager.setHadNoDictionaries(
|
if (scanCompleted) {
|
||||||
localDictionaryRepository.dictionaries.value.isEmpty()
|
preferencesManager.setHadNoDictionaries(
|
||||||
)
|
localDictionaryRepository.dictionaries.value.isEmpty()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user