Public: anyone can read this; the crew can change it.
The browser tab and a phone's home screen show the deal-clock mark, not a blank icon #50
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/48-the-browser-tab-and-a-phone-s-home-scree → main 2 commits fork
7 files
changed +106
−4
README.md +3
| @@ -113,6 +113,9 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 113 | 113 | deals below the clock, then Restore the sample deals and confirms: the four |
| 114 | 114 | samples return as they were, dated from today, and the deals you opened are |
| 115 | 115 | left alone. Only an admin sees it. In the terminal press R; over MCP, the `restore_samples` tool. |
| 116 | 16. **Put it on your phone.** In your phone's browser, choose Add to Home Screen: | |
| 117 | the deal-clock mark sits beside the app's name, and it opens full screen | |
| 118 | like any app. The same mark is the browser tab's icon. | |
| 116 | 119 | |
| 117 | 120 | ## Make it yours |
| 118 | 121 |
src/audit.test.ts +4 −1
| @@ -3,13 +3,14 @@ | ||
| 3 | 3 | * the real server; only an admin reads them; and a trail that cannot be |
| 4 | 4 | * written costs a log line, never the request. |
| 5 | 5 | */ |
| 6 | import { afterAll, expect, spyOn, test } from "bun:test"; | |
| 6 | import { afterAll, beforeEach, expect, spyOn, test } from "bun:test"; | |
| 7 | 7 | import { mkdtempSync } from "node:fs"; |
| 8 | 8 | import { tmpdir } from "node:os"; |
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { createDeal } from "./deals.ts"; |
| 11 | 11 | import type { AuditRow } from "./audit.ts"; |
| 12 | 12 | import { openDb } from "./db.ts"; |
| 13 | import { forgetRationing } from "./security.ts"; | |
| 13 | 14 | import { serve } from "./server.ts"; |
| 14 | 15 | import { sign } from "./who.ts"; |
| 15 | 16 | |
| @@ -21,6 +22,8 @@ const server = serve({ | ||
| 21 | 22 | }); |
| 22 | 23 | const base = `http://${server.hostname}:${server.port}`; |
| 23 | 24 | afterAll(() => server.stop(true)); |
| 25 | // Every test file in one run shares the rationing buckets; a test here starts with them full. | |
| 26 | beforeEach(forgetRationing); | |
| 24 | 27 | |
| 25 | 28 | const as = ( |
| 26 | 29 | id: string, |
src/pages/layout.ts +4 −1
| @@ -20,6 +20,8 @@ import { contactLinks } from "./contact.ts"; | ||
| 20 | 20 | import { token, tokensHref } from "../tokens.ts"; |
| 21 | 21 | import type { Who } from "../who.ts"; |
| 22 | 22 | |
| 23 | const iconHref = asset("icon.svg"); | |
| 24 | ||
| 23 | 25 | export function layout(input: { |
| 24 | 26 | body: string; |
| 25 | 27 | who: Who; |
| @@ -48,7 +50,8 @@ export function layout(input: { | ||
| 48 | 50 | <meta name="color-scheme" content="light dark"> |
| 49 | 51 | <meta name="theme-color" content="${token("color-bg")}" media="(prefers-color-scheme: light)"> |
| 50 | 52 | <meta name="theme-color" content="${token("color-bg", "dark")}" media="(prefers-color-scheme: dark)"> |
| 51 | <link rel="icon" href="data:,"> | |
| 53 | <link rel="icon" type="image/svg+xml" href="${iconHref}"> | |
| 54 | <link rel="manifest" href="/manifest.webmanifest"> | |
| 52 | 55 | <title>${escape(pageTitle)}</title> |
| 53 | 56 | <meta name="description" content="${escape(description)}"> |
| 54 | 57 | <meta property="og:type" content="website"> |
src/routes.ts +42 −2
| @@ -20,8 +20,9 @@ import { | ||
| 20 | 20 | type Failure, |
| 21 | 21 | type Result, |
| 22 | 22 | } from "./actions.ts"; |
| 23 | import { agent, commit, env, forgeUrl, publicOrigin, startedAt, version } from "./env.ts"; | |
| 23 | import { agent, commit, description, env, forgeUrl, publicOrigin, startedAt, title, version } from "./env.ts"; | |
| 24 | 24 | import { |
| 25 | asset, | |
| 25 | 26 | back, |
| 26 | 27 | fields, |
| 27 | 28 | html, |
| @@ -66,7 +67,7 @@ import { refusedPage } from "./pages/refused.ts"; | ||
| 66 | 67 | import { timelinePage } from "./pages/timeline.ts"; |
| 67 | 68 | import { welcomePage } from "./pages/welcome.ts"; |
| 68 | 69 | import { dueOn } from "./reminders.ts"; |
| 69 | import { tokensCss } from "./tokens.ts"; | |
| 70 | import { token, tokensCss } from "./tokens.ts"; | |
| 70 | 71 | import type { Who } from "./who.ts"; |
| 71 | 72 | |
| 72 | 73 | export interface Context { |
| @@ -908,6 +909,45 @@ export const routes: readonly Route[] = [ | ||
| 908 | 909 | }), |
| 909 | 910 | }, |
| 910 | 911 | |
| 912 | // The mark, for the places that ask by name: browsers and link previews look for /favicon.ico. | |
| 913 | { | |
| 914 | method: "GET", | |
| 915 | path: "/favicon.ico", | |
| 916 | handle: () => | |
| 917 | new Response(null, { | |
| 918 | status: 302, | |
| 919 | headers: { location: asset("icon.svg"), ...SECURITY }, | |
| 920 | }), | |
| 921 | }, | |
| 922 | // What "Add to Home Screen" reads: the name, the mark and the colours of the look. | |
| 923 | { | |
| 924 | method: "GET", | |
| 925 | path: "/manifest.webmanifest", | |
| 926 | handle: () => | |
| 927 | new Response( | |
| 928 | JSON.stringify({ | |
| 929 | name: title, | |
| 930 | short_name: title, | |
| 931 | description, | |
| 932 | start_url: "/", | |
| 933 | scope: "/", | |
| 934 | display: "standalone", | |
| 935 | theme_color: token("color-bg"), | |
| 936 | background_color: token("color-bg"), | |
| 937 | icons: [ | |
| 938 | { src: asset("icon.svg"), type: "image/svg+xml", sizes: "any", purpose: "any" }, | |
| 939 | ], | |
| 940 | }), | |
| 941 | { | |
| 942 | headers: { | |
| 943 | "content-type": "application/manifest+json; charset=utf-8", | |
| 944 | "cache-control": "no-cache", | |
| 945 | ...SECURITY, | |
| 946 | }, | |
| 947 | }, | |
| 948 | ), | |
| 949 | }, | |
| 950 | ||
| 911 | 951 | // Files under ./static, cached for a year when linked by content (`asset`). |
| 912 | 952 | { |
| 913 | 953 | method: "GET", |
src/security.ts +2
| @@ -48,6 +48,8 @@ export const WRITES: Rate = { burst: 20, perSecond: 2 }; | ||
| 48 | 48 | /** A stranger's API calls, reads too. Behind the forge every stranger shares one address, so this is all of them together. */ |
| 49 | 49 | export const STRANGERS: Rate = { burst: 60, perSecond: 10 }; |
| 50 | 50 | const buckets = new Map<string, { tokens: number; at: number }>(); |
| 51 | /** Forget every count: for tests, which share this process and so these buckets. */ | |
| 52 | export const forgetRationing = (): void => buckets.clear(); | |
| 51 | 53 | export function allow( |
| 52 | 54 | key: string, |
| 53 | 55 | rate: Rate = WRITES, |
src/server.test.ts +38
| @@ -6,6 +6,7 @@ import { addDays, spoken, today } from "./dates.ts"; | ||
| 6 | 6 | import { agent, env } from "./env.ts"; |
| 7 | 7 | import { drafts } from "./reminders.ts"; |
| 8 | 8 | import { serve } from "./server.ts"; |
| 9 | import { token } from "./tokens.ts"; | |
| 9 | 10 | import { sign } from "./who.ts"; |
| 10 | 11 | |
| 11 | 12 | const KEY = "a-key-only-the-forge-holds"; |
| @@ -400,6 +401,43 @@ test("static files are cached for a year when linked by content", async () => { | ||
| 400 | 401 | expect((await fetch(base + "/static/..%2Fpackage.json")).status).toBe(404); |
| 401 | 402 | }); |
| 402 | 403 | |
| 404 | test("the tab and the home screen carry the mark: icon, favicon.ico and manifest", async () => { | |
| 405 | const page = await (await fetch(base + "/")).text(); | |
| 406 | expect(page).not.toContain("data:,"); | |
| 407 | const icon = /<link rel="icon" type="image\/svg\+xml" href="(\/static\/icon\.svg\?v=[0-9a-f]{8})">/.exec(page)?.[1]; | |
| 408 | expect(icon).toBeDefined(); | |
| 409 | expect(page).toContain('<link rel="manifest" href="/manifest.webmanifest">'); | |
| 410 | ||
| 411 | const svg = await fetch(base + icon!); | |
| 412 | expect(svg.status).toBe(200); | |
| 413 | expect(svg.headers.get("content-type")).toContain("image/svg+xml"); | |
| 414 | expect(svg.headers.get("cache-control")).toContain("immutable"); | |
| 415 | const body = await svg.text(); | |
| 416 | expect(body).toContain("prefers-color-scheme: dark"); | |
| 417 | for (const mode of ["light", "dark"] as const) { | |
| 418 | expect(body).toContain(token("color-bg", mode)); | |
| 419 | expect(body).toContain(token("color-accent", mode)); | |
| 420 | } | |
| 421 | ||
| 422 | const favicon = await fetch(base + "/favicon.ico", { redirect: "manual" }); | |
| 423 | expect(favicon.status).toBe(302); | |
| 424 | expect(favicon.headers.get("location")).toBe(icon!); | |
| 425 | expect(favicon.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 426 | ||
| 427 | const manifest = await fetch(base + "/manifest.webmanifest"); | |
| 428 | expect(manifest.status).toBe(200); | |
| 429 | expect(manifest.headers.get("content-type")).toContain("application/manifest+json"); | |
| 430 | expect(manifest.headers.get("content-security-policy")).toContain("default-src 'self'"); | |
| 431 | const m = (await manifest.json()) as Record<string, unknown> & { icons: { src: string; type: string }[] }; | |
| 432 | expect(m.start_url).toBe("/"); | |
| 433 | expect(m.display).toBe("standalone"); | |
| 434 | expect(typeof m.name).toBe("string"); | |
| 435 | expect(typeof m.short_name).toBe("string"); | |
| 436 | expect(m.theme_color).toBe(token("color-bg")); | |
| 437 | expect(m.background_color).toBe(token("color-bg")); | |
| 438 | expect(m.icons[0]).toMatchObject({ src: icon!, type: "image/svg+xml" }); | |
| 439 | }); | |
| 440 | ||
| 403 | 441 | test("/healthz says up, apart from the page", async () => { |
| 404 | 442 | const response = await fetch(base + "/healthz"); |
| 405 | 443 | expect(response.status).toBe(200); |
static/icon.svg added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32"> | |
| 2 | <style> | |
| 3 | .tile { fill: #f6f3ec; } | |
| 4 | .mark { stroke: #1d5c57; fill: none; stroke-linecap: round; } | |
| 5 | @media (prefers-color-scheme: dark) { | |
| 6 | .tile { fill: #121516; } | |
| 7 | .mark { stroke: #7fcbc2; } | |
| 8 | } | |
| 9 | </style> | |
| 10 | <rect class="tile" width="32" height="32" rx="7"/> | |
| 11 | <circle class="mark" cx="16" cy="16" r="10" stroke-width="3"/> | |
| 12 | <path class="mark" d="M16 16V9.5M16 16l4.6 2.7" stroke-width="3"/> | |
| 13 | </svg> |
new above
offline