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
+7 -4
@@ -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,9 +297,11 @@ 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
preferencesManager.setHadNoDictionaries( if (scanCompleted) {
localDictionaryRepository.dictionaries.value.isEmpty() preferencesManager.setHadNoDictionaries(
) localDictionaryRepository.dictionaries.value.isEmpty()
)
}
} }
} }
} }