From bf2fcc6641643018bd5224ec2f8308173d54cfa4 Mon Sep 17 00:00:00 2001 From: Pierre <397503+bemble@users.noreply.github.com> Date: Mon, 9 May 2022 23:47:05 +0200 Subject: feat(pwa): enhance connectivity checks Also add support to auth proxy such as Authelia --- src/components/ConnectivityChecker.vue | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/components') diff --git a/src/components/ConnectivityChecker.vue b/src/components/ConnectivityChecker.vue index 02cbd7f..a717bcf 100644 --- a/src/components/ConnectivityChecker.vue +++ b/src/components/ConnectivityChecker.vue @@ -29,15 +29,40 @@ 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 (response) { + // opaqueredirect means request has been redirected, to auth provider probably + if (response.type === "opaqueredirect" && !response.ok) { + window.location.reload(true); + } that.offline = !response.ok; }) .catch(function () { -- cgit v1.2.3