diff --git a/Cargo.lock b/Cargo.lock index aaf3e8b1..e32c7763 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,7 +378,7 @@ dependencies = [ [[package]] name = "cros-codecs" version = "0.0.5" -source = "git+https://git.unom.io/unom/punktfunk?rev=ec15a3774b68bd8bac049f9914e79647bc124d77#ec15a3774b68bd8bac049f9914e79647bc124d77" +source = "git+https://git.unom.io/unom/punktfunk?rev=dd871ad7e22f02131efee64ef53225e5d3e48490#dd871ad7e22f02131efee64ef53225e5d3e48490" dependencies = [ "log", "memchr", @@ -582,7 +582,7 @@ dependencies = [ [[package]] name = "fec-rs" version = "0.1.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=ec15a3774b68bd8bac049f9914e79647bc124d77#ec15a3774b68bd8bac049f9914e79647bc124d77" +source = "git+https://git.unom.io/unom/punktfunk?rev=dd871ad7e22f02131efee64ef53225e5d3e48490#dd871ad7e22f02131efee64ef53225e5d3e48490" [[package]] name = "fiat-crypto" @@ -1128,7 +1128,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pf-client-core" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=ec15a3774b68bd8bac049f9914e79647bc124d77#ec15a3774b68bd8bac049f9914e79647bc124d77" +source = "git+https://git.unom.io/unom/punktfunk?rev=dd871ad7e22f02131efee64ef53225e5d3e48490#dd871ad7e22f02131efee64ef53225e5d3e48490" dependencies = [ "anyhow", "cfg_aliases", @@ -1143,7 +1143,7 @@ dependencies = [ [[package]] name = "pf-console-ui" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=ec15a3774b68bd8bac049f9914e79647bc124d77#ec15a3774b68bd8bac049f9914e79647bc124d77" +source = "git+https://git.unom.io/unom/punktfunk?rev=dd871ad7e22f02131efee64ef53225e5d3e48490#dd871ad7e22f02131efee64ef53225e5d3e48490" dependencies = [ "anyhow", "pf-client-core", @@ -1235,7 +1235,7 @@ dependencies = [ [[package]] name = "punktfunk-core" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=ec15a3774b68bd8bac049f9914e79647bc124d77#ec15a3774b68bd8bac049f9914e79647bc124d77" +source = "git+https://git.unom.io/unom/punktfunk?rev=dd871ad7e22f02131efee64ef53225e5d3e48490#dd871ad7e22f02131efee64ef53225e5d3e48490" dependencies = [ "aes-gcm", "aws-lc-rs", diff --git a/Cargo.toml b/Cargo.toml index ccb99d72..d773cf1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,12 +48,12 @@ rustls = { version = "0.23", features = ["aws_lc_rs"] } image = { version = "0.25", default-features = false, features = ["png", "jpeg"] } # Same revision for shared types. -punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "ec15a3774b68bd8bac049f9914e79647bc124d77", features = ["quic", "chacha-aws-lc-rs"] } -pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "ec15a3774b68bd8bac049f9914e79647bc124d77", default-features = false } +punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "dd871ad7e22f02131efee64ef53225e5d3e48490", features = ["quic", "chacha-aws-lc-rs"] } +pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "dd871ad7e22f02131efee64ef53225e5d3e48490", default-features = false } [target.'cfg(target_os = "linux")'.dependencies] -cros-codecs = { git = "https://git.unom.io/unom/punktfunk", rev = "ec15a3774b68bd8bac049f9914e79647bc124d77" } -pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "ec15a3774b68bd8bac049f9914e79647bc124d77", default-features = false, features = ["gl"] } +cros-codecs = { git = "https://git.unom.io/unom/punktfunk", rev = "dd871ad7e22f02131efee64ef53225e5d3e48490" } +pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "dd871ad7e22f02131efee64ef53225e5d3e48490", default-features = false, features = ["gl"] } sdl3 = { version = "0.20", default-features = false } # Disable pkg-config: buildroot mangles the SDL prefix outside its sysroot. # build.rs supplies SDL3_PREFIX for direct linking. diff --git a/src/console/model.rs b/src/console/model.rs index eb9b6593..b003597a 100644 --- a/src/console/model.rs +++ b/src/console/model.rs @@ -407,6 +407,12 @@ impl Service { // Presentation only: which profiles ride as cards behind the host's tile. ConsoleCmd::SetPin { key, preset_id, pin } => self.set_pin(&key, preset_id, pin), ConsoleCmd::FetchProfiles { addr, mgmt, fp_hex } => self.fetch_profiles(addr, mgmt, fp_hex), + ConsoleCmd::FetchAvatar { + addr, + mgmt, + fp_hex, + url, + } => self.fetch_avatar(addr, mgmt, &fp_hex, url), ConsoleCmd::WakeProfile { addr, mgmt, fp_hex, id } => self.wake_profile(addr, mgmt, &fp_hex, id), ConsoleCmd::SetProfile { key, profile } => self.set_profile(&key, profile), // Nothing to do here, each for its own reason: @@ -495,6 +501,25 @@ impl Service { .ok(); } + /// A profile's picture for the faces the shell draws. A read that fails leaves the initials. + fn fetch_avatar(&self, addr: String, mgmt: u16, fp_hex: &str, url: String) { + // The shell asks paired hosts only. Unpinned, this TV's certificate goes to anyone. + let Some(pin) = shared::parse_fp(fp_hex) else { + return; + }; + let console = self.handles.console.clone(); + let identity = self.identity.clone(); + std::thread::Builder::new() + .name("punktfunk-webos-console-avatar".into()) + .spawn( + move || match profiles::fetch_picture(&addr, mgmt, &identity, pin, &url) { + Ok(bytes) => console.set_avatar(&url, bytes), + Err(e) => tracing::debug!("console: picture {url}: {e}"), + }, + ) + .ok(); + } + /// Start a profile's stopped seat. No answer: the shell polls the list until it is up. fn wake_profile(&self, addr: String, mgmt: u16, fp_hex: &str, id: String) { let Some(pin) = shared::parse_fp(fp_hex) else { diff --git a/src/services/profiles.rs b/src/services/profiles.rs index e1778d8c..821d2a60 100644 --- a/src/services/profiles.rs +++ b/src/services/profiles.rs @@ -1,12 +1,12 @@ //! A host's profiles over the management API, on the pinned mTLS lane `library` uses: -//! `GET /api/v1/profiles/enumerate` for the console's picker, and `POST +//! `GET /api/v1/profiles/enumerate` for the console's picker, a row's picture, and `POST //! /api/v1/profiles/{id}/wake` to start a stopped seat. The rules for using the list live in //! `pf_client_core::profiles`, shared with every other client. use pf_client_core::profiles::ListedProfile; use crate::services::budget; -use crate::services::library::{agent, base_url, classify, get_json, LibraryError}; +use crate::services::library::{agent, base_url, classify, fetch_art, get_json, LibraryError}; /// The profiles on the box. `Ok(None)`: it has none, or predates the route (404). pub fn fetch( @@ -19,6 +19,20 @@ pub fn fetch( none_on_404(get_json(addr, mgmt_port, identity, Some(pin), path, budget::REQUEST)) } +/// The picture at `path`, a row's `avatar`. Only a path: a row never sends this TV elsewhere. +pub fn fetch_picture( + addr: &str, + mgmt_port: u16, + identity: &(String, String), + pin: [u8; 32], + path: &str, +) -> Result, LibraryError> { + if !path.starts_with('/') { + return Err(LibraryError::BadReply(format!("picture {path:?} is not host-relative"))); + } + fetch_art(&agent(identity, Some(pin))?, addr, mgmt_port, path) +} + fn none_on_404(answer: Result) -> Result, LibraryError> { match answer { Ok(listed) => Ok(Some(listed)), @@ -48,6 +62,13 @@ pub fn wake( mod tests { use super::*; + #[test] + fn a_picture_must_be_a_path_on_the_host() { + let id = (String::new(), String::new()); + let read = fetch_picture("10.0.0.2", 47990, &id, [0; 32], "https://elsewhere.example/x.png"); + assert!(matches!(read, Err(LibraryError::BadReply(_)))); + } + /// Only a 404 means "no profiles": any other failure is the host not answering the ask. #[test] fn only_a_404_reads_as_no_profiles() { diff --git a/src/services/store/shared.rs b/src/services/store/shared.rs index 6dbfd74a..62f1a119 100644 --- a/src/services/store/shared.rs +++ b/src/services/store/shared.rs @@ -366,6 +366,7 @@ mod launch_tests { id: "kid".into(), display_name: "Kid".into(), remember: true, + ..Default::default() }); assert!(set_profile(&mut state, &format!("{key}\0p1"), pick.clone())); assert!(!set_profile(&mut state, &key, pick.clone()), "a repeat is a no-op");