diff --git a/app/controllers/manifests_controller.rb b/app/controllers/manifests_controller.rb index c151076a..966f6164 100644 --- a/app/controllers/manifests_controller.rb +++ b/app/controllers/manifests_controller.rb @@ -6,8 +6,8 @@ class ManifestsController < ApplicationController def show render json: { name: APP_CONFIG["site_name"], - description: t("about.about.subtitle"), - start_url: root_url(source: "pwa"), + description: t("about.index.subtitle"), + start_url: root_url, scope: root_url, display: "standalone", categories: %w[social], @@ -37,10 +37,12 @@ class ManifestsController < ApplicationController end def webapp_icons - %i[1024 512 384 192 128 96 72 48].map do |size| + %i[1024 512 384 192 144 128 96 72 48].map do |size| [ - { src: "/icons/maskable_icon_x#{size}.webp", size: "#{size}x#{size}", type: "image/webp" }, - { src: "/icons/maskable_icon_x#{size}.png", size: "#{size}x#{size}", type: "image/png" } + { src: "/icons/icon_x#{size}.webp", sizes: "#{size}x#{size}", type: "image/webp", purpose: "any" }, + { src: "/icons/icon_x#{size}.png", sizes: "#{size}x#{size}", type: "image/png", purpose: "any" }, + { src: "/icons/maskable_icon_x#{size}.webp", sizes: "#{size}x#{size}", type: "image/webp", purpose: "maskable" }, + { src: "/icons/maskable_icon_x#{size}.png", sizes: "#{size}x#{size}", type: "image/png", purpose: "maskable" } ] end.flatten end diff --git a/public/icons/icon_x1024.png b/public/icons/icon_x1024.png new file mode 100644 index 00000000..3bf48a3e Binary files /dev/null and b/public/icons/icon_x1024.png differ diff --git a/public/icons/icon_x1024.webp b/public/icons/icon_x1024.webp new file mode 100644 index 00000000..9c72ad3f Binary files /dev/null and b/public/icons/icon_x1024.webp differ diff --git a/public/icons/icon_x128.png b/public/icons/icon_x128.png new file mode 100644 index 00000000..dfb05572 Binary files /dev/null and b/public/icons/icon_x128.png differ diff --git a/public/icons/icon_x128.webp b/public/icons/icon_x128.webp new file mode 100644 index 00000000..c834b7d5 Binary files /dev/null and b/public/icons/icon_x128.webp differ diff --git a/public/icons/icon_x144.png b/public/icons/icon_x144.png new file mode 100644 index 00000000..f23a8209 Binary files /dev/null and b/public/icons/icon_x144.png differ diff --git a/public/icons/icon_x144.webp b/public/icons/icon_x144.webp new file mode 100644 index 00000000..6f17b456 Binary files /dev/null and b/public/icons/icon_x144.webp differ diff --git a/public/icons/icon_x192.png b/public/icons/icon_x192.png new file mode 100644 index 00000000..02c5c92f Binary files /dev/null and b/public/icons/icon_x192.png differ diff --git a/public/icons/icon_x192.webp b/public/icons/icon_x192.webp new file mode 100644 index 00000000..866f866d Binary files /dev/null and b/public/icons/icon_x192.webp differ diff --git a/public/icons/icon_x384.png b/public/icons/icon_x384.png new file mode 100644 index 00000000..baceef0f Binary files /dev/null and b/public/icons/icon_x384.png differ diff --git a/public/icons/icon_x384.webp b/public/icons/icon_x384.webp new file mode 100644 index 00000000..4b771cdd Binary files /dev/null and b/public/icons/icon_x384.webp differ diff --git a/public/icons/icon_x48.png b/public/icons/icon_x48.png new file mode 100644 index 00000000..77093fcd Binary files /dev/null and b/public/icons/icon_x48.png differ diff --git a/public/icons/icon_x48.webp b/public/icons/icon_x48.webp new file mode 100644 index 00000000..e20794a8 Binary files /dev/null and b/public/icons/icon_x48.webp differ diff --git a/public/icons/icon_x512.png b/public/icons/icon_x512.png new file mode 100644 index 00000000..6cf448af Binary files /dev/null and b/public/icons/icon_x512.png differ diff --git a/public/icons/icon_x512.webp b/public/icons/icon_x512.webp new file mode 100644 index 00000000..bb5981bd Binary files /dev/null and b/public/icons/icon_x512.webp differ diff --git a/public/icons/icon_x72.png b/public/icons/icon_x72.png new file mode 100644 index 00000000..9468c0c6 Binary files /dev/null and b/public/icons/icon_x72.png differ diff --git a/public/icons/icon_x72.webp b/public/icons/icon_x72.webp new file mode 100644 index 00000000..d10e54f7 Binary files /dev/null and b/public/icons/icon_x72.webp differ diff --git a/public/icons/icon_x96.png b/public/icons/icon_x96.png new file mode 100644 index 00000000..fe3a4ded Binary files /dev/null and b/public/icons/icon_x96.png differ diff --git a/public/icons/icon_x96.webp b/public/icons/icon_x96.webp new file mode 100644 index 00000000..96abdb70 Binary files /dev/null and b/public/icons/icon_x96.webp differ diff --git a/public/icons/maskable_icon_x1024.png b/public/icons/maskable_icon_x1024.png index 99e22563..34a7834a 100644 Binary files a/public/icons/maskable_icon_x1024.png and b/public/icons/maskable_icon_x1024.png differ diff --git a/public/icons/maskable_icon_x1024.webp b/public/icons/maskable_icon_x1024.webp index 9c72ad3f..e69de29b 100644 Binary files a/public/icons/maskable_icon_x1024.webp and b/public/icons/maskable_icon_x1024.webp differ diff --git a/public/icons/maskable_icon_x128.png b/public/icons/maskable_icon_x128.png index 364a2633..36f47fc2 100644 Binary files a/public/icons/maskable_icon_x128.png and b/public/icons/maskable_icon_x128.png differ diff --git a/public/icons/maskable_icon_x128.webp b/public/icons/maskable_icon_x128.webp index c834b7d5..e69de29b 100644 Binary files a/public/icons/maskable_icon_x128.webp and b/public/icons/maskable_icon_x128.webp differ diff --git a/public/icons/maskable_icon_x144.png b/public/icons/maskable_icon_x144.png new file mode 100644 index 00000000..7fb47b2e Binary files /dev/null and b/public/icons/maskable_icon_x144.png differ diff --git a/public/icons/maskable_icon_x144.webp b/public/icons/maskable_icon_x144.webp new file mode 100644 index 00000000..bc19121f Binary files /dev/null and b/public/icons/maskable_icon_x144.webp differ diff --git a/public/icons/maskable_icon_x192.png b/public/icons/maskable_icon_x192.png index 431b710f..09697ddc 100644 Binary files a/public/icons/maskable_icon_x192.png and b/public/icons/maskable_icon_x192.png differ diff --git a/public/icons/maskable_icon_x192.webp b/public/icons/maskable_icon_x192.webp index 866f866d..e69de29b 100644 Binary files a/public/icons/maskable_icon_x192.webp and b/public/icons/maskable_icon_x192.webp differ diff --git a/public/icons/maskable_icon_x384.png b/public/icons/maskable_icon_x384.png index 6a63aa51..7eb4cfe5 100644 Binary files a/public/icons/maskable_icon_x384.png and b/public/icons/maskable_icon_x384.png differ diff --git a/public/icons/maskable_icon_x384.webp b/public/icons/maskable_icon_x384.webp index 4b771cdd..e69de29b 100644 Binary files a/public/icons/maskable_icon_x384.webp and b/public/icons/maskable_icon_x384.webp differ diff --git a/public/icons/maskable_icon_x48.png b/public/icons/maskable_icon_x48.png index 130736d5..a3aa4124 100644 Binary files a/public/icons/maskable_icon_x48.png and b/public/icons/maskable_icon_x48.png differ diff --git a/public/icons/maskable_icon_x48.webp b/public/icons/maskable_icon_x48.webp index e20794a8..e69de29b 100644 Binary files a/public/icons/maskable_icon_x48.webp and b/public/icons/maskable_icon_x48.webp differ diff --git a/public/icons/maskable_icon_x512.png b/public/icons/maskable_icon_x512.png index 1667c4a5..cf312b13 100644 Binary files a/public/icons/maskable_icon_x512.png and b/public/icons/maskable_icon_x512.png differ diff --git a/public/icons/maskable_icon_x512.webp b/public/icons/maskable_icon_x512.webp index bb5981bd..e69de29b 100644 Binary files a/public/icons/maskable_icon_x512.webp and b/public/icons/maskable_icon_x512.webp differ diff --git a/public/icons/maskable_icon_x72.png b/public/icons/maskable_icon_x72.png index 3c640f1c..4eb4caa9 100644 Binary files a/public/icons/maskable_icon_x72.png and b/public/icons/maskable_icon_x72.png differ diff --git a/public/icons/maskable_icon_x72.webp b/public/icons/maskable_icon_x72.webp index d10e54f7..e69de29b 100644 Binary files a/public/icons/maskable_icon_x72.webp and b/public/icons/maskable_icon_x72.webp differ diff --git a/public/icons/maskable_icon_x96.png b/public/icons/maskable_icon_x96.png index 17c8ca66..e1778b91 100644 Binary files a/public/icons/maskable_icon_x96.png and b/public/icons/maskable_icon_x96.png differ diff --git a/public/icons/maskable_icon_x96.webp b/public/icons/maskable_icon_x96.webp index 96abdb70..e69de29b 100644 Binary files a/public/icons/maskable_icon_x96.webp and b/public/icons/maskable_icon_x96.webp differ diff --git a/public/pwa_offline.html b/public/pwa_offline.html new file mode 100644 index 00000000..1e7fc241 --- /dev/null +++ b/public/pwa_offline.html @@ -0,0 +1,148 @@ + + + + + You are offline + + + + + +
+
+ + + A raccoon peeking out of a bin, looking confused + +
+
+

+ You are offline +

+

+ This content is not available offline. +

+ +
+
+ + + diff --git a/public/service_worker.js b/public/service_worker.js index 1f13f0f8..3735a89b 100644 --- a/public/service_worker.js +++ b/public/service_worker.js @@ -1,3 +1,14 @@ +const OFFLINE_CACHE_NAME = "offline"; +// Bumping this version will force an update of the service worker +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const OFFLINE_PAGE_VERSION = 1; +const OFFLINE_CACHE_PATHS = [ + "/pwa_offline.html", + "/images/errors/small/404.png", + "/images/errors/medium/404.png", + "/images/errors/original/404.png" +]; + self.addEventListener('push', function (event) { if (event.data) { const notification = event.data.json(); @@ -23,3 +34,31 @@ self.addEventListener('notificationclick', async event => { console.warn(`Unhandled notification tag: ${event.notification.tag}`); } }); + +self.addEventListener('install', function (event) { + event.waitUntil( + (async () => { + const cache = await caches.open(OFFLINE_CACHE_NAME); + await cache.addAll(OFFLINE_CACHE_PATHS); + })() + ); + // Immediately activate new versions of the service worker instead of waiting + self.skipWaiting(); +}); + +self.addEventListener('fetch', function (event) { + event.respondWith( + (async () => { + try { + // Try to load the resource + return await fetch(event.request); + } catch (error) { + // Show an error page if offline + console.log("Fetch failed; returning offline page instead.", error); + + const cache = await caches.open(OFFLINE_CACHE_NAME); + return await cache.match(OFFLINE_CACHE_PATHS[0]); + } + })() + ); +}); diff --git a/spec/controllers/manifests_controller_spec.rb b/spec/controllers/manifests_controller_spec.rb index d22707c4..2dff7e95 100644 --- a/spec/controllers/manifests_controller_spec.rb +++ b/spec/controllers/manifests_controller_spec.rb @@ -21,7 +21,7 @@ describe ManifestsController, type: :controller do body = JSON.parse(response.body) expect(body["name"]).to eq("Specspring") - expect(body["start_url"]).to eq("http://test.host/?source=pwa") + expect(body["start_url"]).to eq("http://test.host/") expect(body["scope"]).to eq("http://test.host/") expect(body["theme_color"]).to eq("#5e35b1") end