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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/48-the-browser-tab-and-a-phone-s-home-scree → main 2 commits fork

  • Merged. mason/48-the-browser-tab-and-a-phone-s-home-scree was merged into main as 0860573.

Review

Sign in to review this change.
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
113113 deals below the clock, then Restore the sample deals and confirms: the four
114114 samples return as they were, dated from today, and the deals you opened are
115115 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.
116119
117120 ## Make it yours
118121
src/audit.test.ts +4 −1
@@ -3,13 +3,14 @@
33 * the real server; only an admin reads them; and a trail that cannot be
44 * written costs a log line, never the request.
55 */
6 import { afterAll, expect, spyOn, test } from "bun:test";
6 import { afterAll, beforeEach, expect, spyOn, test } from "bun:test";
77 import { mkdtempSync } from "node:fs";
88 import { tmpdir } from "node:os";
99 import { join } from "node:path";
1010 import { createDeal } from "./deals.ts";
1111 import type { AuditRow } from "./audit.ts";
1212 import { openDb } from "./db.ts";
13 import { forgetRationing } from "./security.ts";
1314 import { serve } from "./server.ts";
1415 import { sign } from "./who.ts";
1516
@@ -21,6 +22,8 @@ const server = serve({
2122 });
2223 const base = `http://${server.hostname}:${server.port}`;
2324 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);
2427
2528 const as = (
2629 id: string,
src/pages/layout.ts +4 −1
@@ -20,6 +20,8 @@ import { contactLinks } from "./contact.ts";
2020 import { token, tokensHref } from "../tokens.ts";
2121 import type { Who } from "../who.ts";
2222
23 const iconHref = asset("icon.svg");
24
2325 export function layout(input: {
2426 body: string;
2527 who: Who;
@@ -48,7 +50,8 @@ export function layout(input: {
4850 <meta name="color-scheme" content="light dark">
4951 <meta name="theme-color" content="${token("color-bg")}" media="(prefers-color-scheme: light)">
5052 <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">
5255 <title>${escape(pageTitle)}</title>
5356 <meta name="description" content="${escape(description)}">
5457 <meta property="og:type" content="website">
src/routes.ts +42 −2
@@ -20,8 +20,9 @@ import {
2020 type Failure,
2121 type Result,
2222 } 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";
2424 import {
25 asset,
2526 back,
2627 fields,
2728 html,
@@ -66,7 +67,7 @@ import { refusedPage } from "./pages/refused.ts";
6667 import { timelinePage } from "./pages/timeline.ts";
6768 import { welcomePage } from "./pages/welcome.ts";
6869 import { dueOn } from "./reminders.ts";
69 import { tokensCss } from "./tokens.ts";
70 import { token, tokensCss } from "./tokens.ts";
7071 import type { Who } from "./who.ts";
7172
7273 export interface Context {
@@ -908,6 +909,45 @@ export const routes: readonly Route[] = [
908909 }),
909910 },
910911
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
911951 // Files under ./static, cached for a year when linked by content (`asset`).
912952 {
913953 method: "GET",
src/security.ts +2
@@ -48,6 +48,8 @@ export const WRITES: Rate = { burst: 20, perSecond: 2 };
4848 /** A stranger's API calls, reads too. Behind the forge every stranger shares one address, so this is all of them together. */
4949 export const STRANGERS: Rate = { burst: 60, perSecond: 10 };
5050 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();
5153 export function allow(
5254 key: string,
5355 rate: Rate = WRITES,
src/server.test.ts +38
@@ -6,6 +6,7 @@ import { addDays, spoken, today } from "./dates.ts";
66 import { agent, env } from "./env.ts";
77 import { drafts } from "./reminders.ts";
88 import { serve } from "./server.ts";
9 import { token } from "./tokens.ts";
910 import { sign } from "./who.ts";
1011
1112 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 () => {
400401 expect((await fetch(base + "/static/..%2Fpackage.json")).status).toBe(404);
401402 });
402403
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
403441 test("/healthz says up, apart from the page", async () => {
404442 const response = await fetch(base + "/healthz");
405443 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>

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs