diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 97df3d5..9875e97 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -5071,9 +5071,9 @@ dependencies = [ [[package]] name = "ringdrop" -version = "0.14.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "659eb22bb40980a969b3ac8e4a02d6c267b18fb471fa4578bd472e8b5bc0c9bf" +checksum = "00a0bb29c197306b3ce9f79e014318710c06428bcad50b6f281b8fb62318d320" dependencies = [ "anyhow", "bao-tree", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ce3eb5f..4d246c2 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -21,5 +21,5 @@ tauri-plugin-dialog = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" dirs = "5" -ringdrop = "0.14.1" +ringdrop = "0.16.0" diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index dc1bcbd..5a721c8 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -35,6 +35,15 @@ pub struct BlobRow { pub rings: Vec, /// `rdrop://…` share ticket. pub ticket: String, + /// Human-readable kind string, e.g. `"file"` or `"dir, 3 files"`. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Number of files in a directory blob (`HashSeq`), if known. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub file_count: Option, + /// Total size in bytes, if known. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub size_bytes: Option, } /// Result returned after a successful import. @@ -86,6 +95,15 @@ pub struct RemoteBlobRow { pub name: String, /// `rdrop://…` share ticket. pub ticket: String, + /// Human-readable kind string, e.g. `"file"` or `"dir, 3 files"`. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub kind: Option, + /// Number of files in a directory blob, if known. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub file_count: Option, + /// Total size in bytes, if known. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub size_bytes: Option, } /// GUI and daemon version numbers, baked in at compile time. @@ -403,6 +421,24 @@ pub async fn receive( serde_json::json!({ "done": done, "total": total }), ); } + EventKind::FileProgress { + file_index, + file_total, + ref file_name, + done, + total, + } => { + let _ = app.emit( + &format!("transfer_progress/{hash}"), + serde_json::json!({ + "done": done, + "total": total, + "file_index": file_index, + "file_total": file_total, + "file_name": file_name, + }), + ); + } // DaemonClient::send delivers Error through the callback and // still returns Ok(()), so we must capture it manually. EventKind::Error { message } => recv_error = Some(message), @@ -436,6 +472,36 @@ mod tests { "hash": "abc", "name": "f.txt", "rings": ["x"], "ticket": "rdrop://t" }))]); assert_eq!(rows[0].rings, vec!["x"]); + assert_eq!(rows[0].kind, None); + assert_eq!(rows[0].size_bytes, None); + } + + #[test] + fn collect_records_deserializes_blob_rows_with_rich_fields() { + let rows: Vec = collect_records(vec![rec(json!({ + "hash": "abc", + "name": "photos", + "rings": [], + "ticket": "rdrop://t", + "kind": "dir, 3 files", + "file_count": 3, + "size_bytes": 1048576, + }))]); + assert_eq!(rows[0].kind.as_deref(), Some("dir, 3 files")); + assert_eq!(rows[0].file_count, Some(3)); + assert_eq!(rows[0].size_bytes, Some(1048576)); + } + + #[test] + fn collect_records_ignores_file_progress_events() { + let rows: Vec = collect_records(vec![EventKind::FileProgress { + file_index: 1, + file_total: 3, + file_name: "readme.txt".into(), + done: 512, + total: 1024, + }]); + assert!(rows.is_empty()); } #[test] @@ -500,6 +566,23 @@ mod tests { "hash": "abc", "name": "video.mp4", "ticket": "rdrop://abc" }))]); assert_eq!(rows[0].name, "video.mp4"); + assert_eq!(rows[0].kind, None); + assert_eq!(rows[0].size_bytes, None); + } + + #[test] + fn collect_records_deserializes_remote_blob_rows_with_rich_fields() { + let rows: Vec = collect_records(vec![rec(json!({ + "hash": "abc", + "name": "photos", + "ticket": "rdrop://abc", + "kind": "dir, 5 files", + "file_count": 5, + "size_bytes": 2097152, + }))]); + assert_eq!(rows[0].kind.as_deref(), Some("dir, 5 files")); + assert_eq!(rows[0].file_count, Some(5)); + assert_eq!(rows[0].size_bytes, Some(2097152)); } #[test] diff --git a/src/lib/BlobTable.svelte b/src/lib/BlobTable.svelte index c9294c6..5f4e1df 100644 --- a/src/lib/BlobTable.svelte +++ b/src/lib/BlobTable.svelte @@ -1,6 +1,7 @@