T-013: Abgleich — periodischer Sync des Download-Stands (heilt bei Neustart/HMR verlorene Events); Badge/Chip unverändert
This commit is contained in:
@ -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(() => {
|
||||
checkAuth()
|
||||
const unlisten = onDownloadUpdate((it) => {
|
||||
@ -189,16 +189,27 @@
|
||||
info = `Download fertig: ${it.asin}`
|
||||
}
|
||||
})
|
||||
downloadList().then((list) => {
|
||||
const m: Record<string, DlItem> = {}
|
||||
for (const it of list) m[it.asin] = it
|
||||
downloads = m
|
||||
})
|
||||
// Abgleich: Events können bei App-Neustart/HMR verlorengehen — der
|
||||
// periodische Abgleich macht den Backend-Stand zur Autorität.
|
||||
const syncId = setInterval(syncDownloads, 3000)
|
||||
syncDownloads()
|
||||
return () => {
|
||||
clearPoll()
|
||||
clearInterval(syncId)
|
||||
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>
|
||||
|
||||
{#if view === 'loading'}
|
||||
|
||||
Reference in New Issue
Block a user