mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-15 04:40:40 -07:00
std::env::set_var is not thread-safe on Unix (unsafe as of Rust 2024 edition) and calling it from a spawned capture thread while other threads (tokio runtime, webview, Tauri plugins) may read the environment is a data race risk. It also never got unset, so the monitor source would leak into any later cpal/ALSA init in the same process. Replace the env-var indirection with direct device selection: when pactl reports a monitor source name, search cpal's input device enumeration for an exact match. Fall back to a substring match on 'monitor' (the original pactl-unavailable path), then the host's default input device. This is the 'pass the source name directly to cpal' option from the issue - no env mutation, no leakage between capture sessions, and it still re-detects the current default sink's monitor on every start_capture call. Fixes #471