X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fcomponents%2FConnectivityChecker.vue;h=1c677d24a068c1ef742ea7060027a786010702ee;hb=98b460d6fe0e09cbdbf37f882f5e5bf7daa48e73;hp=d41c4437442e46256749f2230d1fa3755892ab5f;hpb=c6267296ec03db24ff40959ef58eedcec904c39b;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/components/ConnectivityChecker.vue b/src/components/ConnectivityChecker.vue index d41c443..1c677d2 100644 --- a/src/components/ConnectivityChecker.vue +++ b/src/components/ConnectivityChecker.vue @@ -17,6 +17,9 @@ export default { }; }, created: function () { + if (/t=\d+/.test(window.location.href)) { + window.history.replaceState({}, document.title, window.location.pathname); + } let that = this; this.checkOffline(); @@ -29,16 +32,41 @@ export default { }, false ); + window.addEventListener( + "online", + function () { + that.checkOffline(); + }, + false + ); + window.addEventListener( + "offline", + function () { + this.offline = true; + }, + false + ); }, methods: { checkOffline: function () { + if (!navigator.onLine) { + this.offline = true; + return; + } + + // extra check to make sure we're not offline let that = this; return fetch(window.location.href + "?alive", { method: "HEAD", cache: "no-store", + redirect: "manual" }) - .then(function () { - that.offline = false; + .then(function (response) { + // opaqueredirect means request has been redirected, to auth provider probably + if (response.type === "opaqueredirect" && !response.ok) { + window.location.href = window.location.href + "?t="+(new Date().valueOf()); + } + that.offline = !response.ok; }) .catch(function () { that.offline = true;