From c56bb4e2a685436f658b554651a77a010c33e34e Mon Sep 17 00:00:00 2001 From: OneWay Date: Sun, 4 Oct 2026 12:09:00 +0000 Subject: [PATCH] fix(download): verify payload freshness before restoring the update state On restart the update-available state was restored purely from the saved date. Also compare the installed payload file names against dated sources, and re-check when they no longer match. --- .../research/ui/settings/SettingsViewModel.kt | 24 ++++++++++++++++++- 1 file changed, 23 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 f557125..893444f 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 @@ -519,6 +519,25 @@ class SettingsViewModel( ): List = DictionarySourceFileMatcher.installedSources(sources, dictionaries) + private suspend fun installedDictionariesAreCurrent(): Boolean { + val sources = preferencesManager.dictionarySources.first() + val dictionaries = localDictionaryRepository.dictionaries.first() + val datedEnabledSources = installedEnabledSources(sources, dictionaries) + .filter { DictionarySource.hasDatePlaceholder(it.urlTemplate) } + if (datedEnabledSources.isEmpty()) return true + val fileNames = localDictionaryRepository.listDictionaryPayloadFileNames( + preferencesManager.dictionaryPath + ) ?: return true + val today = DateUtils.getCurrentDateString() + return datedEnabledSources.all { source -> + val baseName = DictionarySource.extractFileName(source.urlTemplate, today) + .removeSuffix(".gz") + .removeSuffix(".dsl") + .removeSuffix(".dz") + fileNames.any { it.startsWith(baseName) } + } + } + private fun cancelDownload() { // Cancel the ViewModel-side scan job so no further status recomputes localDictionaryRepository.cancelIndexing() @@ -579,7 +598,10 @@ class SettingsViewModel( "NeedsUpdate" -> DictionaryStatus.NeedsUpdate else -> null } - if (restoredStatus != null && savedStatusDate == DateUtils.getCurrentDateString()) { + if (restoredStatus != null && + savedStatusDate == DateUtils.getCurrentDateString() && + withContext(Dispatchers.IO) { installedDictionariesAreCurrent() } + ) { dictionaryStatus.value = restoredStatus } else { dictionaryStatus.value = DictionaryStatus.Checking