From 528e2b3dc038b758a165e617499509c4abae6006 Mon Sep 17 00:00:00 2001 From: Korbs Date: Sat, 22 Jun 2024 16:52:17 -0400 Subject: [PATCH] Add PWA support --- src/public/manifest.json | 37 +++++++++++++++++++++ src/public/offline.html | 63 ++++++++++++++++++++++++++++++++++++ src/public/service-worker.js | 38 ++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 src/public/manifest.json create mode 100644 src/public/offline.html create mode 100644 src/public/service-worker.js diff --git a/src/public/manifest.json b/src/public/manifest.json new file mode 100644 index 0000000..1dc06e4 --- /dev/null +++ b/src/public/manifest.json @@ -0,0 +1,37 @@ +{ + "name": "Poke", + "short_name": "Poke", + "description": "The Ultimate Privacy App!", + "start_url": "/", + "display": "standalone", + "display_override": [ + "window-controls-overlay" + ], + "background_color": "#080808", + "theme_color": "#612153", + "categories": [ + "entertainment", + "music" + ], + "icons": [ + { + "src": "/css/pt.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "screenshots": [ + { + "src": "/css/pwa-desktop.png", + "type": "image/png", + "sizes": "1695x1445", + "form_factor": "wide" + }, + { + "src": "/css/pwa-mobile.jpg", + "type": "image/jpg", + "sizes": "1080x2412", + "form_factor": "narrow" + } + ] +} \ No newline at end of file diff --git a/src/public/offline.html b/src/public/offline.html new file mode 100644 index 0000000..12379df --- /dev/null +++ b/src/public/offline.html @@ -0,0 +1,63 @@ + + + + + Poke - No interenet!1!1!1!111! + + +
+
+

Oh nyo >~<

+

Connectivity to the server has been lost qwq
Seems like you're offline - u check your internet connection and try again


+

or u can just view poke!'s status page yk~

+ +
+ +
+ + diff --git a/src/public/service-worker.js b/src/public/service-worker.js new file mode 100644 index 0000000..5f98366 --- /dev/null +++ b/src/public/service-worker.js @@ -0,0 +1,38 @@ +// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later + +'use strict'; + +var cacheVersion = 1; +var currentCache = { + offline: 'offline-cache' + cacheVersion +}; +const offlineUrl = 'offline'; + +this.addEventListener('install', event => { + event.waitUntil( + caches.open(currentCache.offline).then(function (cache) { + return cache.addAll([ + offlineUrl + ]); + }) + ); +}); + +this.addEventListener('fetch', event => { + if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) { + event.respondWith( + fetch(event.request.url).catch(error => { + return caches.match(offlineUrl); + }) + ); + } + else { + event.respondWith(caches.match(event.request) + .then(function (response) { + return response || fetch(event.request); + }) + ); + } +}); + +// @license-end