Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

fix(desktop): a task notification goes to the phone it names, not every match

Beebd841e610db1
diff --git a/desktop/app/src/send_to.rs b/desktop/app/src/send_to.rs
index da1e7bc..96e92e5 100644
--- a/desktop/app/src/send_to.rs
+++ b/desktop/app/src/send_to.rs
@@ -310,9 +310,25 @@ fn task_notify(device: Option<String>, task: nectarlink_core::TaskNotify) {
Some(q) => {
let Ok(devices) = node.paired_devices() else { return };
let lower = q.to_lowercase();
- for d in devices.into_iter().filter(|d| {
- d.id.to_string().starts_with(&lower) || d.info.name.to_lowercase().contains(&lower)
- }) {
+ // The phone it names: its whole name or its id. Part of a
+ // name counts only when it fits one phone, never every
+ // phone whose name holds it.
+ let exact: Vec<_> = devices
+ .iter()
+ .filter(|d| d.id.to_string().starts_with(&lower) || d.info.name.to_lowercase() == lower)
+ .cloned()
+ .collect();
+ let partial: Vec<_> =
+ devices.into_iter().filter(|d| d.info.name.to_lowercase().contains(&lower)).collect();
+ let targets = if !exact.is_empty() {
+ exact
+ } else if partial.len() == 1 {
+ partial
+ } else {
+ tracing::warn!(matches = partial.len(), "task.notify names no single phone");
+ Vec::new()
+ };
+ for d in targets {
if let Err(e) = node.task_notify(Some(d.id), task.clone()).await {
tracing::debug!(device = %d.id, error = %e, "task.notify wasn't delivered");
}