From 75909da2b676238f9dd745a9aac0449143175bc5 Mon Sep 17 00:00:00 2001
From: Ray Arayilakath <72509475+RayhanADev@users.noreply.github.com>
Date: Sat, 12 Jun 2021 14:37:47 +0000
Subject: [PATCH] feat: offline service workers
---
offline/index.html | 2 +-
service-worker.js | 14 +++++++-------
source/game.js | 4 ++++
source/index.html | 12 ------------
source/source-service-worker.js | 34 ---------------------------------
5 files changed, 12 insertions(+), 54 deletions(-)
delete mode 100644 source/source-service-worker.js
diff --git a/offline/index.html b/offline/index.html
index 8d3d8f0..5a8070a 100644
--- a/offline/index.html
+++ b/offline/index.html
@@ -1 +1 @@
-
tether!
\ No newline at end of file
+tether!
\ No newline at end of file
diff --git a/service-worker.js b/service-worker.js
index 58fe24e..c912d37 100644
--- a/service-worker.js
+++ b/service-worker.js
@@ -1,11 +1,11 @@
-const cacheName = 'tether_cache_v1';
+const cacheName = 'tether_cache-v2';
const precacheResources = [
- '/',
- '/offline.html',
- '/fonts/Quantico400.woff2',
- '/fonts/Quantico700.woff2',
- '/fonts/Tulpen-One400.woff2',
- '/favicon.ico',
+ '/',
+ '/fonts/Quantico400.woff2',
+ '/fonts/Quantico700.woff2',
+ '/fonts/Tulpen-One400.woff2',
+ '/icons/favicon-16x16.png',
+ '/tether_theme.mp3',
'/libs/font-awesome.min.css',
'/libs/fontawesome-webfont.woff'
];
diff --git a/source/game.js b/source/game.js
index 7538cc1..a841b35 100644
--- a/source/game.js
+++ b/source/game.js
@@ -34,6 +34,10 @@ var DEBUG = window.location.hash === '#DEBUG',
if(window.location.pathname === '/source/') subtitleText = 'Source Development Mode. #OpenSource';
else subtitleText = 'Swing around a ball and cause pure destruction.';
+setInterval(function() {
+ if(!navigator.onLine) subtitleText = 'Offline Mode.';
+}, 60000);
+
cookieExpiryDate.setFullYear(cookieExpiryDate.getFullYear() + 50);
var cookieSuffix = '; expires=' + cookieExpiryDate.toUTCString();
diff --git a/source/index.html b/source/index.html
index a552cc9..d0a7531 100644
--- a/source/index.html
+++ b/source/index.html
@@ -168,18 +168,6 @@
});
})();
-
diff --git a/source/source-service-worker.js b/source/source-service-worker.js
deleted file mode 100644
index 7733a55..0000000
--- a/source/source-service-worker.js
+++ /dev/null
@@ -1,34 +0,0 @@
-const cacheName = 'tether_source_cache-v2';
-const precacheResources = [
- '/',
- '/offline.html',
- '/fonts/Quantico400.woff2',
- '/fonts/Quantico700.woff2',
- '/fonts/Tulpen-One400.woff2',
- '/icons/favicon.ico',
- '/libs/font-awesome.min.css',
- '/libs/fontawesome-webfont.woff'
-];
-
-// When the service worker is installing, open the cache and add the precache resources to it
-self.addEventListener('install', (event) => {
- console.log('Service worker install event!');
- event.waitUntil(caches.open(cacheName).then((cache) => cache.addAll(precacheResources)));
-});
-
-self.addEventListener('activate', (event) => {
- console.log('Service worker activate event!');
-});
-
-// When there's an incoming fetch request, try and respond with a precached resource, otherwise fall back to the network
-self.addEventListener('fetch', (event) => {
- console.log('Fetch intercepted for:', event.request.url);
- event.respondWith(
- caches.match(event.request).then((cachedResponse) => {
- if (cachedResponse) {
- return cachedResponse;
- }
- return fetch(event.request);
- }),
- );
-});
\ No newline at end of file