mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
refactor: simplify device retrieval in link_player_to_virtual_mic function
This commit is contained in:
+11
-27
@@ -2,10 +2,9 @@ use crate::{
|
|||||||
types::{
|
types::{
|
||||||
audio_player::AudioPlayer,
|
audio_player::AudioPlayer,
|
||||||
config::DaemonConfig,
|
config::DaemonConfig,
|
||||||
pipewire::AudioDevice,
|
|
||||||
socket::{Request, Response},
|
socket::{Request, Response},
|
||||||
},
|
},
|
||||||
utils::pipewire::{create_link, get_all_devices},
|
utils::pipewire::{create_link, get_device},
|
||||||
};
|
};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{error::Error, fs};
|
use std::{error::Error, fs};
|
||||||
@@ -36,37 +35,22 @@ pub fn get_daemon_config() -> DaemonConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn link_player_to_virtual_mic() -> Result<(), Box<dyn Error>> {
|
pub async fn link_player_to_virtual_mic() -> Result<(), Box<dyn Error>> {
|
||||||
let (input_devices, output_devices) = get_all_devices().await?;
|
let pwsp_daemon_output;
|
||||||
|
if let Ok(device) = get_device("alsa_playback.pwsp-daemon").await {
|
||||||
let mut pwsp_daemon_output: Option<AudioDevice> = None;
|
pwsp_daemon_output = device;
|
||||||
for output_device in output_devices {
|
} else {
|
||||||
if output_device.name == "alsa_playback.pwsp-daemon" {
|
eprintln!("Could not find alsa_playback.pwsp-daemon device, skipping device linking");
|
||||||
pwsp_daemon_output = Some(output_device);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pwsp_daemon_output.is_none() {
|
|
||||||
eprintln!("Could not find pwsp-daemon output device, skipping device linking");
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut pwsp_daemon_input: Option<AudioDevice> = None;
|
let pwsp_daemon_input;
|
||||||
for input_device in input_devices {
|
if let Ok(device) = get_device("pwsp-virtual-mic").await {
|
||||||
if input_device.name == "pwsp-virtual-mic" {
|
pwsp_daemon_input = device;
|
||||||
pwsp_daemon_input = Some(input_device);
|
} else {
|
||||||
break;
|
eprintln!("Could not find pwsp-virtual-mic device, skipping device linking");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pwsp_daemon_input.is_none() {
|
|
||||||
eprintln!("Could not find pwsp-daemon input device, skipping device linking");
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let pwsp_daemon_output = pwsp_daemon_output.unwrap();
|
|
||||||
let pwsp_daemon_input = pwsp_daemon_input.unwrap();
|
|
||||||
|
|
||||||
let output_fl = pwsp_daemon_output
|
let output_fl = pwsp_daemon_output
|
||||||
.clone()
|
.clone()
|
||||||
.output_fl
|
.output_fl
|
||||||
|
|||||||
Reference in New Issue
Block a user