From 9a2d02478c36434aa57babf97afe6367e1fca58a Mon Sep 17 00:00:00 2001 From: MaciejkaG Date: Fri, 12 Apr 2024 22:04:11 +0200 Subject: [PATCH] Adding PWA (not finished) --- package.json | 2 +- public/assets/js/service-worker.js | 25 +++++++++++++++++++++++++ public/assets/js/worker-handler.js | 6 ++++++ public/pwa/manifest.json | 15 +++++++++++++++ views/layouts/main.handlebars | 3 +++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 public/assets/js/service-worker.js create mode 100644 public/assets/js/worker-handler.js create mode 100644 public/pwa/manifest.json diff --git a/package.json b/package.json index 8d48045..c66c965 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "statki-backend", - "version": "1.0.0", + "version": "0.7.0", "description": "Backend do gry w statki", "main": "index.js", "type": "module", diff --git a/public/assets/js/service-worker.js b/public/assets/js/service-worker.js new file mode 100644 index 0000000..aee2207 --- /dev/null +++ b/public/assets/js/service-worker.js @@ -0,0 +1,25 @@ +const statki = "statki-by-maciejka-0.7.0"; +const assets = [ + "/favicon.ico", + "/assets/css/landing.css", + "/assets/css/main.css", + "/assets/css/responsive.css", + "/assets/css/board.css", + "/assets/css/board-responsive.css", + "/assets/js/battleships-lib.js", + "/assets/js/key-handling.js", + "/assets/js/landing.js", + "/assets/js/main.js", + "/assets/js/socket-err-handler.js", + "/assets/js/socket-game.js", + "/assets/js/socket.js", + "/assets/js/spa_lib.js" +]; + +self.addEventListener("install", installEvent => { + installEvent.waitUntil( + caches.open(statki).then(cache => { + cache.addAll(assets); + }) + ); +}); \ No newline at end of file diff --git a/public/assets/js/worker-handler.js b/public/assets/js/worker-handler.js new file mode 100644 index 0000000..08d5612 --- /dev/null +++ b/public/assets/js/worker-handler.js @@ -0,0 +1,6 @@ +window.addEventListener("load", function () { + navigator.serviceWorker + .register("/assets/js/service-worker.js") + .then(res => console.log("Service worker registered")) + .catch(err => console.log("Service worker not registered", err)); +}); \ No newline at end of file diff --git a/public/pwa/manifest.json b/public/pwa/manifest.json new file mode 100644 index 0000000..c38fee0 --- /dev/null +++ b/public/pwa/manifest.json @@ -0,0 +1,15 @@ +{ + "name": "Statki", + "start_url": "/", + "background_color": "black", + "theme_color": "black", + "orientation": "landscape", + "icons": [ + { + "src": "/assets/img/statki-logo-crop.png", + "sizes": "1080x1080", + "type": "image/png" + } + ], + "display": "standalone" +} \ No newline at end of file diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars index 05bfae5..ddd66d4 100644 --- a/views/layouts/main.handlebars +++ b/views/layouts/main.handlebars @@ -20,10 +20,13 @@ + + Designed by Maciejka {{{body}}} + \ No newline at end of file