Skip to content

Commit

Permalink
check url local
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov N committed Dec 15, 2024
1 parent 47b6f0a commit 941f9c3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/store/plugins/navigatorOnline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { i18n } from '@/i18n'
import axios from 'axios'

const checkUrl = 'https://ipv4.icanhazip.com'
const checkUrl = 'robots.txt'

export default (store) => {
// window.addEventListener('online', handleEvent)
Expand All @@ -14,18 +14,20 @@ export default (store) => {
// store.commit('setIsOnline', false)
// }

setInterval(async () => {
const res = Boolean(await inetConnectionCheck())
const storeVal = store.getters['isOnline']
if (storeVal !== res) {
store.commit('setIsOnline', res)
const snackMsg = res ? 'online' : 'offline'
store.dispatch('snackbar/show', {
message: i18n.global.t(`connection.${snackMsg}`),
timeout: 3000
})
}
}, 1000)
window.onload = () => {
setInterval(async () => {
const res = Boolean(await inetConnectionCheck())
const storeVal = store.getters['isOnline']
if (storeVal !== res) {
store.commit('setIsOnline', res)
const snackMsg = res ? 'online' : 'offline'
store.dispatch('snackbar/show', {
message: i18n.global.t(`connection.${snackMsg}`),
timeout: 3000
})
}
}, 1000)
}
}

const inetConnectionCheck = async () => {
Expand Down

0 comments on commit 941f9c3

Please sign in to comment.