aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Stendahl <jakobste@uio.no>2021-01-11 21:40:16 +0100
committerJakob Stendahl <jakobste@uio.no>2021-01-11 21:40:16 +0100
commitadab47e51d27f5e45f0bc1ad00ed340423bcbebb (patch)
treea92d2a8d054774865ebe06346bd516a07e3d44bf
parent5503baa65102b47d8f2b07fc69b0ebad9507613c (diff)
downloadhoverbit-ble-adab47e51d27f5e45f0bc1ad00ed340423bcbebb.tar.gz
hoverbit-ble-adab47e51d27f5e45f0bc1ad00ed340423bcbebb.zip
:sparkles: Add manifest
-rw-r--r--icon.pngbin0 -> 21396 bytes
-rw-r--r--index.html2
-rw-r--r--manifest.json16
-rw-r--r--script.js5
-rw-r--r--sw.js61
5 files changed, 83 insertions, 1 deletions
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..be75d96
--- /dev/null
+++ b/icon.png
Binary files differ
diff --git a/index.html b/index.html
index a704871..83ee48c 100644
--- a/index.html
+++ b/index.html
@@ -4,7 +4,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>HOVER:BIT Controller</title>
+ <link rel="canonical" rel="https://jakobst1n.github.io/hoverbit-ble/">
<link rel="stylesheet" type="text/css" href="styles.css">
+ <link rel="manifest" href="manifest.json" crossorigin="use-credentials">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script type="text/javascript" src="microbit.umd.js"></script>
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 0000000..573118f
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,16 @@
+{
+ "background_color": "#464a47",
+ "theme_color": "#5ac775",
+ "name": "HOVERBIT Controller",
+ "short_name": "HOVERBIT BLE",
+ "display": "fullscreen",
+ "start_url": "/microbit-ble/",
+ "orientation": "landscape",
+ "icons": [
+ {
+ "src": "icon.png",
+ "sizes": "512x512",
+ "type": "image/png"
+ }
+ ]
+}
diff --git a/script.js b/script.js
index dc61b25..4376d15 100644
--- a/script.js
+++ b/script.js
@@ -1,5 +1,8 @@
-let StickyControls = false;
+if (navigator.serviceWorker) {
+ navigator.serviceWorker.register('/hoverbit-ble/sw.js', {scope: '/hoverbit-ble/'})
+}
+let StickyControls = false;
let throttleElement = document.querySelector(".throttle");
let rudderElement = document.querySelector(".rudder");
diff --git a/sw.js b/sw.js
new file mode 100644
index 0000000..bc3f42d
--- /dev/null
+++ b/sw.js
@@ -0,0 +1,61 @@
+var APP_PREFIX = 'hoverbitcontroller' // Identifier for this app (this needs to be consistent across every cache update)
+var VERSION = 'version_01' // Version of the off-line cache (change this value everytime you want to update cache)
+var CACHE_NAME = APP_PREFIX + VERSION
+var URLS = [ // Add URL you want to cache in this list.
+ '/hoverbit-ble/', // If you have separate JS/CSS files,
+ '/hoverbit-ble/index.html', // add path to those files here
+ '/hoverbit-ble/styles.css',
+ '/hoverbit-ble/microbit.umd.js',
+ '/hoverbit-ble/script.js'
+]
+
+// Respond with cached resources
+self.addEventListener('fetch', function (e) {
+ console.log('fetch request : ' + e.request.url)
+ e.respondWith(
+ caches.match(e.request).then(function (request) {
+ if (request) { // if cache is available, respond with cache
+ console.log('responding with cache : ' + e.request.url)
+ return request
+ } else { // if there are no cache, try fetching request
+ console.log('file is not cached, fetching : ' + e.request.url)
+ return fetch(e.request)
+ }
+
+ // You can omit if/else for console.log & put one line below like this too.
+ // return request || fetch(e.request)
+ })
+ )
+})
+
+// Cache resources
+self.addEventListener('install', function (e) {
+ e.waitUntil(
+ caches.open(CACHE_NAME).then(function (cache) {
+ console.log('installing cache : ' + CACHE_NAME)
+ return cache.addAll(URLS)
+ })
+ )
+})
+
+// Delete outdated caches
+self.addEventListener('activate', function (e) {
+ e.waitUntil(
+ caches.keys().then(function (keyList) {
+ // `keyList` contains all cache names under your username.github.io
+ // filter out ones that has this app prefix to create white list
+ var cacheWhitelist = keyList.filter(function (key) {
+ return key.indexOf(APP_PREFIX)
+ })
+ // add current cache name to white list
+ cacheWhitelist.push(CACHE_NAME)
+
+ return Promise.all(keyList.map(function (key, i) {
+ if (cacheWhitelist.indexOf(key) === -1) {
+ console.log('deleting cache : ' + keyList[i] )
+ return caches.delete(keyList[i])
+ }
+ }))
+ })
+ )
+})