Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
feat(desktop): call or text a copied number from the command palette (#83)
Bee433e746ba56c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a5518d0..c636672 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,10 @@ change things that need a step from you, and its notes say so.from the PC turns the phone's screen on if it's off, so the phone can stayin a pocket; a locked phone shows its lock screen in the window([#82](https://github.com/thtbee/nectarlink/issues/82)).+- **Call or text a copied number from the command palette.** Copy a phone+ number anywhere, open the palette with its shortcut, and Call and Text+ for that number are at the top+ ([#83](https://github.com/thtbee/nectarlink/issues/83)).- **The PC app on Linux**, for Ubuntu 24.04 or newer, Debian 13, Fedora 40or newer and other distributions from 2024 on, as a `.deb`, an `.rpm`,an AppImage or a tarball. It does what the Windows app does: notifications withdiff --git a/desktop/app/i18n/nectarlink_de.ts b/desktop/app/i18n/nectarlink_de.tsindex 47ae81b..4a93fd8 100644--- a/desktop/app/i18n/nectarlink_de.ts+++ b/desktop/app/i18n/nectarlink_de.ts@@ -893,6 +893,11 @@<source>Copied image</source><translation>Kopiertes Bild</translation></message>+ <message>+ <location filename="rust_strings.h" line="72"/>+ <source>Copied number</source>+ <translation>Kopierte Nummer</translation>+ </message><message><location filename="rust_strings.h" line="73"/><source>Copy: %1</source>diff --git a/desktop/app/i18n/nectarlink_zh_CN.ts b/desktop/app/i18n/nectarlink_zh_CN.tsindex 6c3ca86..2d02fd6 100644--- a/desktop/app/i18n/nectarlink_zh_CN.ts+++ b/desktop/app/i18n/nectarlink_zh_CN.ts@@ -893,6 +893,11 @@<source>Copied image</source><translation>已复制的图片</translation></message>+ <message>+ <location filename="rust_strings.h" line="72"/>+ <source>Copied number</source>+ <translation>已复制的号码</translation>+ </message><message><location filename="rust_strings.h" line="73"/><source>Copy: %1</source>diff --git a/desktop/app/i18n/rust_strings.h b/desktop/app/i18n/rust_strings.hindex cc90932..4bcc8d9 100644--- a/desktop/app/i18n/rust_strings.h+++ b/desktop/app/i18n/rust_strings.h@@ -69,6 +69,7 @@ static const char *const nectarlink_rust_strings[] = {QT_TRANSLATE_NOOP("CommandPalette", "Connection Doctor"), // desktop/app/src/command_palette.rsQT_TRANSLATE_NOOP("CommandPalette", "Continue copied video on phone"), // desktop/app/src/command_palette.rsQT_TRANSLATE_NOOP("CommandPalette", "Copied image"), // desktop/app/src/command_palette.rs+ QT_TRANSLATE_NOOP("CommandPalette", "Copied number"), // desktop/app/src/command_palette.rsQT_TRANSLATE_NOOP("CommandPalette", "Copy: %1"), // desktop/app/src/command_palette.rsQT_TRANSLATE_NOOP("CommandPalette", "Diagnose and fix firewall, discovery, or network issues"), // desktop/app/src/command_palette.rsQT_TRANSLATE_NOOP("CommandPalette", "Features guide"), // desktop/app/src/command_palette.rsdiff --git a/desktop/app/i18n/template/nectarlink.ts b/desktop/app/i18n/template/nectarlink.tsindex 40d973e..2b0c2dc 100644--- a/desktop/app/i18n/template/nectarlink.ts+++ b/desktop/app/i18n/template/nectarlink.ts@@ -893,6 +893,11 @@<source>Copied image</source><translation type="unfinished"></translation></message>+ <message>+ <location filename="../rust_strings.h" line="72"/>+ <source>Copied number</source>+ <translation type="unfinished"></translation>+ </message><message><location filename="../rust_strings.h" line="73"/><source>Copy: %1</source>diff --git a/desktop/app/src/command_palette.rs b/desktop/app/src/command_palette.rsindex f1af241..612675d 100644--- a/desktop/app/src/command_palette.rs+++ b/desktop/app/src/command_palette.rs@@ -1143,9 +1143,61 @@ fn build_candidates() -> Vec<PaletteCandidate> {}}+ let clip = match crate::win::clipboard::read() {+ crate::win::clipboard::Clip::Text { text, .. } => text,+ _ => String::new(),+ };+ let from_clipboard = clipboard_number_candidates(&out, &clip);+ out.extend(from_clipboard);out}+/// "Call" and "Text" for a phone number on the clipboard, at the top of the+/// list: copy a number anywhere, open the palette with its shortcut, press+/// Enter (#83). Nothing when the clipboard holds no number or no phone is paired.+fn clipboard_number_candidates(candidates: &[PaletteCandidate], clip: &str) -> Vec<PaletteCandidate> {+ let Some(number) = nectarlink_core::classify_clip(clip)+ .filter(|s| s.kind == nectarlink_core::ClipKind::PhoneNumber)+ .map(|s| s.target)+ else {+ return Vec::new();+ };+ let Some(dev_id) = candidates.iter().find_map(|c| {+ c.id.strip_prefix("action:send_clipboard:")+ .or_else(|| c.id.strip_prefix("action:ring:"))+ .map(str::to_owned)+ }) else {+ return Vec::new();+ };+ vec![+ PaletteCandidate {+ id: format!("call_contact:{dev_id}:{number}"),+ title: tr!("CommandPalette", "Call %1", number),+ subtitle: tr!("CommandPalette", "Copied number"),+ category: "Calls".into(),+ icon: "call".into(),+ badge: "Dial".into(),+ shortcut: String::new(),+ keywords: "clipboard copied".into(),+ base_boost: CLIPBOARD_BOOST,+ },+ PaletteCandidate {+ id: format!("text_contact:{dev_id}:{number}\t{number}"),+ title: tr!("CommandPalette", "Text %1", number),+ subtitle: tr!("CommandPalette", "Copied number"),+ category: "Messages".into(),+ icon: "messages".into(),+ badge: "New".into(),+ shortcut: String::new(),+ keywords: "clipboard copied".into(),+ base_boost: CLIPBOARD_BOOST - 1,+ },+ ]+}++/// Above every other item (the highest otherwise is 100).+const CLIPBOARD_BOOST: i64 = 150;+/// Filters and ranks `candidates` against `query` using fast fuzzy matching,/// synthesizing direct `"Text <query>"` / `"Call <query>"` actions when the/// user types an explicit prefix like `text ...` or `call ...`.@@ -1514,6 +1566,24 @@ mod tests {assert!(call_res[0].id.starts_with("call_contact:"));}+ #[test]+ fn a_copied_number_is_offered_first() {+ let mut candidates = sample_candidates();+ let copied = clipboard_number_candidates(&candidates, "+1 (415) 555-0199");+ assert_eq!(copied.len(), 2);+ candidates.extend(copied);+ let first = filter_and_rank(&candidates, "");+ assert!(+ first[0].id.starts_with("call_contact:") && first[0].title.contains("4155550199"),+ "{}",+ first[0].title+ );+ assert!(first[1].id.starts_with("text_contact:"));++ assert!(clipboard_number_candidates(&sample_candidates(), "just some text").is_empty());+ assert!(clipboard_number_candidates(&[], "+1 (415) 555-0199").is_empty(), "no phone to call from");+ }+#[test]fn search_across_500_candidates_completes_well_under_20ms() {let mut candidates = sample_candidates();