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
2 changes: 1 addition & 1 deletion apps/web/project.inlang/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://inlang.com/schema/project-settings",
"baseLocale": "en",
"locales": ["en", "de", "es", "fr"],
"locales": ["en", "de", "es", "fr", "it", "pt-BR"],
"modules": [
"../../node_modules/@inlang/plugin-message-format/dist/index.js"
],
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/_e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ try {
const info = await l.host.info();
log("ok ready; host " + info.hostname);
try {
const lib = await l.host.library();
const lib = (await l.host.library()).entries;
log(`ok library: ${lib.length} entries`);
// Covers as the grid asks for them: an object URL, a CDN URL, nothing, or a throw.
const tally = { shown: 0, none: 0, missing: 0, failed: 0 };
Expand Down
224 changes: 203 additions & 21 deletions apps/web/src/app.ts

Large diffs are not rendered by default.

77 changes: 72 additions & 5 deletions apps/web/src/ui/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ export class ConsoleUi implements Ui {
private pairReq: ConsoleReq = NO_REQ;
private libraryReq: ConsoleReq = NO_REQ;
private pendingPlay: { origin: string; id: string | null; title: string; profile: string } | null = null;
/** The rows of the hidden list the console last asked for: a title it shows again goes back
* on the shelf whole. */
private hiddenRows = new Map<string, LibraryEntry>();
/** A `FetchProfiles` for a host the engine is not on: it is reached quietly and answered once
* ready, without re-rooting the console on its shelf mid-ask. */
private profilesAsk: { origin: string; fp: string; at: number } | null = null;
Expand Down Expand Up @@ -262,8 +265,8 @@ export class ConsoleUi implements Ui {

/** The web shell's toaster shows over the canvas too; the console has no line of its own
* for something that is not a screen. */
notify(text: string, tone?: "error"): void {
this.fallback.notify(text, tone);
notify(text: string, tone?: "error", action?: { label: string; run: () => void }): void {
this.fallback.notify(text, tone, action);
}

mount(actions: Actions): void {
Expand Down Expand Up @@ -352,6 +355,10 @@ export class ConsoleUi implements Ui {
tizen: tizen(),
// Answers `FetchProfiles`, so a connect picks the profile and readies its seat first.
profiles: true,
// A profile's PIN or password is typed on the console's own screen; the engine sends it.
prompts_unlock: true,
// Answers `SetHidden` and `FetchHidden`: Hide for me.
hides: true,
settings: this.startSettings(),
// The browser's own list, most preferred first: the console words itself in the first it ships.
languages: [...navigator.languages],
Expand Down Expand Up @@ -648,7 +655,15 @@ export class ConsoleUi implements Ui {
}
return;
case "connecting":
if (this.dialled) c.phase(0);
// `opening`: the host took the unlock and starts the profile's desktop.
if (this.dialled) c.phase(s.phase === "opening" ? 6 : 0);
return;
case "unlock":
// The host wants the profile's unlock: the console's prompt opens with its sentence.
// Once per refusal: a redraw of the same screen is not another one.
if (was?.kind === "unlock") return;
this.dialled = false;
c.phase(7, s.error ?? "");
return;
case "pair": {
const pin = this.pendingPin;
Expand Down Expand Up @@ -924,7 +939,8 @@ export class ConsoleUi implements Ui {
}
const now = this.engine.current;
const profile = l.profile ?? "";
if (now.kind === "ready" && now.origin === origin) {
// `profile-locked`: this launch is the prompt's, and dials from where the host left it.
if ((now.kind === "ready" || now.kind === "profile-locked") && now.origin === origin) {
this.actions?.play(l.launch ? ({ id: l.launch, title: l.title } as LibraryEntry) : undefined, profile);
return;
}
Expand All @@ -942,9 +958,10 @@ export class ConsoleUi implements Ui {
this.libraryReq = reqOf(body);
const now = this.engine.current;
if (now.kind === "ready" && now.origin === origin) {
// Already there: hand the shelf what the app has.
// Already there: hand the shelf what the app has, read again when the pick moved.
this.gamesSent = "";
this.artSent.clear();
this.actions?.browse(origin);
if (this.screen?.kind === "library") this.library(this.screen);
return;
}
Expand Down Expand Up @@ -1028,6 +1045,22 @@ export class ConsoleUi implements Ui {
case "EndGame":
if (origin) void this.endGame(origin, str("app_id"), str("title"));
return;
case "FetchHidden": {
const [fp, profile] = [str("fp_hex"), str("profile")];
const host = origin ? this.apiFor(origin) : undefined;
if (!origin || !host) return this.pushHidden(fp, profile, { Failed: m.browser_lib_not_connected_this_host() });
void this.answerHidden(origin, fp, profile, host);
return;
}
case "SetHidden": {
const [fp, profile, id] = [str("fp_hex"), str("profile"), str("app_id")];
const hidden = body["hidden"] === true;
const entry = this.hiddenRows.get(id) ?? ({ id, title: str("title") } as LibraryEntry);
void this.actions?.setHidden(entry, hidden, { id: profile, name: str("name") }).then(({ done, notice }) =>
this.engine.console.push(CONSOLE_PUSH.HIDE, { fp_hex: fp, profile, app_id: id, hidden, done, notice }),
);
return;
}
case "SetScreen":
if (origin && body["screen"]) void this.setScreen(origin, body["screen"] as DisplayTarget, str("topology"));
return;
Expand Down Expand Up @@ -1073,6 +1106,40 @@ export class ConsoleUi implements Ui {
this.engine.console.push(CONSOLE_PUSH.PROFILES, { fp_hex: fp, answer });
}

/** What `profile` hides, for the console's `FetchHidden`: its rows, then their covers. */
private async answerHidden(origin: string, fp: string, profile: string, host: Host): Promise<void> {
let rows: LibraryEntry[];
try {
rows = await host.hidden(profile);
} catch (e) {
return this.pushHidden(fp, profile, { Failed: e instanceof Error ? e.message : String(e) });
}
this.hiddenRows = new Map(rows.map((e) => [e.id, e]));
this.pushHidden(fp, profile, { Listed: rows.map((e) => game(e, undefined)) });
for (const e of rows) {
const art = e.art?.portrait ?? e.art?.header;
if (!art || this.artSent.has(e.id)) continue;
this.artSent.add(e.id);
this.toDecode.push(async () => {
try {
const url = await host.art(art);
if (!url) return;
const blob = await (await fetch(url)).blob();
if (url.startsWith("blob:")) URL.revokeObjectURL(url);
const bytes = (await coverBytes(blob)) ?? new Uint8Array(await blob.arrayBuffer());
if (this.shelf === origin) this.covers.push([origin, e.id, bytes]);
} catch {
this.artSent.delete(e.id);
}
});
}
this.decodeNext();
}

private pushHidden(fp: string, profile: string, answer: unknown): void {
this.engine.console.push(CONSOLE_PUSH.HIDDEN, { fp_hex: fp, profile, answer });
}

/** What the host runs, as the console's launch hold and Resume badge read it. Unanswered,
* the hold gives up after 15 s and covers the stream with a failure. */
private refreshRunning(origin: string): void {
Expand Down
13 changes: 13 additions & 0 deletions apps/web/src/ui/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const hosts: HostCard[] = [
];
const shelves = hosts.filter((h) => h.fingerprint);
const origin = "https://192.168.1.25:47990";
/** Kid's shelf: the box's, less what Kid hides. */
const kids = entries.filter((_, i) => ![1, 3, 9].includes(i));
const kidsHidden = [entries[1]!, entries[3]!, entries[9]!];
const kidsShelf = { kind: "library", origin, shelves, host: "living-room-pc", entries: kids, art, hide: { name: "Kid" } } as const;
/** The statistics where a fresh browser puts them. */
const overlay = { corner: "topTrailing", scale: 1 } as const;

Expand Down Expand Up @@ -82,13 +86,22 @@ export const SCREENS = {
},
"profiles-gone": { kind: "profiles", origin: "https://192.168.1.25:47990", host: "Living room", gone: "Old desk", cards: [{ id: "a1", name: "Mia", initials: "M", accent: "#e0457b" }] },
"seat": { kind: "seat", origin: "https://192.168.1.25:47990", title: "Getting Kid's desk ready…", detail: "Signing in…" },
"unlock": { kind: "unlock", origin, host: "Living room", name: "Kid", form: "pin" },
"unlock-refused": { kind: "unlock", origin, host: "Living room", name: "Kid", form: "pin", error: "That isn't this profile's PIN." },
"unlock-wait": { kind: "unlock", origin, host: "Living room", name: "Kid", form: "pin", error: "Too many wrong PINs. Try again in 3 minutes." },
"unlock-password": { kind: "unlock", origin, host: "Living room", name: "Mia", form: "password" },
"opening": { kind: "connecting", origin, phase: "opening", host: "Living room" },
"link": { kind: "link", name: "Desk", address: "192.168.1.21", launch: "steam:570" },
"trust": {
kind: "trust",
origin: "https://192.168.1.25:47990",
reason: "this is not the host that was paired with",
},
"library": { kind: "library", origin, shelves, host: "living-room-pc", entries, art, running: "Hades", resume: entries[1]! },
"library-profile": kidsShelf,
"library-hidden": { ...kidsShelf, hidden: { name: "Kid", entries: kidsHidden } },
"library-hidden-none": { ...kidsShelf, hidden: { name: "Kid", entries: [] } },
"library-hidden-failed": { ...kidsShelf, hidden: { name: "Kid", failed: true } },
"library-empty": { kind: "library", origin, shelves, host: "living-room-pc", entries: [], art: new Map() },
"library-loading": { kind: "library", origin, shelves, host: "living-room-pc", entries: [], art: new Map(), busy: true },
"library-offline": { kind: "library", origin, shelves, host: "living-room-pc", entries: [], art: new Map(), offline: true },
Expand Down
97 changes: 92 additions & 5 deletions apps/web/src/ui/library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { LibraryEntry } from "@punktfunk/stream";
import { cn } from "@unom/ui/lib/utils";
import { CircleX, Monitor, Play, Search, Server } from "lucide-react";
import { CircleX, EyeOff, Monitor, Play, Search, Server } from "lucide-react";
import { motion } from "motion/react";
import { type JSX, type KeyboardEvent, useRef, useState } from "react";
import { ROW, ROW_GAP, Stagger, staggerProps } from "@/components/stagger";
Expand Down Expand Up @@ -52,6 +52,7 @@ export function Library({ screen, actions }: { screen: LibraryScreen; actions: A
return (
<Body>
{screen.tools && <HostSheet host={screen.host ?? ""} tools={screen.tools} actions={actions} />}
{screen.hidden && <HiddenSheet hidden={screen.hidden} actions={actions} />}
<PageHead
title={
<span className="flex items-center gap-3">
Expand All @@ -68,6 +69,12 @@ export function Library({ screen, actions }: { screen: LibraryScreen; actions: A
</Button>
)}
{screen.endable && screen.running && <EndGame onEnd={() => actions.endGame()} />}
{screen.hide && (
<Button size="sm" variant="ghost" onClick={() => actions.openHidden(true)}>
<EyeOff className="size-4" />
{m.lib_hidden_for({ name: screen.hide.name })}
</Button>
)}
{!screen.offline && (
<Button size="icon" variant="ghost" aria-label="Host actions" title="Host actions" onClick={() => actions.openTools(true)}>
<Server className="size-4" />
Expand Down Expand Up @@ -191,7 +198,7 @@ function Grid({ entries, screen, actions }: { entries: LibraryEntry[]; screen: L
const onKey = (e: KeyboardEvent<HTMLUListElement>) => {
const el = grid.current;
if (!el) return;
const tiles = [...el.querySelectorAll<HTMLButtonElement>("button")];
const tiles = [...el.querySelectorAll<HTMLButtonElement>("button[data-tile]")];
const i = tiles.indexOf(document.activeElement as HTMLButtonElement);
if (i < 0) return;
const cols = Math.max(1, getComputedStyle(el).gridTemplateColumns.split(" ").length);
Expand All @@ -216,20 +223,56 @@ function Grid({ entries, screen, actions }: { entries: LibraryEntry[]; screen: L
art={screen.art.get(entry.id)}
running={screen.running === entry.title}
onPlay={() => actions.play(entry)}
hide={screen.hide?.name}
onHide={() => actions.setHidden(entry, true)}
/>
))}
</motion.ul>
);
}

/** A poster: 2:3 art, the title under it. Until its cover arrives the title stands in the frame;
* the cover then fades in over it rather than popping. */
function Tile({ entry, art, running, onPlay }: { entry: LibraryEntry; art: string | undefined; running: boolean; onPlay: () => void }): JSX.Element {
* the cover then fades in over it rather than popping. `hide` names the profile the shelf plays
* as when this device may hide titles for it: the tile then offers that, in its corner. */
function Tile({
entry,
art,
running,
onPlay,
hide,
onHide,
}: {
entry: LibraryEntry;
art: string | undefined;
running: boolean;
onPlay: () => void;
hide: string | undefined;
onHide: () => Promise<{ done: boolean }>;
}): JSX.Element {
const [loaded, setLoaded] = useState(false);
return (
<motion.li variants={TILE} className="min-w-0">
<motion.li variants={TILE} className="group/tile relative min-w-0">
{hide && (
<Button
size="icon"
variant="secondary"
aria-label={`${m.lib_hide_for({ name: hide })}: ${entry.title}`}
title={m.lib_hide_for({ name: hide })}
// Shown with the pointer on the tile, with focus, and always where nothing hovers.
className="absolute top-2 left-2 z-1 size-8 opacity-0 shadow-sm transition-opacity group-hover/tile:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100"
onClick={(e) => {
// The tile leaves on a yes: its neighbour takes the focus, never the top.
const li = e.currentTarget.closest("li");
const next = (li?.nextElementSibling ?? li?.previousElementSibling)?.querySelector<HTMLElement>("button[data-tile]");
void onHide().then((r) => { if (r.done && li?.contains(document.activeElement)) next?.focus(); });
}}
>
<EyeOff className="size-4" />
</Button>
)}
<button
type="button"
data-tile
aria-label={entry.title}
onClick={onPlay}
className="group flex w-full flex-col gap-2 rounded-[10px] text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
Expand Down Expand Up @@ -263,6 +306,50 @@ function Tile({ entry, art, running, onPlay }: { entry: LibraryEntry; art: strin
);
}

/** What the shelf's profile hides, read when opened: each title dimmed, with the way back. */
function HiddenSheet({ hidden, actions }: { hidden: NonNullable<LibraryScreen["hidden"]>; actions: Actions }): JSX.Element {
const none = hidden.entries?.length === 0;
return (
<Dialog open onOpenChange={(open) => { if (!open) actions.openHidden(false); }}>
<DialogContent className="max-w-md" {...(none ? {} : { "aria-describedby": undefined })}>
<DialogHeader>
<DialogTitle>{m.lib_hidden_for({ name: hidden.name })}</DialogTitle>
{none && <DialogDescription>{m.lib_hidden_none({ name: hidden.name })}</DialogDescription>}
</DialogHeader>
{hidden.failed ? (
<div className="grid gap-3">
<ErrorLine text={m.lib_load_failed()} />
<Button variant="secondary" onClick={() => actions.openHidden(true)}>{m.common_retry()}</Button>
</div>
) : !hidden.entries ? (
<Spinner className="mx-auto my-4 size-8" />
) : (
<ul className="m-0 grid list-none gap-1 p-0">
{hidden.entries.map((entry) => (
<li key={entry.id} className="flex items-center justify-between gap-3 py-1">
<span className="min-w-0 truncate text-muted-foreground" title={entry.title}>{entry.title}</span>
<Button
size="sm"
variant="secondary"
aria-label={`${m.lib_show_for({ name: hidden.name })}: ${entry.title}`}
onClick={(e) => {
// The row leaves on a yes: the next one's button takes the focus.
const li = e.currentTarget.closest("li");
const next = (li?.nextElementSibling ?? li?.previousElementSibling)?.querySelector("button");
void actions.setHidden(entry, false).then((r) => { if (r.done) next?.focus(); });
}}
>
{m.lib_show_for({ name: hidden.name })}
</Button>
</li>
))}
</ul>
)}
</DialogContent>
</Dialog>
);
}

/** End the running title this device launched. It asks twice, as the dial does: unsaved progress
* in the game is lost. */
function EndGame({ onEnd }: { onEnd: () => void }): JSX.Element {
Expand Down
Loading
Loading