feat: Add persistent configuration and enumerate PipeWire audio devices

This commit is contained in:
2026-05-27 16:03:07 -04:00
parent e0ba002c12
commit dac53fc2ad
8 changed files with 352 additions and 24 deletions
+41
View File
@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct AppConfig {
pub input_device: String,
pub output_device: String,
}
impl AppConfig {
fn config_path() -> Option<PathBuf> {
dirs::config_dir().map(|mut p| {
p.push("peerspeak");
p.push("config.json");
p
})
}
pub fn load() -> Self {
if let Some(path) = Self::config_path() {
if let Ok(contents) = fs::read_to_string(&path) {
if let Ok(config) = serde_json::from_str(&contents) {
return config;
}
}
}
Self::default()
}
pub fn save(&self) {
if let Some(path) = Self::config_path() {
if let Some(dir) = path.parent() {
let _ = fs::create_dir_all(dir);
}
if let Ok(json) = serde_json::to_string_pretty(self) {
let _ = fs::write(path, json);
}
}
}
}