Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
LocalSend: don't crash when it's turned on
Beea8b90971ce93
diff --git a/core/nectarlink-core/src/localsend.rs b/core/nectarlink-core/src/localsend.rsindex 24e26f8..1f97305 100644--- a/core/nectarlink-core/src/localsend.rs+++ b/core/nectarlink-core/src/localsend.rs@@ -396,6 +396,8 @@ impl LocalSendState {if !self.enabled() {return;}+ // Called from apps' UI threads too, outside the runtime.+ let _runtime = shared.runtime.enter();if let Some(running) = self.running.lock().unwrap_or_else(|e| e.into_inner()).as_ref() {let _ = running.announce_tx.send(());}@@ -412,6 +414,9 @@ impl LocalSendState {}pub fn start(&self, shared: &Arc<Shared>) {+ // Called from apps' UI threads too (turning LocalSend on), outside the+ // runtime: its servers and announcer run on the node's.+ let _runtime = shared.runtime.enter();let mut guard = self.running.lock().unwrap_or_else(|e| e.into_inner());if guard.is_some() {return;diff --git a/core/nectarlink-core/tests/two_devices.rs b/core/nectarlink-core/tests/two_devices.rsindex 03019f6..0a6815a 100644--- a/core/nectarlink-core/tests/two_devices.rs+++ b/core/nectarlink-core/tests/two_devices.rs@@ -4326,6 +4326,34 @@ async fn localsend_is_off_by_default_and_persists_setting() {dev2.node.shutdown().await;}+/// Apps turn LocalSend on from their UI thread, outside the node's runtime.+#[tokio::test(flavor = "multi_thread")]+async fn localsend_turns_on_from_a_thread_outside_the_runtime() {+ let dir = tempfile::tempdir().unwrap();+ let mut dev = start_localsend_in(dir, "PC", DeviceKind::Desktop, free_tcp_port()).await;+ let node = dev.node.clone();+ std::thread::spawn(move || {+ node.set_localsend_enabled(true).unwrap();+ node.refresh_localsend();+ })+ .join()+ .expect("turning LocalSend on outside the runtime doesn't panic");+ for _ in 0..40 {+ if dev.node.localsend_receiving() {+ break;+ }+ tokio::time::sleep(Duration::from_millis(50)).await;+ }+ assert!(dev.node.localsend_receiving());+ dev.node.set_localsend_enabled(false).unwrap();+ wait_for(&mut dev, "localsend changed event", |e| match e {+ NodeEvent::LocalSendChanged => Some(()),+ _ => None,+ })+ .await;+ dev.node.shutdown().await;+}+#[tokio::test]async fn localsend_coexists_when_port_is_already_bound() {let occupied = std::net::TcpListener::bind(("0.0.0.0", 0)).expect("bind occupied port");