robin/utils/
notifications.rs

1use std::process::Command;
2use anyhow::Result;
3use notify_rust::Notification;
4
5pub fn send_notification(title: &str, message: &str, success: bool) -> Result<()> {
6    if cfg!(target_os = "windows") {
7        let icon = if success { "✅" } else { "❌" };
8        let script = format!(
9            "New-BurntToastNotification -Text '{}', '{} {}' -Silent",
10            title, icon, message
11        );
12        Command::new("powershell")
13            .arg("-Command")
14            .arg(script)
15            .output()?;
16    } else {
17        // Use notify-rust for Unix-like systems (Linux and macOS)
18        let mut notification = Notification::new();
19        
20        notification
21            .summary(title)
22            .body(&format!("{} {}", if success { "✅" } else { "❌" }, message))
23            .timeout(5000); // 5 seconds
24
25        // Set appropriate icon based on the platform
26        if cfg!(target_os = "macos") {
27            notification.sound_name("default");
28        } else {
29            notification.icon(if success { "dialog-ok" } else { "dialog-error" });
30        }
31
32        notification.show()?;
33    }
34    Ok(())
35}