Audio config
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
use cpal::traits::{DeviceTrait, HostTrait};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AudioDevice {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_input_devices() -> Result<Vec<AudioDevice>, String> {
|
||||
pub fn list_input_devices() -> Result<Vec<String>, String> {
|
||||
let host = cpal::default_host();
|
||||
|
||||
let devices = host
|
||||
@@ -16,10 +9,19 @@ pub fn list_input_devices() -> Result<Vec<AudioDevice>, String> {
|
||||
.map_err(|e| format!("Failed to enumerate input devices: {e}"))?;
|
||||
|
||||
Ok(devices
|
||||
.filter_map(|d| {
|
||||
Some(AudioDevice {
|
||||
name: d.description().ok()?.name().to_string(),
|
||||
})
|
||||
})
|
||||
.filter_map(|d| Some(d.description().ok()?.name().to_string()))
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn list_output_devices() -> Result<Vec<String>, String> {
|
||||
let host = cpal::default_host();
|
||||
|
||||
let devices = host
|
||||
.output_devices()
|
||||
.map_err(|e| format!("Failed to enumerate output devices: {e}"))?;
|
||||
|
||||
Ok(devices
|
||||
.filter_map(|d| Some(d.description().ok()?.name().to_string()))
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use cpal::traits::{DeviceTrait, HostTrait};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::sync::Mutex;
|
||||
@@ -6,13 +7,25 @@ use tauri::{AppHandle, Manager, State};
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Config {
|
||||
pub audio_device_name: Option<String>,
|
||||
pub input_device_name: Option<String>,
|
||||
pub output_device_name: Option<String>,
|
||||
pub input_volume: u8,
|
||||
pub output_volume: u8,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
let host = cpal::default_host();
|
||||
|
||||
Self {
|
||||
audio_device_name: None,
|
||||
input_device_name: host
|
||||
.default_input_device()
|
||||
.and_then(|d| Some(d.description().ok()?.name().to_string())),
|
||||
output_device_name: host
|
||||
.default_output_device()
|
||||
.and_then(|d| Some(d.description().ok()?.name().to_string())),
|
||||
input_volume: 0,
|
||||
output_volume: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ pub fn run() {
|
||||
commands::accounts::save_accounts,
|
||||
commands::accounts::get_accounts,
|
||||
commands::audio::list_input_devices,
|
||||
commands::audio::list_output_devices,
|
||||
commands::config::update_config,
|
||||
commands::config::save_config,
|
||||
commands::config::get_config,
|
||||
|
||||
Reference in New Issue
Block a user