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.
This commit is contained in:
OneWay committed 2026-10-04 12:09:00 +00:00
1 parent 6514e81804
commit c56bb4e2a6
1 file changed
+23 -1
@@ -519,6 +519,25 @@ class SettingsViewModel(
): List<DictionarySource> = ): List<DictionarySource> =
DictionarySourceFileMatcher.installedSources(sources, dictionaries) 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() { private fun cancelDownload() {
// Cancel the ViewModel-side scan job so no further status recomputes // Cancel the ViewModel-side scan job so no further status recomputes
localDictionaryRepository.cancelIndexing() localDictionaryRepository.cancelIndexing()
@@ -579,7 +598,10 @@ class SettingsViewModel(
"NeedsUpdate" -> DictionaryStatus.NeedsUpdate "NeedsUpdate" -> DictionaryStatus.NeedsUpdate
else -> null else -> null
} }
if (restoredStatus != null && savedStatusDate == DateUtils.getCurrentDateString()) { if (restoredStatus != null &&
savedStatusDate == DateUtils.getCurrentDateString() &&
withContext(Dispatchers.IO) { installedDictionariesAreCurrent() }
) {
dictionaryStatus.value = restoredStatus dictionaryStatus.value = restoredStatus
} else { } else {
dictionaryStatus.value = DictionaryStatus.Checking dictionaryStatus.value = DictionaryStatus.Checking