Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
PC files on the phone: list them again
Beeffad687628e7
diff --git a/core/nectarlink-core/src/storage.rs b/core/nectarlink-core/src/storage.rsindex 40f9dcc..9eff6ef 100644--- a/core/nectarlink-core/src/storage.rs+++ b/core/nectarlink-core/src/storage.rs@@ -150,10 +150,13 @@ fn we_offer(shared: &Shared, cap: &str) -> bool {shared.local_capabilities().iter().any(|c| c == cap)}-/// Checks if the client user explicitly turned `storage` (or `remote_files` when on Relay) off for `peer`.+/// Checks if the client user explicitly turned `storage` (a PC browsing a+/// phone) or `remote_files` (over Relay) off for `peer`.fn pc_allows(shared: &Shared, peer: &DeviceId) -> Result<bool> {let toggles = shared.store.toggles(peer)?;- if toggles.get(TOGGLE).copied() == Some(false) {+ // A PC's `storage` toggle is "browse that phone here"; a phone's is "let+ // that PC browse me", which says nothing about browsing the PC.+ if !serves_phone_storage(shared) && toggles.get(TOGGLE).copied() == Some(false) {return Ok(false);}if shared.session(peer).is_some_and(|s| s.path() == crate::ConnectionPath::Relay)@@ -172,7 +175,11 @@ fn check_phone_allowed(if !we_offer(shared, cap) {return Err((ErrorCode::Unsupported, format!("{cap} is not offered by this device")));}- if !shared.toggle_on(peer, TOGGLE) {+ // The `storage` toggle is a phone's "let this PC browse my storage". On a+ // PC the same toggle means the opposite way (browse that phone here), so+ // it doesn't gate the PC's own folders: the app's "share this PC's+ // folders" setting does (`Platform::storage_list` and friends refuse).+ if serves_phone_storage(shared) && !shared.toggle_on(peer, TOGGLE) {let first_time = shared.storage.lock().unwrap_or_else(|e| e.into_inner()).mark_prompted(*peer);if first_time {shared.emit(NodeEvent::StorageRequested { device: *peer });@@ -190,6 +197,14 @@ fn check_phone_allowed(Ok(())}+/// Whether this device is a phone or tablet, sharing its own storage.+fn serves_phone_storage(shared: &Shared) -> bool {+ matches!(+ shared.local.read().unwrap_or_else(|e| e.into_inner()).device.kind,+ nectarlink_protocol::messages::DeviceKind::Phone | nectarlink_protocol::messages::DeviceKind::Tablet+ )+}+fn parent_dir_of(path: &str) -> &str {match path.rfind('/') {Some(idx) => &path[..idx],diff --git a/core/nectarlink-core/tests/two_devices.rs b/core/nectarlink-core/tests/two_devices.rsindex 0a6815a..7f06e5e 100644--- a/core/nectarlink-core/tests/two_devices.rs+++ b/core/nectarlink-core/tests/two_devices.rs@@ -3044,6 +3044,42 @@ async fn deck_layout_and_state_arrive_press_runs_action_and_respects_toggles_andassert!(matches!(phone.node.deck_press(pc_id, "run_build".into()).await, Err(Error::NotFound)));}+/// A phone browses a PC's shared folders: the toggles named `storage` (on+/// the PC: browse that phone; on the phone: let that PC browse it) don't+/// stand in the way, whichever way they are set.+#[tokio::test(flavor = "multi_thread")]+async fn a_phone_browses_a_pcs_shared_folders() {+ use nectarlink_core::{FolderStorage, STORAGE_MOUNT, STORAGE_READ, STORAGE_WRITE};++ let mut pc = device_with("Desktop", DeviceKind::Desktop, &[STORAGE_MOUNT, STORAGE_READ]).await;+ let mut phone = device_with("Pixel", DeviceKind::Phone, &[STORAGE_READ, STORAGE_WRITE]).await;+ let shared = tempfile::tempdir().unwrap();+ std::fs::create_dir_all(shared.path().join("Downloads")).unwrap();+ std::fs::write(shared.path().join("Downloads/report.pdf"), b"pdf").unwrap();+ *pc.platform.storage.lock().unwrap() = Some(FolderStorage::new(shared.path()));++ pair_qr(&mut pc, &mut phone).await;+ let (pc_id, phone_id) = (pc.node.device_id(), phone.node.device_id());++ for (pc_toggle, phone_toggle) in [(None, None), (Some(false), Some(false)), (Some(true), Some(true))] {+ if let Some(on) = pc_toggle {+ pc.node.set_device_toggle(phone_id, "storage", on).unwrap();+ }+ if let Some(on) = phone_toggle {+ phone.node.set_device_toggle(pc_id, "storage", on).unwrap();+ }+ let root = with_timeout("list the PC", phone.node.storage_list(pc_id, "")).await.unwrap();+ assert_eq!(root.iter().map(|e| e.name.as_str()).collect::<Vec<_>>(), ["Downloads"], "{pc_toggle:?}");+ let files =+ with_timeout("list Downloads", phone.node.storage_list(pc_id, "Downloads")).await.unwrap();+ assert_eq!(files.iter().map(|e| e.name.as_str()).collect::<Vec<_>>(), ["report.pdf"]);+ }++ // A PC that doesn't share its folders says no.+ *pc.platform.storage.lock().unwrap() = None;+ assert!(phone.node.storage_list(pc_id, "").await.is_err());+}+#[tokio::test(flavor = "multi_thread")]async fn phone_storage_lists_reads_ranges_writes_resumes_mutates_and_enforces_security() {use nectarlink_core::{FolderStorage, STORAGE_MOUNT, STORAGE_READ, STORAGE_WRITE};