feat: offline resilience and connection status

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 00:27:05 +00:00
co-authored by Claude Opus 4.6
parent 627a1a0d9e
commit 6e092ee7be
4 changed files with 131 additions and 1 deletions
@@ -0,0 +1,28 @@
import { ref, onMounted, onUnmounted } from 'vue'
const isOnline = ref(typeof navigator !== 'undefined' ? navigator.onLine : true)
let listenerCount = 0
function handleOnline() { isOnline.value = true }
function handleOffline() { isOnline.value = false }
export function useOnlineStatus() {
onMounted(() => {
if (listenerCount === 0) {
window.addEventListener('online', handleOnline)
window.addEventListener('offline', handleOffline)
}
listenerCount++
})
onUnmounted(() => {
listenerCount--
if (listenerCount === 0) {
window.removeEventListener('online', handleOnline)
window.removeEventListener('offline', handleOffline)
}
})
return { isOnline }
}