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:
OneWay committed 2026-10-05 05:16:21 +08:00
1 parent d2c9dd7701
commit 9b6a34b607
1 file changed
+4 -1
@@ -277,9 +277,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()) {
@@ -296,12 +297,14 @@ class SettingsViewModel(
android.util.Log.w("SettingsViewModel", "Failed to load language preference: ${e.message}") android.util.Log.w("SettingsViewModel", "Failed to load language preference: ${e.message}")
} }
hasCompletedStartupScan.value = true hasCompletedStartupScan.value = true
if (scanCompleted) {
preferencesManager.setHadNoDictionaries( preferencesManager.setHadNoDictionaries(
localDictionaryRepository.dictionaries.value.isEmpty() localDictionaryRepository.dictionaries.value.isEmpty()
) )
} }
} }
} }
}
fun onEvent(event: SettingsUiEvent) { fun onEvent(event: SettingsUiEvent) {
when (event) { when (event) {