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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions src/console/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 23 additions & 2 deletions src/services/profiles.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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<Vec<u8>, 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<T>(answer: Result<T, LibraryError>) -> Result<Option<T>, LibraryError> {
match answer {
Ok(listed) => Ok(Some(listed)),
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/services/store/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down