fix(web): localStorage safety, default fetch timeout, visibility-aware polling

This commit is contained in:
2026-04-29 12:00:40 +08:00
parent 7377c2135f
commit 357d08f2e3
5 changed files with 210 additions and 43 deletions
+24 -2
View File
@@ -18,13 +18,35 @@ export function useUnreadPoller() {
}
}
onMounted(() => {
function start() {
if (timer !== null) return
refresh()
timer = setInterval(refresh, POLL_INTERVAL_MS)
}
function stop() {
if (timer !== null) {
clearInterval(timer)
timer = null
}
}
function onVisibilityChange() {
if (document.hidden) {
stop()
} else {
start()
}
}
onMounted(() => {
start()
document.addEventListener('visibilitychange', onVisibilityChange)
})
onUnmounted(() => {
if (timer) clearInterval(timer)
document.removeEventListener('visibilitychange', onVisibilityChange)
stop()
})
return { refresh, error }