🍎 Makes app installable

This commit is contained in:
Rune Harlyk
2024-03-17 22:01:54 +01:00
committed by Rune Harlyk
parent 8528f3400f
commit 09f9649d6f
6 changed files with 68 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

+15
View File
@@ -0,0 +1,15 @@
{
"short_name": "Quadruped Controller",
"name": "Quadruped Controller",
"icons": [
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
+45
View File
@@ -0,0 +1,45 @@
const CACHE_NAME = 'v1';
const urlsToCache = ['/', '/index.html', '/stl.zip'];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll(urlsToCache);
})
);
});
// self.addEventListener('fetch', (event) => {
// event.respondWith(
// caches.match(event.request).then((response) => {
// if (response) {
// return response;
// }
// return fetch(event.request).then((response) => {
// if (!response || response.status !== 200 || response.type !== 'basic') {
// return response;
// }
// var responseToCache = response.clone();
// caches.open(CACHE_NAME).then((cache) => {
// cache.put(event.request, responseToCache);
// });
// return response;
// });
// })
// );
// });
self.addEventListener('activate', (event) => {
var cacheWhitelist = ['v1'];
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});