diff options
author | Bastien Wirtz <bastien.wirtz@gmail.com> | 2020-05-30 23:22:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-30 23:22:02 -0700 |
commit | 5fa6b6cfa6b3010279ead23088add5c5664e8ac0 (patch) | |
tree | 5f3ffa4dc62b4355d38346ef0155878ca6aeedcd /src/components/ConnectivityChecker.vue | |
parent | ab7ac44c191e3b7dea696e76b74097e23f73b18c (diff) | |
parent | 9052ec59b75a37b4518ad39c493ee6c2d4198b98 (diff) | |
download | homer-5fa6b6cfa6b3010279ead23088add5c5664e8ac0.tar.gz homer-5fa6b6cfa6b3010279ead23088add5c5664e8ac0.tar.zst homer-5fa6b6cfa6b3010279ead23088add5c5664e8ac0.zip |
Merge pull request #62 from bastienwirtz/dev/build-system120405250
Build system integration using vue-cli.
Diffstat (limited to 'src/components/ConnectivityChecker.vue')
-rw-r--r-- | src/components/ConnectivityChecker.vue | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/components/ConnectivityChecker.vue b/src/components/ConnectivityChecker.vue new file mode 100644 index 0000000..a91a809 --- /dev/null +++ b/src/components/ConnectivityChecker.vue | |||
@@ -0,0 +1,52 @@ | |||
1 | <template> | ||
2 | <div v-if="offline" class="offline-message"> | ||
3 | <i class="far fa-dizzy"></i> | ||
4 | <h1> | ||
5 | You're offline bro. | ||
6 | <span @click="checkOffline"> <i class="fas fa-redo-alt"></i></span> | ||
7 | </h1> | ||
8 | </div> | ||
9 | </template> | ||
10 | |||
11 | <script> | ||
12 | export default { | ||
13 | name: "ConnectivityChecker", | ||
14 | data: function () { | ||
15 | return { | ||
16 | offline: false, | ||
17 | }; | ||
18 | }, | ||
19 | created: function () { | ||
20 | let that = this; | ||
21 | this.checkOffline(); | ||
22 | |||
23 | document.addEventListener( | ||
24 | "visibilitychange", | ||
25 | function () { | ||
26 | if (document.visibilityState == "visible") { | ||
27 | that.checkOffline(); | ||
28 | } | ||
29 | }, | ||
30 | false | ||
31 | ); | ||
32 | }, | ||
33 | methods: { | ||
34 | checkOffline: function () { | ||
35 | let that = this; | ||
36 | return fetch(window.location.href + "?alive", { | ||
37 | method: "HEAD", | ||
38 | cache: "no-store", | ||
39 | }) | ||
40 | .then(function () { | ||
41 | that.offline = false; | ||
42 | }) | ||
43 | .catch(function () { | ||
44 | that.offline = true; | ||
45 | }) | ||
46 | .finally(function () { | ||
47 | that.$emit("network:status-update", that.offline); | ||
48 | }); | ||
49 | }, | ||
50 | }, | ||
51 | }; | ||
52 | </script> | ||