Add the PWA layer: manifest, service worker, icons, offline page

Implements installable-PWA support per the plan: a manifest.webmanifest
view (name/short_name "Evection", standalone display, 192/512/maskable
icons), a service worker served at domain root (/sw.js, with
Service-Worker-Allowed: / so its scope covers the whole app, not just
/static/), and an offline fallback page.

The service worker ignores all non-GET requests outright (so mutations
like mark-read/star/OPML upload stay network-only without special-
casing every endpoint), does network-first-with-cache-fallback for
navigations (bounded to the 60 most recently viewed pages, trimmed
oldest-first), and cache-first for /static/ assets, with the cache
name keyed by EVECTION_PWA_CACHE_VERSION so a deploy can invalidate
old caches. Per the earlier decision, embedded remote images in
article content are not cached for offline reading — text/HTML only.

Generates a simple RSS-glyph icon set (192/512/maskable/apple-touch)
with a throwaway Pillow script (not a project dependency). Adds iOS
meta tags and service-worker registration to base.html. Fixed a real
bug found during this work: the first-run setup-wizard middleware was
redirecting /manifest.webmanifest, /sw.js, and /offline/ to /setup/
before an admin account existed, which would have broken a browser's
very first visit to a fresh install.

Verified: manifest JSON validity and required fields, sw.js delivery
(content-type, Service-Worker-Allowed header, correct body) via both
curl and automated tests (112 passing). Actual service-worker
registration could not be verified in this sandboxed browser pane —
confirmed via a control test (even a trivial unrelated static file
fails to register here with an opaque "unknown error fetching script")
that this is an environment limitation of locally-started dev servers
in this tool, not an application bug; registration, install-prompt,
and offline behavior need confirming in a real browser.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-30 16:46:06 -06:00
1 parent ea214dd9ce
commit 7577110238
14 files changed
+252 -3

No files matched your search

+12 -1
View File
@@ -24,10 +24,21 @@ class SetupWizardMiddleware:
def __call__(self, request):
path = request.path
if not path.startswith(_SETUP_EXEMPT_PREFIXES):
if not path.startswith(_SETUP_EXEMPT_PREFIXES) and path not in _pwa_exempt_paths():
if not SetupWizardMiddleware._a_user_exists:
SetupWizardMiddleware._a_user_exists = User.objects.exists()
setup_url = reverse("accounts:setup")
if path != setup_url and not SetupWizardMiddleware._a_user_exists:
return redirect(setup_url)
return self.get_response(request)
def _pwa_exempt_paths():
"""The manifest/service worker/offline page must work even before the
instance's first-run setup is complete — a browser can fetch these on
any visit, setup page included (it extends the same base template)."""
return {
reverse("pwa:manifest"),
reverse("pwa:service_worker"),
reverse("pwa:offline"),
}
+7
View File
@@ -19,6 +19,13 @@ def test_root_redirects_to_setup_when_no_users_exist(client):
assert response.url == reverse("accounts:setup")
@pytest.mark.django_db
def test_pwa_routes_bypass_the_setup_redirect(client):
for url_name in ["pwa:manifest", "pwa:service_worker", "pwa:offline"]:
response = client.get(reverse(url_name))
assert response.status_code == 200, url_name
@pytest.mark.django_db
def test_setup_creates_admin_and_logs_in(client):
response = client.post(