mirror of
https://github.com/koel/koel
synced 2024-12-25 20:13:06 +00:00
22 lines
554 B
TypeScript
22 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
|
||
|
}
|
||
|
}
|