Skip to content
Merged
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
20 changes: 20 additions & 0 deletions crates/pf-ps5-app/src/ui/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ impl Service {
// ---- the host list -----------------------------------------------------------------

fn save_host(&mut self, name: String, addr: String, port: u16) {
let (addr, port) = typed(addr, port);
self.store.edit(|state| {
// Keyed by address, not fingerprint: a hand-typed host has none yet, so an
// fp-keyed upsert would collide every one of them onto the same record.
Expand All @@ -793,6 +794,7 @@ impl Service {
}

fn update_host(&mut self, key: &str, name: String, addr: String, port: u16) {
let (addr, port) = typed(addr, port);
let edited = self.store.edit(|state| {
let Some(i) = shared::find_known(&state.known_hosts, key) else {
return false;
Expand Down Expand Up @@ -1351,3 +1353,21 @@ fn to_model(games: &[GameEntry]) -> Vec<LibraryGame> {
})
.collect()
}

/// A form's address as the store keeps it: bare, a pasted port in place of the field's.
fn typed(addr: String, port: u16) -> (String, u16) {
let edit = pf_client_core::trust::HostEdit::typed(String::new(), addr, port);
(edit.addr.unwrap_or_default(), edit.port.unwrap_or(port))
}

#[cfg(test)]
mod tests {
/// `base_url` brackets a bare IPv6 itself, and a pasted port is the one to dial.
#[test]
fn a_typed_address_is_stored_bare() {
let typed = |addr: &str| super::typed(addr.into(), 9777);
assert_eq!(typed(" desk.lan:9800 "), ("desk.lan".into(), 9800));
assert_eq!(typed("[fd00::1]"), ("fd00::1".into(), 9777));
assert_eq!(typed("192.168.1.20"), ("192.168.1.20".into(), 9777));
}
}
Loading