synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
use crate::persistence::app_state as prefs;

/// Notification sound types.
#[derive(Clone, Debug, PartialEq)]
pub enum NotificationSound {
    Default,
    Ping,
    Pop,
    Chime,
    None,
}

/// Play a notification sound based on user preferences.
pub async fn play_notification_sound() {
    let enabled = match prefs::load_preferences().await {
        Ok(p) => p.notification_sounds,
        Err(_) => true,
    };

    if !enabled {
        return;
    }

    // Use platform-specific sound APIs
    #[cfg(target_os = "windows")]
    {
        play_windows_sound();
    }

    #[cfg(target_os = "macos")]
    {
        play_macos_sound();
    }

    #[cfg(target_os = "linux")]
    {
        play_linux_sound();
    }

    #[cfg(target_family = "wasm")]
    {
        play_web_sound();
    }
}

/// Play the default notification sound on Windows.
#[cfg(target_os = "windows")]
fn play_windows_sound() {
    // Use PowerShell to play a system sound
    let _ = std::process::Command::new("powershell")
        .args([
            "-WindowStyle", "Hidden",
            "-Command",
            "[System.Media.SystemSounds]::Asterisk.Play()"
        ])
        .spawn();
}

/// Play the default notification sound on macOS.
#[cfg(target_os = "macos")]
fn play_macos_sound() {
    let _ = std::process::Command::new("afplay")
        .args(["/System/Library/Sounds/Glass.aiff"])
        .spawn();
}

/// Play the default notification sound on Linux.
#[cfg(target_os = "linux")]
fn play_linux_sound() {
    // Try paplay first (PulseAudio), then aplay (ALSA)
    let result = std::process::Command::new("paplay")
        .args(["/usr/share/sounds/freedesktop/stereo/message.oga"])
        .spawn();
    if result.is_err() {
        let _ = std::process::Command::new("aplay")
            .args(["/usr/share/sounds/freedesktop/stereo/message.oga"])
            .spawn();
    }
}

/// Play a sound on web using the Web Audio API.
#[cfg(target_family = "wasm")]
fn play_web_sound() {
    tracing::debug!("Web notification sound requested");
}