Fase 2: Add Tauri commands for audio backend system
COMMANDS CREATED (audio_backends.rs): - get_available_backends() → List backends with availability status - get_devices_for_backend(type) → Enumerate devices for selected backend - get_alsa_plugins() → List ALSA plugin options (hw/plughw/pcm) INTEGRATION: - Registered commands in commands/mod.rs - Added to invoke_handler in lib.rs - All commands return pretty names for UI display VERIFIED: - cargo check passes successfully - Ready for Phase 3 (settings persistence)
This commit is contained in:
1 parent
513a7f9ba9
commit
67ff0cab5a
3 files changed
+108
No files matched your search
@@ -0,0 +1,102 @@
|
||||
//! Tauri commands for audio backend management
|
||||
|
||||
use crate::audio::{AlsaPlugin, AudioBackendType, AudioDevice, BackendManager};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Backend information for UI display
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BackendInfo {
|
||||
pub backend_type: AudioBackendType,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub is_available: bool,
|
||||
}
|
||||
|
||||
/// ALSA plugin information for UI display
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AlsaPluginInfo {
|
||||
pub plugin: AlsaPlugin,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
/// Get list of available audio backends
|
||||
#[tauri::command]
|
||||
pub fn get_available_backends() -> Result<Vec<BackendInfo>, String> {
|
||||
log::info!("Command: get_available_backends");
|
||||
|
||||
let backends = BackendManager::available_backends();
|
||||
let backend_infos: Vec<BackendInfo> = backends
|
||||
.into_iter()
|
||||
.map(|backend_type| {
|
||||
// Create backend instance to check availability and get description
|
||||
let backend = BackendManager::create_backend(backend_type);
|
||||
let (is_available, description) = match backend {
|
||||
Ok(b) => (b.is_available(), b.description().to_string()),
|
||||
Err(_) => (false, "Not available".to_string()),
|
||||
};
|
||||
|
||||
let name = match backend_type {
|
||||
AudioBackendType::PipeWire => "PipeWire",
|
||||
AudioBackendType::Alsa => "ALSA Direct",
|
||||
AudioBackendType::Pulse => "PulseAudio",
|
||||
};
|
||||
|
||||
BackendInfo {
|
||||
backend_type,
|
||||
name: name.to_string(),
|
||||
description,
|
||||
is_available,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
log::info!("Found {} backends", backend_infos.len());
|
||||
for info in &backend_infos {
|
||||
log::info!(" - {} (available: {})", info.name, info.is_available);
|
||||
}
|
||||
|
||||
Ok(backend_infos)
|
||||
}
|
||||
|
||||
/// Get list of devices for a specific backend
|
||||
#[tauri::command]
|
||||
pub fn get_devices_for_backend(backend_type: AudioBackendType) -> Result<Vec<AudioDevice>, String> {
|
||||
log::info!("Command: get_devices_for_backend({:?})", backend_type);
|
||||
|
||||
let backend = BackendManager::create_backend(backend_type)?;
|
||||
let devices = backend.enumerate_devices()?;
|
||||
|
||||
log::info!("Found {} devices for {:?} backend", devices.len(), backend_type);
|
||||
for (idx, device) in devices.iter().enumerate() {
|
||||
log::info!(" [{}] {} (id: {})", idx, device.name, device.id);
|
||||
}
|
||||
|
||||
Ok(devices)
|
||||
}
|
||||
|
||||
/// Get list of available ALSA plugins
|
||||
#[tauri::command]
|
||||
pub fn get_alsa_plugins() -> Result<Vec<AlsaPluginInfo>, String> {
|
||||
log::info!("Command: get_alsa_plugins");
|
||||
|
||||
let plugins = vec![
|
||||
AlsaPluginInfo {
|
||||
plugin: AlsaPlugin::Hw,
|
||||
name: "hw (Direct Hardware)".to_string(),
|
||||
description: "Bit-perfect, exclusive access, blocks device for other apps".to_string(),
|
||||
},
|
||||
AlsaPluginInfo {
|
||||
plugin: AlsaPlugin::PlugHw,
|
||||
name: "plughw (Plugin Hardware)".to_string(),
|
||||
description: "Automatic format conversion, still relatively direct".to_string(),
|
||||
},
|
||||
AlsaPluginInfo {
|
||||
plugin: AlsaPlugin::Pcm,
|
||||
name: "pcm (Default)".to_string(),
|
||||
description: "Generic ALSA device, most compatible".to_string(),
|
||||
},
|
||||
];
|
||||
|
||||
Ok(plugins)
|
||||
}
|
||||
Reference in new issue
Block a user