PWA: installable, instant and offline (#89) #91

Closed
kayg wants to merge 0 commits from issue/89-pwa-1 into dev
Owner

Closes #89. Calternal installs on the phone and the desktop, opens instantly from its own copy of the app, and opens offline with the last notes.

Installable

  • public/manifest.webmanifest: name Calternal, display: standalone, start_url/scope/id /, background and theme #f3ece2 (the light paper, as on the existing theme-color meta), icons 192/512 "any", 512 "maskable", plus the SVG.
  • iOS: apple-touch-icon (180), apple-mobile-web-app-capable, mobile-web-app-capable, apple-mobile-web-app-title, apple-mobile-web-app-status-bar-style: black-translucent. The viewport already had viewport-fit=cover.
  • A placeholder icon until the logo exists (a sun on the horizon, inside the maskable safe zone): icons/icon.svg, rendered by scripts/icons.mjs (run by hand; the PNGs are committed, so builds need no browser).

Service worker, no plugin

  • scripts/sw-plugin.ts (about 40 lines) writes sw.js at build time with the exact shell: index.html, the hashed assets, fonts, icons and the manifest, with a version derived from them. I skipped vite-plugin-pwa: it would bring Workbox for what is one list and three handlers.
  • sw/sw.js:
    • Serves the shell first; every page of the app is the cached index.html (routes live in the hash).
    • Never touches /api or the live socket. Only same-origin GETs are handled, so notes only ever come from the server or the editor's IndexedDB copy.
    • Backdrop photos are kept after their first use.
    • Matches by URL with ignoreVary: scripts and fonts are CORS requests and the server's Vary header made them miss offline.
  • Updates never interrupt: no skipWaiting on its own. A new version waits for the next launch. Settings → Devices shows a quiet "Update ready" with Update now (the person's tap, then one reload), and the Devices row gets a dot. The app checks for a new version when it comes back to the front.

Offline

  • Auth: if the server can't be reached at all (not a "no"), the app opens as whoever was last signed in on this device, and re-checks when back online (an ended session then shows sign-in).
  • The newest 300 notes' list fields are kept on the device and shown at once on start (also online, so the list is instant). The server's list replaces them when it answers.
  • The note opens from the editor's IndexedDB copy, and the status says "Not saved yet" for changes until the connection is back.
  • Signing out forgets the remembered person and the saved list.
  • Not offline yet: saved preferences (theme, accent) fall back to the defaults when the server can't be reached.

Safe areas

  • --safe-top/right/bottom/left tokens (fed by env() on a real phone) replace the scattered env() calls.
  • The wide layout (iPad) pads all four, phone screens on their side pad left/right, the FAB and the toasts clear the home indicator. The toast primitive's bottom now takes a CSS length.

Install hint (N9): Settings → Devices → This device shows "Add Calternal to your Home Screen". It offers Install where the browser offers it (Chrome, Edge, Android) and shows Safari's steps (Share, then Add to Home Screen) on iOS. × closes it for good. Once on a phone, after 4 launches, one toast points there. Never a modal.

Tests (e2e/pwa.spec.ts)

  • Chromium: Page.getInstallabilityErrors is empty; the manifest has the required fields; the cache holds the shell and nothing under /api.
  • Chromium: opening offline shows the note from IndexedDB and the list from the device; typing says "Not saved yet"; back online it says "Saved".
  • WebKit: the iOS tags and the apple-touch-icon (200, PNG).
  • Phone (390, iPhone user agent, iPhone insets 47/34 through the tokens): the back button is below the status bar, the bar is 34+ px above the bottom, the hint shows Safari's steps, and dismissing it survives a reload. Screenshots in the first comment.
  • Not covered by a test: the update flow (it needs two builds in one run); it's small and in pwa.svelte.ts.

Locally: full browser suite 85 passed / 36 skipped; svelte-check 0 errors.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Closes #89. Calternal installs on the phone and the desktop, opens instantly from its own copy of the app, and opens offline with the last notes. **Installable** - `public/manifest.webmanifest`: name Calternal, `display: standalone`, `start_url`/`scope`/`id` `/`, background and theme `#f3ece2` (the light paper, as on the existing theme-color meta), icons 192/512 "any", 512 "maskable", plus the SVG. - iOS: `apple-touch-icon` (180), `apple-mobile-web-app-capable`, `mobile-web-app-capable`, `apple-mobile-web-app-title`, `apple-mobile-web-app-status-bar-style: black-translucent`. The viewport already had `viewport-fit=cover`. - A placeholder icon until the logo exists (a sun on the horizon, inside the maskable safe zone): `icons/icon.svg`, rendered by `scripts/icons.mjs` (run by hand; the PNGs are committed, so builds need no browser). **Service worker, no plugin** - `scripts/sw-plugin.ts` (about 40 lines) writes `sw.js` at build time with the exact shell: `index.html`, the hashed assets, fonts, icons and the manifest, with a version derived from them. I skipped vite-plugin-pwa: it would bring Workbox for what is one list and three handlers. - `sw/sw.js`: - Serves the shell first; every page of the app is the cached `index.html` (routes live in the hash). - **Never touches `/api` or the live socket.** Only same-origin GETs are handled, so notes only ever come from the server or the editor's IndexedDB copy. - Backdrop photos are kept after their first use. - Matches by URL with `ignoreVary`: scripts and fonts are CORS requests and the server's `Vary` header made them miss offline. - **Updates never interrupt:** no `skipWaiting` on its own. A new version waits for the next launch. Settings → Devices shows a quiet "Update ready" with **Update now** (the person's tap, then one reload), and the Devices row gets a dot. The app checks for a new version when it comes back to the front. **Offline** - Auth: if the server can't be reached at all (not a "no"), the app opens as whoever was last signed in on this device, and re-checks when back online (an ended session then shows sign-in). - The newest 300 notes' list fields are kept on the device and shown at once on start (also online, so the list is instant). The server's list replaces them when it answers. - The note opens from the editor's IndexedDB copy, and the status says "Not saved yet" for changes until the connection is back. - Signing out forgets the remembered person and the saved list. - Not offline yet: saved preferences (theme, accent) fall back to the defaults when the server can't be reached. **Safe areas** - `--safe-top/right/bottom/left` tokens (fed by `env()` on a real phone) replace the scattered `env()` calls. - The wide layout (iPad) pads all four, phone screens on their side pad left/right, the FAB and the toasts clear the home indicator. The toast primitive's `bottom` now takes a CSS length. **Install hint (N9)**: Settings → Devices → This device shows "Add Calternal to your Home Screen". It offers **Install** where the browser offers it (Chrome, Edge, Android) and shows Safari's steps (Share, then Add to Home Screen) on iOS. × closes it for good. Once on a phone, after 4 launches, one toast points there. Never a modal. **Tests** (`e2e/pwa.spec.ts`) - Chromium: `Page.getInstallabilityErrors` is empty; the manifest has the required fields; the cache holds the shell and nothing under `/api`. - Chromium: opening offline shows the note from IndexedDB and the list from the device; typing says "Not saved yet"; back online it says "Saved". - WebKit: the iOS tags and the apple-touch-icon (200, PNG). - Phone (390, iPhone user agent, iPhone insets 47/34 through the tokens): the back button is below the status bar, the bar is 34+ px above the bottom, the hint shows Safari's steps, and dismissing it survives a reload. Screenshots in the first comment. - Not covered by a test: the update flow (it needs two builds in one run); it's small and in `pwa.svelte.ts`. Locally: full browser suite 85 passed / 36 skipped; svelte-check 0 errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Web: an installable app that opens instantly and offline (#89)
All checks were successful
CI / rust (pull_request) Successful in 1m15s
CI / web (pull_request) Successful in 3m9s
4fc8840517
- Manifest (standalone, start and scope /, light colours, any and
  maskable icons), iOS tags (apple-touch-icon, web-app capable, title,
  black-translucent status bar). A placeholder icon until the logo
  exists: icons/icon.svg, rendered to PNGs by scripts/icons.mjs.
- Service worker without a plugin: scripts/sw-plugin.ts writes sw.js at
  build time with the exact shell (page, hashed assets, fonts, icons,
  manifest) and a version from it. Shell first; /api and the live socket
  are never touched; backdrop photos are kept after first use. A new
  version waits for the next launch, or "Update now" in Settings.
- Offline: auth falls back to who was last signed in on this device when
  the server can't be reached (re-checked when back online); the newest
  300 notes' list fields are kept on the device and shown at once; the
  editor's IndexedDB copy opens the note and says "Not saved yet".
  Signing out forgets both.
- Safe areas through --safe-* tokens (env() on a real phone); the wide
  layout, phone screens on their side and toasts clear them too.
- Settings → Devices → This device: "Update ready" and a quiet,
  dismissible "Add Calternal to your Home Screen" (Install where the
  browser offers it, Safari's steps on iOS); once on a phone after a few
  launches, one toast pointing there. Never a modal.
- e2e/pwa.spec.ts: Chromium installability (no installability errors),
  cache contents (shell yes, API never), offline reload with the note,
  the list and Not saved yet, then Saved when back; iOS tags in WebKit;
  a phone with iPhone insets: nothing under the status bar or the home
  indicator, the hint, and dismissing it for good (with screenshots).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Phone layout with iPhone insets (status bar 47 px, home indicator 34 px), WebKit at 390, from e2e/pwa.spec.ts:

A note: the back button starts below the status bar; the bar floats above the home indicator.
phone note

Settings → Devices: the quiet install hint with Safari's steps (× closes it for good).
phone settings

The placeholder icon (512):
icon

Phone layout with iPhone insets (status bar 47 px, home indicator 34 px), WebKit at 390, from `e2e/pwa.spec.ts`: **A note**: the back button starts below the status bar; the bar floats above the home indicator. ![phone note](https://git.kayg.org/attachments/22f0f3cd-409a-44e2-b4c0-96e4678e4234) **Settings → Devices**: the quiet install hint with Safari's steps (× closes it for good). ![phone settings](https://git.kayg.org/attachments/24ebd152-cae7-4d42-aaee-da26179c16b5) **The placeholder icon** (512): ![icon](https://git.kayg.org/attachments/cf745e38-1c07-47b4-bb4c-da33a5c9aaf0)
Author
Owner

Reviewed by Claude (phone screenshots: bar above the home indicator, install hint in Settings). Hand-written SW precaching only the shell, never /api or the socket; update waits for next launch or an explicit Update now. CI green. Merging and deploying.

Reviewed by Claude (phone screenshots: bar above the home indicator, install hint in Settings). Hand-written SW precaching only the shell, never /api or the socket; update waits for next launch or an explicit Update now. CI green. Merging and deploying.
Author
Owner

Closing: this branch is already fully contained in dev (it landed through a merge train). Branch cleanup, 2026-10-15.

Closing: this branch is already fully contained in `dev` (it landed through a merge train). Branch cleanup, 2026-10-15.
kayg closed this pull request 2026-10-15 08:35:12 +00:00
All checks were successful
CI / rust (pull_request) Successful in 1m15s
CI / web (pull_request) Successful in 3m9s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!91
No description provided.