feat: PWA manifest + service worker so dashboard is installable#44
Open
jakduch wants to merge 4 commits into
Open
feat: PWA manifest + service worker so dashboard is installable#44jakduch wants to merge 4 commits into
jakduch wants to merge 4 commits into
Conversation
Adds GET /manifest.json, GET /sw.js, and GET /icon.svg routes plus the
matching <link rel="manifest">, theme-color meta, icon links, and
navigator.serviceWorker.register('/sw.js') boot in the HTML head/tail.
Chrome (and Edge/Safari) now offers 'Install Claude Usage' as a desktop
app. The service worker is intentionally tiny: install, claim clients,
fetch passthrough with a stale-while-revalidate cache for the Chart.js
CDN bundle so repeat loads are instant and the dashboard still boots
when offline-after-first-visit. All /api/* traffic goes straight to the
network — no stale data risk.
Icon is a single SVG (bar-chart glyph in the Apple-theme accent blue),
served at /icon.svg with image/svg+xml. Modern browsers accept SVG for
PWA manifest icons, so no PNG raster is needed.
Tests: 5 new tests in tests/test_pwa.py cover manifest JSON shape +
required keys, sw.js content-type + scope header, icon.svg content,
HTML <link rel=manifest> hook, and the SW register call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this add and why do you believe it belongs in this dashboard?
This PR makes the local dashboard a Progressive Web App by adding a
manifest.json, a minimalsw.jsservice worker, and an SVG app icon, plus the matching<link rel="manifest">,<meta name="theme-color">, Appleapple-touch-icon/apple-mobile-web-app-*metas in<head>and a feature-detectednavigator.serviceWorker.register("/sw.js")boot. Once installed, the dashboard opens in its own OS window with no browser chrome and gets its own dock/taskbar icon — Chrome and Edge show their "Install app" affordance, and on iOS Safari "Add to Home Screen" produces a real standalone web app.It belongs in this dashboard because Claude Code Usage is the kind of tool you check repeatedly throughout the day. Hunting for the right
localhost:8080tab is friction; a real installable app removes that friction without giving up the "it's just a local Python script" property of the project. The cost is genuinely tiny — three newdo_GETbranches and ~10 HTML lines, no new third-party dependencies, no build step, no PNG raster (SVG icons are accepted by modern Chrome/Edge/Safari for PWA installs). The service worker only caches the Chart.js CDN bundle as stale-while-revalidate; every/api/*request goes straight to the network, so installed users never see stale numbers.Checklist
Code correctness
calcCost()calls pass 6 arguments:(model, inp, out, cache_read, cache_creation, cache_1h)`), not escaped ones (\`)Tests
python3 -m unittest discover -s tests -v— all passingpython3 -m unittest tests.test_browser -v— all passingScope
dashboard.py,scanner.py,cli.py,pricing.py,cowork.py,tests/) — or I've explained below why a new file is neededtests/test_pwa.pyis the one new file. It is the unit-test home for the three new PWA routes (/manifest.json,/sw.js,/icon.svg) plus the HTML manifest-link and SW-register hooks. Putting these checks in their own module keepstest_dashboard.pyfocused on the existing HTML/API surface and means a future "remove PWA" patch is a single-file delete.