From 4e95008bdc8948e6429b58e0e6b2c4db57f866d1 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Sat, 14 Nov 2026 00:21:52 +0100 Subject: [PATCH 1/2] chore(deps): pin the monorepo at 7ff5eeeed The stream crates and the server leave 28c312102, so both halves build one core again. The newer core carries a profile's lock, the console kit's PIN screen and Hide for me; nothing here turns them on yet. The page's messages follow the pin: Italian and Brazilian Portuguese ship with it. --- apps/web/project.inlang/settings.json | 2 +- packages/stream/Cargo.lock | 10 +++++----- packages/stream/Cargo.toml | 8 ++++---- server/Cargo.lock | 4 ++-- server/Cargo.toml | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/web/project.inlang/settings.json b/apps/web/project.inlang/settings.json index 25950d6..4564565 100644 --- a/apps/web/project.inlang/settings.json +++ b/apps/web/project.inlang/settings.json @@ -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" ], diff --git a/packages/stream/Cargo.lock b/packages/stream/Cargo.lock index 7ba7603..b6c697a 100644 --- a/packages/stream/Cargo.lock +++ b/packages/stream/Cargo.lock @@ -531,7 +531,7 @@ dependencies = [ [[package]] name = "fec-rs" version = "0.1.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" [[package]] name = "fiat-crypto" @@ -997,7 +997,7 @@ dependencies = [ [[package]] name = "pf-client-core" version = "0.46.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" dependencies = [ "anyhow", "cfg_aliases", @@ -1013,7 +1013,7 @@ dependencies = [ [[package]] name = "pf-console-ui" version = "0.46.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" dependencies = [ "anyhow", "pf-client-core", @@ -1029,7 +1029,7 @@ dependencies = [ [[package]] name = "pf-l10n" version = "0.46.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" [[package]] name = "pin-project-lite" @@ -1112,7 +1112,7 @@ dependencies = [ [[package]] name = "punktfunk-core" version = "0.46.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" dependencies = [ "aes-gcm", "aws-lc-rs", diff --git a/packages/stream/Cargo.toml b/packages/stream/Cargo.toml index 0e71473..1e96f47 100644 --- a/packages/stream/Cargo.toml +++ b/packages/stream/Cargo.toml @@ -15,7 +15,7 @@ name = "punktfunk-client-web" path = "rust/main.rs" # The punktfunk crates follow the host's release tags, all three together: the client speaks that -# release's wire. This is 28c312102, ahead of v0.46.0. +# release's wire. This is 7ff5eeeed, ahead of v0.46.0. [dependencies] anyhow = "1" # The device fingerprint: SHA-256 of the WebCrypto key's SPKI, which is what the host stores. @@ -23,7 +23,7 @@ anyhow = "1" sha2 = "0.11" # `transport::Transport`, the wire codecs and the SPAKE2 ceremony. `pake`, not `quic`: the # browser plane is WebTransport, so the ceremony is wanted and the quinn runtime under it is not. -punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "28c3121022d22a4b1780e7ba00acc1a1ed9c03d4", default-features = false, features = ["pake"] } +punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "7ff5eeeedcd8c3fad7be45ab57ca7023dced9259", default-features = false, features = ["pake"] } # wasm only. Off it this is a bin that prints how to build it, so `cargo test` on a developer's # desktop stays green and does not resolve skia-safe for a target that wants a second Skia @@ -32,12 +32,12 @@ punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "28c3121022 # The shell itself. `default-features = false`: `vulkan-overlay` is the desktop session binary's, # and it would put `vulkan` on skia-safe and change the prebuilt key away from # `ganesh-gl-jpegd-jpege-pdf-textlayout`, the one build.sh downloads for this target. -pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "28c3121022d22a4b1780e7ba00acc1a1ed9c03d4", default-features = false } +pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "7ff5eeeedcd8c3fad7be45ab57ca7023dced9259", default-features = false } # The bridge's JSON both ways: the model the page pushes, what the shell raises. serde = "1" serde_json = "1" # The portable half — `trust::Settings` for the snapshot store the shell loads from. -pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "28c3121022d22a4b1780e7ba00acc1a1ed9c03d4", default-features = false } +pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "7ff5eeeedcd8c3fad7be45ab57ca7023dced9259", default-features = false } # The SAME line pf-console-ui's wasm block carries, features included: two feature sets in one # build resolve two prebuilt keys, and the second one puts a source build of Skia on the critical # path. Only `host.rs` names it, to build the context and wrap the canvas. diff --git a/server/Cargo.lock b/server/Cargo.lock index 810b20c..6a1eaf3 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -544,7 +544,7 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "fec-rs" version = "0.1.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" [[package]] name = "find-msvc-tools" @@ -1408,7 +1408,7 @@ dependencies = [ [[package]] name = "punktfunk-core" version = "0.46.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=28c3121022d22a4b1780e7ba00acc1a1ed9c03d4#28c3121022d22a4b1780e7ba00acc1a1ed9c03d4" +source = "git+https://git.unom.io/unom/punktfunk?rev=7ff5eeeedcd8c3fad7be45ab57ca7023dced9259#7ff5eeeedcd8c3fad7be45ab57ca7023dced9259" dependencies = [ "aes-gcm", "chacha20poly1305", diff --git a/server/Cargo.toml b/server/Cargo.toml index add45b0..c1827d3 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -41,7 +41,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } wtransport = { version = "0.7", default-features = false, features = ["aws-lc-rs"] } # The same PinVerify and address ranking the native clients use, and the route table, address # classes and plane attestation check the host itself reads. The same rev as packages/stream. -punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "28c3121022d22a4b1780e7ba00acc1a1ed9c03d4", default-features = false, features = ["tls"] } +punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "7ff5eeeedcd8c3fad7be45ab57ca7023dced9259", default-features = false, features = ["tls"] } [dev-dependencies] tower = { version = "0.5", features = ["util"] } From f3d2e16cb4f753f7b040a49859493c5a24e0262f Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Sat, 14 Nov 2026 00:21:57 +0100 Subject: [PATCH 2/2] feat(stream): play as the saved profile in the browser The library is read as the pick this browser keeps for a host. A profile the host no longer holds, or will not show this device, is read once more as the box, with no error. A profile that opens with a PIN or an account password is asked for it before its dial: the web shell's sheet, or the console's own screen. The unlock goes behind the device's answer to the host's challenge, where the browser plane reads it, and is not kept. The host's sentence for one it refused shows under the field. A profile's person hides a title from its tile and brings it back from the list of what the profile hides. The rules replay the monorepo's vectors. --- apps/web/src/_e2e.ts | 2 +- apps/web/src/app.ts | 224 ++++++++- apps/web/src/ui/console.ts | 77 ++- apps/web/src/ui/fixtures.ts | 13 + apps/web/src/ui/library.tsx | 97 +++- apps/web/src/ui/screens.stories.tsx | 50 +- apps/web/src/ui/sheets.tsx | 68 +++ apps/web/src/ui/shell.tsx | 14 +- apps/web/src/ui/types.ts | 31 +- apps/web/src/words.ts | 4 + packages/stream/build.sh | 2 +- packages/stream/rust/host.rs | 57 ++- packages/stream/rust/session.rs | 83 +++- packages/stream/src/console-bridge.ts | 4 + packages/stream/src/emscripten.d.ts | 10 + packages/stream/src/engine.test.ts | 94 ++++ packages/stream/src/engine.ts | 71 ++- packages/stream/src/hide-for-me-vectors.json | 177 +++++++ packages/stream/src/hide.test.ts | 69 +++ packages/stream/src/hide.ts | 91 ++++ packages/stream/src/host.ts | 70 ++- packages/stream/src/index.ts | 4 +- .../stream/src/library-profile-vectors.json | 123 +++++ packages/stream/src/library.test.ts | 75 +++ .../stream/src/profile-unlock-vectors.json | 447 ++++++++++++++++++ packages/stream/src/profiles.test.ts | 9 + packages/stream/src/profiles.ts | 10 +- packages/stream/src/unlock.test.ts | 61 +++ packages/stream/src/unlock.ts | 62 +++ packages/stream/src/words.ts | 4 + 30 files changed, 2017 insertions(+), 86 deletions(-) create mode 100644 packages/stream/src/hide-for-me-vectors.json create mode 100644 packages/stream/src/hide.test.ts create mode 100644 packages/stream/src/hide.ts create mode 100644 packages/stream/src/library-profile-vectors.json create mode 100644 packages/stream/src/library.test.ts create mode 100644 packages/stream/src/profile-unlock-vectors.json create mode 100644 packages/stream/src/unlock.test.ts create mode 100644 packages/stream/src/unlock.ts diff --git a/apps/web/src/_e2e.ts b/apps/web/src/_e2e.ts index 44fff5f..c233221 100644 --- a/apps/web/src/_e2e.ts +++ b/apps/web/src/_e2e.ts @@ -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 }; diff --git a/apps/web/src/app.ts b/apps/web/src/app.ts index cd35882..324abe0 100644 --- a/apps/web/src/app.ts +++ b/apps/web/src/app.ts @@ -17,6 +17,8 @@ import { type EngineState, gameEndNotice, gameGone, + hideNotice, + hideOffer, type HostTarget, hosts, initials, @@ -34,6 +36,7 @@ import { pickerDecision, pickOf, profileNote, + type ProfilePick, type Reach, reach, reachTarget, @@ -46,6 +49,9 @@ import { settings, type Shortcuts, statusOf, + type UnlockForm, + unlockForm, + unlockNeed, VersionSkew, wakeFailed, wakingLine, @@ -86,7 +92,7 @@ const STANDBY_GAP_MS = 5_000; /** The engine's states on the way to a host. Leaving the tab they sit under cancels them. */ const FLOWS = new Set([ "bad-address", "reaching", "blocked", "unreachable", "untrusted", "connecting", "needs-pairing", - "awaiting-approval", "pairing", "paired", "pair-refused", "forgotten", "starting", "error", + "awaiting-approval", "pairing", "paired", "pair-refused", "forgotten", "starting", "profile-locked", "error", ]); type Ready = Extract; @@ -115,6 +121,15 @@ class App { * it answers at once with an empty list, which must not read as still loading. */ private libraryAt = 0; private libraryError: string | undefined; + /** The profile id the titles were last asked as; unset is the box's. A pick that moved since + * is read again. */ + private libraryAsked: string | undefined; + /** The profile the shelf was read as, when this device may hide titles for it. */ + private hideFor: { id: string; name: string } | null = null; + /** What that profile hides, while its sheet is open. Read on opening, never kept. */ + private hidden: { name: string; entries?: LibraryEntry[]; failed?: boolean } | null = null; + /** Where each title hidden this visit sat on the shelf, so Undo puts it back there. */ + private readonly hidAt = new Map(); private tools: HostTools | null = null; private running: string | undefined; /** The running title's library id, which is what `Resume` launches. */ @@ -216,6 +231,9 @@ class App { back: () => (this.gate ? this.cancelGate() : engine.disconnect()), play: (entry, profile) => this.play(entry, undefined, profile), pickProfile: (id) => this.pickProfile(id), + unlock: (secret, stay) => this.unlock(secret, stay), + setHidden: (entry, hidden, as) => this.setHidden(entry, hidden, as), + openHidden: (on) => void this.openHidden(on), switchProfile: (origin) => this.switchProfile(origin), forget: (origin) => this.forget(origin), followLink: (yes) => this.followLink(yes), @@ -424,14 +442,26 @@ class App { // The console has no tabs: a host it reaches is a library it shows. if (this.web && this.tab === "hosts") return this.home(); this.setShelf(s.origin); - if (this.libraryFor !== s.origin || (!this.libraryLoading && Date.now() - this.libraryAt > LIBRARY_TTL_MS)) { + const moved = this.libraryAsked !== this.pickFor(s.origin)?.id; + if (this.libraryFor !== s.origin || (!this.libraryLoading && (moved || Date.now() - this.libraryAt > LIBRARY_TTL_MS))) { void this.openLibrary(s); } this.watchRunning(s); return this.showLibrary(); } case "starting": + if (s.opening) return this.show({ kind: "connecting", origin: s.origin, phase: "opening", host: this.nameOf(s.origin) }); return this.show({ kind: "connecting", origin: s.origin, phase: "starting" }); + case "profile-locked": { + const dial = this.lastPlay; + // The console prompts by itself: it hears the host's sentence as its session's end. + if (!this.web) { + return this.show({ kind: "unlock", origin: s.origin, host: this.nameOf(s.origin), name: "", form: "password", ...(s.said ? { error: s.said } : {}) }); + } + // Not from inside this listener: the prompt puts the engine back on `ready`. + queueMicrotask(() => void this.reprompt(s.origin, s.host, dial, s.said)); + return; + } case "streaming": { const live = pageShortcuts(this.prefs.shortcuts); const menuHint = this.menuOpen ? menuHintText(live) : undefined; @@ -802,11 +832,21 @@ class App { if (this.libraryFor !== s.origin) this.clearLibrary(); this.libraryFor = s.origin; this.libraryLoading = true; + const pick = this.pickFor(s.origin); + this.libraryAsked = pick?.id; this.redrawLibrary(); try { - const entries = [...(await s.host.library())]; + // The box's list says whether this device may hide titles for the pick. No pick, no ask. + const [catalog, listed] = await Promise.all([ + s.host.library(pick?.id), + pick ? s.host.profiles().catch(() => null) : null, + ]); if (this.libraryFor !== s.origin) return; - this.entries = entries; + this.entries = [...catalog.entries]; + const person = hideOffer(listed, catalog.as); + this.hideFor = person ? { id: person.id, name: person.display_name } : null; + if (!this.hideFor) this.hidden = null; + this.hidAt.clear(); this.libraryError = undefined; this.libraryAt = Date.now(); } catch (e) { @@ -828,19 +868,91 @@ class App { } this.redrawLibrary(); // Art after the grid, per entry: the grid should appear before its covers do. - for (const entry of this.entries) { - const art = entry.art.portrait ?? entry.art.header; - if (!art || this.art.has(entry.id)) continue; - void s.host - .art(art) - .then((url) => { - if (!url || this.libraryFor !== s.origin) return; - this.art.set(entry.id, url); - this.redrawLibrary(); - }) - // A cover that cannot load leaves its tile's placeholder. - .catch(() => {}); + for (const entry of this.entries) this.readArt(s.host, s.origin, entry); + } + + /** Read `entry`'s cover for the shelf of `origin`, unless it is there already. */ + private readArt(host: Host, origin: string, entry: LibraryEntry): void { + const art = entry.art?.portrait ?? entry.art?.header; + if (!art || this.art.has(entry.id)) return; + void host + .art(art) + .then((url) => { + if (!url || this.libraryFor !== origin) return; + this.art.set(entry.id, url); + this.redrawLibrary(); + }) + // A cover that cannot load leaves its tile's placeholder. + .catch(() => {}); + } + + /** The pick the shelf of `origin` is read as: the one this browser keeps. The console applies + * only a pick it was told to remember, as it does for a dial. */ + private pickFor(origin: string): ProfilePick | undefined { + const pick = hosts.all()[origin]?.profile; + return pick && (this.web || pick.remember) ? pick : undefined; + } + + // --- hide for me ------------------------------------------------------------------------- + /** Hide (`hidden`) or show `entry` for the shelf's profile, or for `as`. The shelf follows a + * yes at once, with no new fetch; a no changes nothing. The web shell says the line here. */ + private async setHidden(entry: LibraryEntry, hidden: boolean, as = this.hideFor ?? undefined): Promise<{ done: boolean; notice: string }> { + const host = this.shelfHost(); + const shelf = this.libraryFor; + const outcome = host && as + ? await host.setHidden(as.id, entry.id, hidden) + : ({ kind: "failed", why: m.browser_lib_not_connected_this_host() } as const); + const done = outcome.kind === "done"; + const notice = hideNotice(outcome, hidden, entry.title, as?.name ?? ""); + if (done && this.libraryFor === shelf) this.noteHidden(entry, hidden); + if (this.web) { + const undo = { label: m.common_undo(), run: () => void this.setHidden(entry, !hidden, as) }; + this.ui.notify(notice, done ? undefined : "error", done ? undo : undefined); + } + return { done, notice }; + } + + /** The shelf after `entry` left it (`hidden`) or came back. A title that comes back takes + * the place this visit saw it leave, else the end until the shelf is read again. */ + private noteHidden(entry: LibraryEntry, hidden: boolean): void { + const at = this.entries.findIndex((e) => e.id === entry.id); + const listed = this.hidden?.entries; + if (hidden) { + const [gone] = at >= 0 ? this.entries.splice(at, 1) : []; + if (gone) this.hidAt.set(entry.id, at); + if (listed && !listed.some((e) => e.id === entry.id)) listed.push(gone ?? entry); + } else { + // Only a whole row goes back on the shelf; the console names a title by its id alone. + if (at < 0 && entry.store !== undefined) { + this.entries.splice(Math.min(this.hidAt.get(entry.id) ?? this.entries.length, this.entries.length), 0, entry); + const host = this.shelfHost(); + if (host && this.libraryFor) this.readArt(host, this.libraryFor, entry); + } else if (at < 0) { + this.libraryAt = 0; + } + this.hidAt.delete(entry.id); + if (listed) this.hidden = { ...this.hidden!, entries: listed.filter((e) => e.id !== entry.id) }; } + this.redrawLibrary(); + } + + /** Open what the shelf's profile hides, read now and never kept, or close it. */ + private async openHidden(on: boolean): Promise { + const who = this.hideFor; + const host = this.shelfHost(); + if (!on || !who || !host) { + this.hidden = null; + return this.redrawLibrary(); + } + const sheet = (this.hidden = { name: who.name }); + this.redrawLibrary(); + try { + const entries = await host.hidden(who.id); + if (this.hidden === sheet) this.hidden = { name: who.name, entries }; + } catch { + if (this.hidden === sheet) this.hidden = { name: who.name, failed: true }; + } + this.redrawLibrary(); } /** What the host is running, polled while its library is connected: the event stream is not @@ -900,6 +1012,8 @@ class App { ...(mine && connected && this.running && this.runningEndable ? { endable: true } : {}), ...(mine && this.endNotice ? { notice: this.endNotice } : {}), ...(mine && this.libraryError ? { error: m.browser_lib_load_failed_desktop({ why: sentence(this.libraryError) }) } : {}), + ...(mine && connected && this.hideFor ? { hide: { name: this.hideFor.name } } : {}), + ...(mine && connected && this.hidden ? { hidden: this.hidden } : {}), }); void this.probe(shelves.map((h) => h.origin)); } @@ -1036,6 +1150,10 @@ class App { this.libraryLoading = false; this.libraryAt = 0; this.libraryError = undefined; + this.libraryAsked = undefined; + this.hideFor = null; + this.hidden = null; + this.hidAt.clear(); this.running = undefined; this.runningId = undefined; this.runningEndable = false; @@ -1106,7 +1224,8 @@ class App { this.engine.fullscreen(true); } const s = this.engine.current; - if (s.kind === "ready" && s.origin === origin) return this.start(entry, profile); + // `profile-locked`: the console's own prompt dials again from where the host left it. + if ((s.kind === "ready" || s.kind === "profile-locked") && s.origin === origin) return this.start(entry, profile); this.quiet = false; this.resumeOnReady = { ...(entry ? { entry } : {}), ...(profile !== undefined ? { profile } : {}) }; void this.engine.connect(this.targetOf(origin)); @@ -1150,11 +1269,17 @@ class App { void this.askProfile(s.origin, s.host, entry ? { entry } : {}); } - private dial(entry?: LibraryEntry, profile?: string): void { + /** `unlock` is what the prompt took, for this dial alone: `lastPlay` never holds it. */ + private dial(entry?: LibraryEntry, profile?: string, unlock?: { secret: string; stay: boolean }): void { this.gate = null; this.endNotice = undefined; this.lastPlay = { ...(entry ? { entry } : {}), ...(profile ? { profile } : {}) }; - this.engine.startStream({ ...this.streamOptions(), ...(entry ? { launch: entry } : {}), ...(profile ? { profile } : {}) }); + this.engine.startStream({ + ...this.streamOptions(), + ...(entry ? { launch: entry } : {}), + ...(profile ? { profile } : {}), + ...(unlock ? { unlock } : {}), + }); } // --- the profile gate ---------------------------------------------------------------- @@ -1223,7 +1348,7 @@ class App { private async settleSeat(gate: Gate, id: string | undefined): Promise { const row = id ? gate.rows.find((p) => p.id === id) : undefined; let next = row ? seatGate(row) : ({ kind: "dial" } as const); - if (!row || next.kind === "dial") return this.dial(gate.play?.entry, id); + if (!row || next.kind === "dial") return this.dialOrPrompt(gate, row, id); const name = row.display_name; if (next.kind === "wake") { this.gateShow(gate, { kind: "seat", origin: gate.origin, title: wakingLine(name) }); @@ -1256,10 +1381,63 @@ class App { const now = rows?.find((p) => p.id === row.id); // A profile the list dropped is the host's to refuse. next = now ? seatGate(now) : { kind: "dial" }; - if (next.kind === "dial") return this.dial(gate.play?.entry, row.id); + if (next.kind === "dial") return this.dialOrPrompt(gate, now, row.id); } } + // --- a profile's unlock -------------------------------------------------------------------- + // This page holds no unlock key, so a profile that opens with a PIN or an account password + // is asked for it before its dial, and again when the host refuses what was typed + // (`unlock.ts`). + + /** Dial as `row`, behind the prompt when it needs an unlock. A profile the list dropped + * dials as it stands, and the host answers for it. */ + private dialOrPrompt(gate: Gate, row: ListedProfile | undefined, id: string | undefined): void { + const form = row ? unlockForm(unlockNeed(row["unlock"])) : null; + if (!row || !form) return this.dial(gate.play?.entry, id); + gate.unlock = row.id; + this.gateShow(gate, { kind: "unlock", origin: gate.origin, host: this.nameOf(gate.origin), name: row.display_name, form }); + } + + /** The prompt's answer: the dial it stood in front of, with what was typed. */ + private unlock(secret: string, stay: boolean): void { + const gate = this.gate; + if (gate?.unlock) this.dial(gate.play?.entry, gate.unlock, { secret, stay }); + } + + /** + * The host closed `dial` as `profile-locked`: the prompt, with its sentence when it refused + * what was typed. The form is the profile's fresh row's, the password when the list names + * none. A dial that named no profile has nothing to prompt for, and says so. + */ + private async reprompt(origin: string, host: Host, dial: Play | null, said?: string): Promise { + let rows: ReadonlyArray | null = null; + try { + rows = await host.profiles(); + } catch { + // The prompt still opens, for the password. + } + const now = this.engine.current; + if (now.kind !== "profile-locked" || now.origin !== origin) return; + const id = dial?.profile; + const row = rows?.find((p) => p.id === id); + const gate: Gate = { + origin, + host, + play: dial?.entry ? { entry: dial.entry } : {}, + rows: rows ?? [], + screen: { kind: "error", head: m.browser_gate_failed_title(), text: sentence(said ?? m.reject_profile_locked()) }, + }; + if (id) { + const form = (row ? unlockForm(unlockNeed(row["unlock"])) : null) ?? "password"; + gate.unlock = id; + gate.screen = { kind: "unlock", origin, host: this.nameOf(origin), name: row?.display_name ?? id, form, ...(said ? { error: sentence(said) } : {}) }; + } + this.gate = gate; + // `ready` again, with the gate's screen in front of it. + this.engine.leave(); + } + private gateShow(gate: Gate, screen: Screen): void { if (this.gate !== gate) return; gate.screen = screen; @@ -1315,6 +1493,8 @@ interface Gate { play: { entry?: LibraryEntry } | null; rows: ReadonlyArray; screen: Screen; + /** The profile the unlock prompt on `screen` opens. */ + unlock?: string; } /** `p`, or a rejection once `ms` have passed. */ @@ -1446,6 +1626,8 @@ try { const engine = await Engine.create({ videoCanvas, uiCanvas, + // Both interfaces draw the unlock prompt: the web shell's sheet, the console's own screen. + promptsUnlock: true, ...(__PF_TRANSPORT_HOST__ ? { transportHost: __PF_TRANSPORT_HOST__ } : {}), }); const server = (await readConfig(serverFetch(), location.href)) ?? { listed: new Map(), viaServer: false }; diff --git a/apps/web/src/ui/console.ts b/apps/web/src/ui/console.ts index 571bbfd..4514e8a 100644 --- a/apps/web/src/ui/console.ts +++ b/apps/web/src/ui/console.ts @@ -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(); /** 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; @@ -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 { @@ -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], @@ -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; @@ -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; } @@ -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; } @@ -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; @@ -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 { + 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 { diff --git a/apps/web/src/ui/fixtures.ts b/apps/web/src/ui/fixtures.ts index 54c1fde..6cec1a3 100644 --- a/apps/web/src/ui/fixtures.ts +++ b/apps/web/src/ui/fixtures.ts @@ -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; @@ -82,6 +86,11 @@ 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", @@ -89,6 +98,10 @@ export const SCREENS = { 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 }, diff --git a/apps/web/src/ui/library.tsx b/apps/web/src/ui/library.tsx index c4f1515..0cf85df 100644 --- a/apps/web/src/ui/library.tsx +++ b/apps/web/src/ui/library.tsx @@ -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"; @@ -52,6 +52,7 @@ export function Library({ screen, actions }: { screen: LibraryScreen; actions: A return ( {screen.tools && } + {screen.hidden &&