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(() => {
|
$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'}
|
||||||
|
|||||||
Reference in New Issue
Block a user