Add PWA option

This commit is contained in:
eris 2022-08-28 09:21:31 +00:00
parent e69dddee69
commit dd42d8e92c
3 changed files with 77 additions and 0 deletions

View File

@ -10,10 +10,19 @@
<link rel="stylesheet" href="/static/font/css/lato.css">
<link rel="stylesheet" href="/static/mfm.css">
<!--server-generated-meta-->
<link rel="manifest" href="/static/manifest.json" />
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar" content="black-translucent" />
<link rel="apple-touch-icon" href="/images/icons/icon-512x512.png"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="theme-color" content="#000000" />
<meta name="theme-color-orig" content="#000000" />
<link rel="icon" type="image/png" href="/favicon.png">
</head>
<body class="hidden">
<noscript>To use Pleroma, please enable JavaScript.</noscript>
<script>if('serviceWorker' in navigator){navigator.serviceWorker.register('/static/service-worker.js');} else {console.log("Service worker is not supported");}</script>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>

29
static/manifest.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "☽ D̷i̵s̴q̴ordi̴a ☾",
"short_name": "☽ D̷i̵s̴q̴ordi̴a ☾",
"start_url": "/",
"display": "standalone",
"background_color": "#000000",
"theme_color": "#000000",
"orientation": "portrait-primary",
"icons": [
{
"src": "/images/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "/images/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "/images/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable any"
}
]
}

39
static/service-worker.js Normal file
View File

@ -0,0 +1,39 @@
// Installing service worker
const CACHE_NAME = 'Disqordia';
/* Add relative URL of all the static content you want to store in
* cache storage (this will help us use our app offline)*/
let resourcesToCache = ["/", "/static/font/css/fontello.css", "/static/font/css/animation.css", "/static/font/tiresias.css", "/static/font/css/lato.css", "/static/mfm.css", "/favicon.png", "/static/css/app.d7c75a48f7d627e0493f.css", "/static/js/vendors~app.4600ad9d6a3c807e6688.js", "/static/js/app.afaee31b8c11ba3c67aa.js"];
self.addEventListener("install", e=>{
e.waitUntil(
caches.open(CACHE_NAME).then(cache =>{
return cache.addAll(resourcesToCache);
})
);
});
// Cache and return requests
self.addEventListener("fetch", e=>{
e.respondWith(
caches.match(e.request).then(response=>{
return response || fetch(e.request);
})
);
});
// Update a service worker
const cacheWhitelist = ['Disqordia'];
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});