Skip to main content

wire/
os_notify.rs

1//! Cross-platform best-effort desktop notifications.
2//!
3//! Each backend shells out to the native binary (notify-send / osascript /
4//! powershell). Failures are swallowed — we'd rather lose a toast than crash
5//! the caller. Used by both `wire notify` (inbox events) and the daemon's
6//! pending-pair tick (SAS-ready, pair-confirmed).
7
8#[cfg(target_os = "linux")]
9pub fn toast(title: &str, body: &str) {
10    let _ = std::process::Command::new("notify-send")
11        .arg("--app-name=wire")
12        .arg("--icon=mail-message-new")
13        .arg(title)
14        .arg(body)
15        .output();
16}
17
18#[cfg(target_os = "macos")]
19pub fn toast(title: &str, body: &str) {
20    let safe = |s: &str| s.replace('\\', "\\\\").replace('"', "\\\"");
21    let script = format!(
22        "display notification \"{}\" with title \"{}\"",
23        safe(body),
24        safe(title),
25    );
26    let _ = std::process::Command::new("osascript")
27        .arg("-e")
28        .arg(script)
29        .output();
30}
31
32#[cfg(target_os = "windows")]
33pub fn toast(title: &str, body: &str) {
34    eprintln!("[wire notify] {title}\n  {body}");
35}
36
37#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
38pub fn toast(title: &str, body: &str) {
39    eprintln!("[wire notify] {title}\n  {body}");
40}