mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
piefed is a pwa
This commit is contained in:
parent
b6572f1a86
commit
abed85a1e3
4 changed files with 47 additions and 3 deletions
|
@ -550,3 +550,16 @@ function displayTimeTracked() {
|
|||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
],
|
||||
"theme_color": "#007BBF",
|
||||
"background_color": "#ffffff",
|
||||
"display": "browser",
|
||||
"display": "minimal-ui",
|
||||
"start_url": "/",
|
||||
"scope": "/"
|
||||
}
|
31
app/static/service_worker.js
Normal file
31
app/static/service_worker.js
Normal 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;
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
|
@ -52,7 +52,7 @@
|
|||
<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="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 href='/static/images/favicon.ico' rel='icon' type='image/x-icon'>
|
||||
<meta name="msapplication-TileColor" content="#da532c">
|
||||
|
|
Loading…
Reference in a new issue