Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
# `@punktfunk/host` comes from the Gitea npm registry (`.npmrc` names the scope). Reads
# are anonymous there, so no secret is needed to install.
- run: npm ci
# The page's messages come from the pinned monorepo's checkout, which cargo finds
# (`scripts/l10n-messages.mjs`, run by the app's `check`, `test` and `build`).
- run: rustup toolchain install
working-directory: packages/stream
- run: npm run check
- run: npm test
# The screens as Storybook renders them, without the wasm: the stories never start the
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ node_modules/
/packages/stream/wasm/*.js
/packages/stream/wasm/*.wasm
/apps/web/dist
/apps/web/l10n
/apps/web/src/paraglide
/apps/web/storybook-static
/apps/web/screenshots
/target
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ Four tools, each for what it is for, in this order:
4. **Vite** builds the app from source — the library through a workspace alias, the SDK, Effect —
and turns the library's wasm reference into an emitted asset.

The page's words are not in this repo. They are the pinned monorepo's `l10n/messages`, which
`scripts/l10n-messages.mjs` finds through cargo and copies into `apps/web/l10n/` before the app's
`dev`, `check`, `test` and `build` run, so those need the Rust toolchain and the checkout cargo
fetches for the pin. The page follows the browser's language list, and a language shows once the
pinned monorepo ships it.

For development against a real host without accepting its certificate first, build the debug
module once (`packages/stream/build.sh`, seconds to relink) and run the dev server:

Expand Down
9 changes: 9 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
"type": "module",
"description": "The punktfunk web client — the flagship consumer of @punktfunk/stream. React + @unom/ui + Tailwind, the same stack as the host's management console.",
"scripts": {
"l10n": "node ../../scripts/l10n-messages.mjs && paraglide-js compile --project ./project.inlang --outdir ./src/paraglide --strategy preferredLanguage baseLocale",
"predev": "npm run l10n",
"dev": "vite",
"prebuild": "npm run l10n",
"build": "vite build",
"precheck": "npm run l10n",
"check": "tsc --noEmit",
"pretest": "npm run l10n",
"test": "node --experimental-transform-types --disable-warning=ExperimentalWarning --test 'src/**/*.test.ts'",
"prestorybook": "npm run l10n",
"storybook": "storybook dev -p 6006",
"prebuild-storybook": "npm run l10n",
"build-storybook": "storybook build",
"screenshots": "node tools/screenshots.mjs"
},
Expand All @@ -29,6 +36,8 @@
"zod": "^4.6.5"
},
"devDependencies": {
"@inlang/paraglide-js": "^2.29.3",
"@inlang/plugin-message-format": "^4.6.0",
"@storybook/react-vite": "^10.6.0",
"@tailwindcss/vite": "^4.3.3",
"@types/react": "^19.3.0",
Expand Down
16 changes: 16 additions & 0 deletions apps/web/project.inlang/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://inlang.com/schema/project-settings",
"baseLocale": "en",
"locales": ["en"],
"modules": [
"../../node_modules/@inlang/plugin-message-format/dist/index.js"
],
"plugin.inlang.messageFormat": {
"pathPattern": [
"./l10n/browser/{locale}.json",
"./l10n/client/{locale}.json",
"./l10n/common/{locale}.json",
"./l10n/host/{locale}.json"
]
}
}
68 changes: 34 additions & 34 deletions apps/web/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// hosts, trust, pairing and the session lives in the library, which is what lets the same engine
// sit under a TV app without a line of this file.

