mirror of
https://github.com/koel/koel
synced 2024-11-15 08:57:16 +00:00
21 lines
554 B
TypeScript
21 lines
554 B
TypeScript
import { computed, onUnmounted, ref } from 'vue'
|
|
|
|
export const useNetworkStatus = () => {
|
|
const online = ref(navigator.onLine)
|
|
const offline = computed(() => !online.value)
|
|
|
|
const updateOnlineStatus = () => (online.value = navigator.onLine)
|
|
|
|
window.addEventListener('online', updateOnlineStatus)
|
|
window.addEventListener('offline', updateOnlineStatus)
|
|
|
|
onUnmounted(() => {
|
|
window.removeEventListener('online', updateOnlineStatus)
|
|
window.removeEventListener('offline', updateOnlineStatus)
|
|
})
|
|
|
|
return {
|
|
online,
|
|
offline
|
|
}
|
|
}
|