T-013: Abgleich — periodischer Sync des Download-Stands (heilt bei Neustart/HMR verlorene Events); Badge/Chip unverändert

This commit is contained in:
2026-11-06 19:56:38 +01:00
parent 55aa526ea0
commit 7095f06873

View File

@ -179,7 +179,7 @@
} }
} }
// Beim Start: auth prüfen, Download-Events abonnieren, Queue-Stand laden. // Beim Start: auth prüfen, Download-Events abonnieren, Abstammung + Abgleich.
$effect(() => { $effect(() => {
checkAuth() checkAuth()
const unlisten = onDownloadUpdate((it) => { const unlisten = onDownloadUpdate((it) => {
@ -189,16 +189,27 @@
info = `Download fertig: ${it.asin}` info = `Download fertig: ${it.asin}`
} }
}) })
downloadList().then((list) => { // Abgleich: Events können bei App-Neustart/HMR verlorengehen — der
const m: Record<string, DlItem> = {} // periodische Abgleich macht den Backend-Stand zur Autorität.
for (const it of list) m[it.asin] = it const syncId = setInterval(syncDownloads, 3000)
downloads = m syncDownloads()
})
return () => { return () => {
clearPoll() clearPoll()
clearInterval(syncId)
unlisten.then((f) => f()) unlisten.then((f) => f())
} }
}) })
async function syncDownloads(): Promise<void> {
try {
const list = await downloadList()
const m: Record<string, DlItem> = {}
for (const it of list) m[it.asin] = it
downloads = m
} catch {
// still ok — Events decken es ab
}
}
</script> </script>
{#if view === 'loading'} {#if view === 'loading'}