import "./words.ts";
import {
captureLog,
Engine,
Expand Down Expand Up @@ -40,12 +41,13 @@ import {
type Settings,
settings,
statusOf,
TOO_MANY,
VersionSkew,
wakeFailed,
wakingLine,
} from "@punktfunk/stream";
import { type Configured, readConfig, type ServerConfig } from "./config.ts";
import { m } from "./paraglide/messages.js";
import { apiText } from "./words.ts";
import { ConsoleUi } from "./ui/console.ts";
import { noop, WebShell } from "./ui/shell.tsx";
import type { HostCard, HostTools, ProfileCard, Screen, Tab, Ui } from "./ui/types.ts";
Expand Down Expand Up @@ -263,7 +265,7 @@ class App {
// The server turned its list away: say so, and ask again on a later redraw of the hosts.
if (server.wait) {
this.configAgainAt = Date.now() + server.wait * 1000;
ui.notify(sentence(TOO_MANY), "error");
ui.notify(m.browser_too_many(), "error");
}
this.applyPrefs();
this.watchSize();
Expand Down Expand Up @@ -344,8 +346,8 @@ class App {
case "unreachable":
return this.show({
kind: "error",
head: "No answer",
text: `Nothing responded at ${bare(s.origin)}. Check the address, and that the host is running.`,
head: m.browser_no_answer_title(),
text: m.error_host_timeout(),
retry: true,
});
case "untrusted":
Expand Down Expand Up @@ -374,7 +376,7 @@ class App {
kind: "pair",
origin: s.origin,
mode: "first",
error: s.reason ? sentence(s.reason) : "That PIN was refused.",
error: s.reason ? sentence(s.reason) : m.pair_wrong_pin(),
});
case "forgotten":
return this.show({ kind: "pair", origin: s.origin, mode: "again" });
Expand Down Expand Up @@ -434,13 +436,11 @@ class App {
return this.show({
kind: "error",
head: s.skew
? "This host speaks a different version"
? m.browser_skew_title()
: this.dropped
? "The stream stopped"
: "Something went wrong",
text: s.skew
? `${sentence(s.message)} Update the host, or this page, so the two agree.`
: sentence(s.message),
: m.browser_error_title(),
text: s.skew ? `${sentence(s.message)} ${m.browser_skew_hint()}` : sentence(s.message),
retry: !s.skew,
});
}
Expand Down Expand Up @@ -628,10 +628,10 @@ class App {
if (parsed === null) return;
history.replaceState(null, "", location.pathname + location.hash);
if (typeof parsed === "string") {
return this.show({ kind: "error", head: "That link can't be used", text: LINK_ERRORS[parsed] });
return this.show({ kind: "error", head: m.link_refused_title(), text: LINK_ERRORS[parsed]() });
}
const found = this.resolveLink(parsed);
if (typeof found === "string") return this.show({ kind: "error", head: "That link can't be used", text: found });
if (typeof found === "string") return this.show({ kind: "error", head: m.link_refused_title(), text: found });
const { target, name, address } = found;
this.link = { target, ...(parsed.fp ? { fp: parsed.fp } : {}), ...(parsed.launch ? { launch: parsed.launch } : {}) };
this.show({ kind: "link", name, address, ...(parsed.launch ? { launch: parsed.launch } : {}) });
Expand All @@ -651,10 +651,10 @@ class App {
}
const byOrigin = all.find((h) => h.origin === origin || h.origin === link.host.replace(/\/+$/, ""));
const byName = all.filter((h) => h.name?.toLowerCase() === link.host.toLowerCase());
if (!byOrigin && byName.length > 1) return `More than one host here is called “${link.host}”.`;
if (!byOrigin && byName.length > 1) return m.link_ambiguous_host({ name: link.host });
const hit = byOrigin ?? byName[0];
if (hit) return { target: this.targetOf(hit.origin), name: hit.name ?? bare(hit.origin), address: bare(hit.origin) };
if (!origin) return `“${link.host}” is not an address or a host this page knows.`;
if (!origin) return m.link_unknown_host({ name: link.host });
return { target: this.targetOf(link.host), name: link.name ?? bare(origin), address: bare(origin) };
}

Expand Down Expand Up @@ -684,10 +684,10 @@ class App {
const fingerprint = this.engine.knownHosts().find((h) => h.origin === origin)?.fingerprint;
try {
await navigator.clipboard.writeText(linkFor(location.href, origin, fingerprint));
this.ui.notify(`Link to ${this.nameOf(origin)} copied.`);
this.ui.notify(m.hostcard_link_copied());
} catch (e) {
console.warn("punktfunk: copy link", e);
this.ui.notify("Couldn't copy the link — the browser kept the clipboard.", "error");
this.ui.notify(m.hostcard_link_copy_failed(), "error");
}
}

Expand All @@ -705,7 +705,7 @@ class App {
try {
const r = await serverFetch()(url, { method: "POST" });
if (r.status === 403 || r.status === 429) {
const why = r.status === 429 ? sentence(TOO_MANY) : `Only a browser paired with ${this.nameOf(origin)} can wake it from this page.`;
const why = r.status === 429 ? m.browser_too_many() : m.browser_wake_unpaired({ host: this.nameOf(origin) });
this.ui.notify(why, "error");
return false;
}
Expand All @@ -717,11 +717,11 @@ class App {
this.reachCache.set(origin, { reach: now, at: Date.now() });
up = now === "ok";
}
if (!up) this.ui.notify(`${this.nameOf(origin)} didn't answer within a minute of waking. It may still be starting.`, "error");
if (!up) this.ui.notify(m.browser_wake_timeout({ host: this.nameOf(origin) }), "error");
return true;
} catch (e) {
console.warn("punktfunk: wake", e);
this.ui.notify(`Couldn't wake ${this.nameOf(origin)} — this page's server didn't send the wake packet.`, "error");
this.ui.notify(m.browser_wake_failed({ host: this.nameOf(origin) }), "error");
return false;
} finally {
this.waking.delete(origin);
Expand Down Expand Up @@ -763,8 +763,8 @@ class App {
if (e instanceof VersionSkew) {
return this.show({
kind: "error",
head: "This host speaks a different version",
text: `${sentence(e.message)} Update the host, or this page, so the two agree.`,
head: m.browser_skew_title(),
text: `${sentence(e.message)} ${m.browser_skew_hint()}`,
});
}
// The stream still works without a library, so this is a line on the page rather than a
Expand Down Expand Up @@ -846,7 +846,7 @@ class App {
...(mine ? this.resumable() : {}),
...(mine && connected && this.running && this.runningEndable ? { endable: true } : {}),
...(mine && this.endNotice ? { notice: this.endNotice } : {}),
...(mine && this.libraryError ? { error: `${sentence(this.libraryError)} You can still stream the desktop.` } : {}),
...(mine && this.libraryError ? { error: m.browser_lib_load_failed_desktop({ why: sentence(this.libraryError) }) } : {}),
});
void this.probe(shelves.map((h) => h.origin));
}
Expand Down Expand Up @@ -880,7 +880,7 @@ class App {
enabled: a.available && a.permitted,
...(a.available && a.permitted
? {}
: { reason: a.available ? "This device's access does not include it" : (a.unavailable_reason ?? "Not on this host") }),
: { reason: a.available ? "This device's access does not include it" : (apiText(a["unavailable_code"] as string | undefined, a["unavailable_params"] as Record<string, string> | undefined, a.unavailable_reason) ?? "Not on this host") }),
})),
});
} catch (e) {
Expand Down Expand Up @@ -1139,7 +1139,7 @@ class App {
cards: gate.rows.map((p) => cardOf(p, this.pictures)),
...(saved ? { saved: saved.id } : {}),
...(decision?.gone ? { gone: decision.gone } : {}),
...(listed === undefined ? { error: "Couldn't load the profiles." } : {}),
...(listed === undefined ? { error: m.profile_load_failed() } : {}),
};
this.gateShow(gate, picker);
void this.readPictures(gate, picker);
Expand Down Expand Up @@ -1213,7 +1213,7 @@ class App {
}

private gateFailed(gate: Gate, line: string): void {
this.gateShow(gate, { kind: "error", head: "Couldn't start the stream", text: sentence(line) });
this.gateShow(gate, { kind: "error", head: m.browser_gate_failed_title(), text: sentence(line) });
}

private cancelGate(): void {
Expand Down Expand Up @@ -1296,12 +1296,12 @@ function readShelf(): string | null {
}

/** Why a link was refused, as a sentence. */
const LINK_ERRORS: Record<Exclude<ReturnType<typeof parseLink>, PageLink | null>, string> = {
"missing-host": "It does not say which host to connect to.",
"too-long": "One of its parts is longer than a real link's.",
"control-char": "It carries characters no real link does.",
"bad-fingerprint": "Its host fingerprint is not one.",
"bad-launch": "Its game id is not a valid one.",
const LINK_ERRORS: Record<Exclude<ReturnType<typeof parseLink>, PageLink | null>, () => string> = {
"missing-host": () => m.link_error_missing_host_ref(),
"too-long": () => m.link_error_too_long(),
"control-char": () => m.link_error_malformed(),
"bad-fingerprint": () => m.link_error_bad_fingerprint(),
"bad-launch": () => m.link_error_bad_launch_id(),
};

/** The engine speaks in lowercase fragments, as logs do; a screen speaks in sentences. */
Expand Down Expand Up @@ -1416,7 +1416,7 @@ const EXIT_HINT_MS = 6000;
/** How to leave with the input in hand: the pad chord with a controller connected, the dial's
* End stream on a touchscreen, the key otherwise. */
function exitHintText(): string {
if (navigator.getGamepads?.().some((g) => g?.mapping === "standard")) return "Hold L1 + R1 + Start + Select to leave";
if (matchMedia("(pointer: coarse)").matches) return "Menu, then End stream, to leave";
return "Ctrl+Alt+Shift+D to leave";
if (navigator.getGamepads?.().some((g) => g?.mapping === "standard")) return m.notice_exit_hold({ keys: "L1 + R1 + Start + Select" });
if (matchMedia("(pointer: coarse)").matches) return m.browser_exit_menu();
return m.notice_exit_keys({ keys: "Ctrl+Alt+Shift+D" });
}
5 changes: 4 additions & 1 deletion apps/web/src/ui/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
tizen,
tvBack,
} from "@punktfunk/stream";
import { m } from "../paraglide/messages.js";
import { FrameMeter, type Row, type Step, Sweep, table } from "./console-cost.ts";
import { hostRow, originFor } from "./console-hosts.ts";
import { coverBytes } from "./cover.ts";
Expand Down Expand Up @@ -340,6 +341,8 @@ export class ConsoleUi implements Ui {
// Answers `FetchProfiles`, so a connect picks the profile and readies its seat first.
profiles: true,
settings: this.startSettings(),
// The browser's own list, most preferred first: the console words itself in the first it ships.
languages: [...navigator.languages],
});
if (!this.started) {
console.error("punktfunk: the console could not start; the web shell stays up");
Expand Down Expand Up @@ -742,7 +745,7 @@ export class ConsoleUi implements Ui {
this.gamesSent = sig;
if (s.error) {
this.pushLibrary(CONSOLE_PUSH.LIBRARY_PHASE, "phase", {
Error: { title: "The library could not be read", body: s.error, can_retry: true },
Error: { title: m.lib_load_failed(), body: s.error, can_retry: true },
});
} else if (s.entries.length === 0) {
this.pushLibrary(CONSOLE_PUSH.LIBRARY_PHASE, "phase", s.busy ? "Loading" : "Empty");
Expand Down
21 changes: 11 additions & 10 deletions apps/web/src/ui/frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Gamepad2, LibraryBig, type LucideIcon, Monitor, Settings } from "lucide
import { motion, stagger, type Variants } from "motion/react";
import type { JSX, ReactNode } from "react";
import { staggerProps } from "@/components/stagger";
import { m } from "../paraglide/messages.js";
import { BrandMark, Wordmark } from "./brand.tsx";
import type { Actions, Tab } from "./types.ts";

Expand All @@ -34,10 +35,10 @@ const PRESS = { scale: 0.9 };
const HOVER = { scale: 1.02 };
const TAP = { scale: 0.98 };

const TABS: ReadonlyArray<{ tab: Tab; icon: LucideIcon; label: string }> = [
{ tab: "hosts", icon: Monitor, label: "Hosts" },
{ tab: "library", icon: LibraryBig, label: "Library" },
{ tab: "settings", icon: Settings, label: "Settings" },
const TABS: ReadonlyArray<{ tab: Tab; icon: LucideIcon; label: () => string }> = [
{ tab: "hosts", icon: Monitor, label: () => m.hosts_tab() },
{ tab: "library", icon: LibraryBig, label: () => m.hosts_tab_library() },
{ tab: "settings", icon: Settings, label: () => m.hosts_tab_settings() },
];

export function Frame({
Expand All @@ -62,21 +63,21 @@ export function Frame({
<BrandMark className="size-7 shrink-0 drop-shadow-[0_2px_12px_rgba(108,91,243,0.45)]" animate={false} />
<Wordmark className="hidden h-4 w-auto lg:block" animate={false} />
</div>
<motion.nav aria-label="Main" initial="from" animate="enter" {...staggerProps()} className="flex flex-1 flex-col gap-1">
<motion.nav aria-label={m.browser_nav_main_a11y()} initial="from" animate="enter" {...staggerProps()} className="flex flex-1 flex-col gap-1">
{TABS.map(({ tab: t, icon, label }) => (
<SidebarItem
key={t}
icon={icon}
label={label}
label={label()}
sub={t === "library" ? host : undefined}
active={tab === t}
onClick={() => actions.navigate(t)}
/>
))}
<SidebarItem
icon={Gamepad2}
label="Console mode"
title="Console mode — the controller interface"
label={m.browser_nav_console()}
title={m.browser_nav_console_hint()}
className="mt-auto"
onClick={() => actions.consoleMode(true)}
/>
Expand All @@ -96,7 +97,7 @@ export function Frame({
</div>

<motion.nav
aria-label="Main"
aria-label={m.browser_nav_main_a11y()}
initial="from"
animate="enter"
variants={BAR}
Expand All @@ -119,7 +120,7 @@ export function Frame({
<TabIcon active={tab === t}>
<Icon className="size-5 shrink-0" />
</TabIcon>
<span className="w-full truncate text-center leading-tight">{label}</span>
<span className="w-full truncate text-center leading-tight">{label()}</span>
</motion.button>
))}
</motion.nav>
Expand Down
Loading
Loading