From 5c1f449f672df69cc6b40631469ab1369a1564a2 Mon Sep 17 00:00:00 2001 From: Steam Deck User Date: Thu, 4 May 2023 07:41:56 +0200 Subject: [PATCH] p2p scan/avail and editor basis --- editor.html | 1 + examples/pwa/index.html | 22 +++++++++++++++++++++ examples/pwa/sw.js | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 editor.html create mode 100644 examples/pwa/index.html create mode 100644 examples/pwa/sw.js diff --git a/editor.html b/editor.html new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/editor.html @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/examples/pwa/index.html b/examples/pwa/index.html new file mode 100644 index 0000000..6550734 --- /dev/null +++ b/examples/pwa/index.html @@ -0,0 +1,22 @@ + + + testing PWA + + doesnt have to have a manifest as this is only for the home screen + + surely works on iOS as my own IterativeExploration page is there + (somehow added to HomeScreen, yet nothing related found + cf serverhome/web/iterative-explorations.com/www/index.html ) + + + diff --git a/examples/pwa/sw.js b/examples/pwa/sw.js new file mode 100644 index 0000000..4f1b0c0 --- /dev/null +++ b/examples/pwa/sw.js @@ -0,0 +1,44 @@ +const cacheAssets = [ + '/pwa/index.html', + '/pwa/testdata.json', +] +const cacheName = '00004'; + +// Call Install Event +self.addEventListener('install', e => { + console.log('Service Worker: Installed'); + + e.waitUntil( + async () => { + cache = await caches.open(cacheName); + console.log('Service Worker: Caching Files', cache); + await cache.addAll(cacheAssets); + self.skipWaiting(); + } +); + +}); + +// Call Activate Event +self.addEventListener('activate', e => { + console.log('Service Worker: Activated'); + // Remove unwanted caches + e.waitUntil( + caches.keys().then(cacheNames => { + return Promise.all( + cacheNames.map(cache => { + if (cache !== cacheName) { + console.log('Service Worker: Clearing Old Cache'); + return caches.delete(cache); + } + }) + ); + }) + ); +}); + +// Call Fetch Event +self.addEventListener('fetch', e => { + console.log('Service Worker: Fetching'); + e.respondWith(fetch(e.request).catch(() => caches.match(e.request))); +});