From 5c655e769c71674422302e1f9c1ee3e4c4d7bc8d Mon Sep 17 00:00:00 2001 From: OneWay Date: Tue, 6 Oct 2026 09:42:54 +0800 Subject: [PATCH] fix(settings): skip the startup scan when dictionaries are already loaded A second activity instance (PROCESS_TEXT) ran the full directory scan again, and the main screen stayed blank until the scan finished. The repository is a process-wide singleton: when it already holds dictionaries, mark them up to date and load preferences immediately. --- .../com/example/research/ui/settings/SettingsViewModel.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt index 0f86e1d..a9647c8 100644 --- a/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/example/research/ui/settings/SettingsViewModel.kt @@ -280,7 +280,12 @@ class SettingsViewModel( var scanCompleted = false viewModelScope.launch { try { - scanCompleted = scanDirectoryInternal(preferencesManager.dictionaryPath) is OperationResult.Success + scanCompleted = if (localDictionaryRepository.dictionaries.value.isEmpty()) { + scanDirectoryInternal(preferencesManager.dictionaryPath) is OperationResult.Success + } else { + dictionaryStatus.value = DictionaryStatus.UpToDate + false + } } catch (e: Exception) { android.util.Log.e("SettingsViewModel", "Initial scan failed", e) dictionaryStatus.value = if (localDictionaryRepository.dictionaries.value.isEmpty()) {