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() {
|
||||
var scanCompleted = false
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
scanDirectoryInternal(preferencesManager.dictionaryPath)
|
||||
scanCompleted = scanDirectoryInternal(preferencesManager.dictionaryPath) is OperationResult.Success
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("SettingsViewModel", "Initial scan failed", e)
|
||||
dictionaryStatus.value = if (localDictionaryRepository.dictionaries.value.isEmpty()) {
|
||||
@@ -299,9 +300,11 @@ class SettingsViewModel(
|
||||
}
|
||||
hasLoadedPreferences.value = true
|
||||
hasCompletedStartupScan.value = true
|
||||
preferencesManager.setHadNoDictionaries(
|
||||
localDictionaryRepository.dictionaries.value.isEmpty()
|
||||
)
|
||||
if (scanCompleted) {
|
||||
preferencesManager.setHadNoDictionaries(
|
||||
localDictionaryRepository.dictionaries.value.isEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user