piefed is a pwa

This commit is contained in:
rimu 2024-02-28 17:42:49 +13:00
parent b6572f1a86
commit abed85a1e3
4 changed files with 47 additions and 3 deletions

View file

@ -550,3 +550,16 @@ function displayTimeTracked() {
timeSpentElement.textContent = formatTime(timeSpent) timeSpentElement.textContent = formatTime(timeSpent)
} }
} }
/*register a service worker */
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/static/service_worker.js', {scope: '/static/'}).then(function(registration) {
// Registration was successful
// console.log('ServiceWorker2 registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker2 registration failed: ', err);
});
});
}

View file

@ -15,7 +15,7 @@
], ],
"theme_color": "#007BBF", "theme_color": "#007BBF",
"background_color": "#ffffff", "background_color": "#ffffff",
"display": "browser", "display": "minimal-ui",
"start_url": "/", "start_url": "/",
"scope": "/" "scope": "/"
} }

View file

@ -0,0 +1,31 @@
//https://developers.google.com/web/fundamentals/primers/service-workers
// Font files
var fontFiles = [
'/static/fonts/feather/feather.ttf',
];
//this is just an empty service worker so that the 'Install CB as an app' prompt appears in web browsers
self.addEventListener('install', function(event) {
event.waitUntil(caches.open('core').then(function (cache) {
fontFiles.forEach(function (file) {
cache.add(new Request(file));
});
return;
}));
});
self.addEventListener('fetch', function(event) {
// Fonts
// Offline-first
if (request.url.includes('feather.ttf')) {
event.respondWith(
caches.match(request).then(function (response) {
return response || fetch(request).then(function (response) {
// Return the requested file
return response;
});
})
);
}
});

View file

@ -52,7 +52,7 @@
<link rel="apple-touch-icon" sizes="152x152" href="/static/images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="152x152" href="/static/images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/images/favicon-16x16.png"> <link rel="icon" type="image/png" sizes="16x16" href="/static/images/favicon-16x16.png">
<link rel="manifest" href="/static/site.webmanifest"> <link rel="manifest" href="/static/manifest.json">
<link rel="shortcut icon" type="image/png" href="/static/images/favicon-32x32.png"> <link rel="shortcut icon" type="image/png" href="/static/images/favicon-32x32.png">
<link href='/static/images/favicon.ico' rel='icon' type='image/x-icon'> <link href='/static/images/favicon.ico' rel='icon' type='image/x-icon'>
<meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-TileColor" content="#da532c">