feat: set to default input device when in dual-way

This commit is contained in:
Kingtous
2023-01-31 10:01:31 +08:00
parent cab1fc719a
commit 7e5c5b50e5
5 changed files with 85 additions and 4 deletions

View File

@@ -30,6 +30,8 @@ use hbb_common::{
// #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
use hbb_common::{config::RENDEZVOUS_PORT, futures::future::join_all};
use crate::ui_interface::{set_option, get_option};
pub type NotifyMessageBox = fn(String, String, String, String) -> dyn Future<Output = ()>;
pub const CLIPBOARD_NAME: &'static str = "clipboard";
@@ -105,6 +107,46 @@ pub fn check_clipboard(
None
}
/// Set sound input device.
pub fn set_sound_input(device: String) {
let prior_device = get_option("audio-input".to_owned());
if prior_device != device {
log::info!("switch to audio input device {}", device);
set_option("audio-input".to_owned(), device);
} else {
log::info!("audio input is already set to {}", device);
}
}
/// Get system's default sound input device name.
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn get_default_sound_input() -> Option<String> {
#[cfg(not(target_os = "linux"))]
{
use cpal::traits::{DeviceTrait, HostTrait};
let host = cpal::default_host();
let dev = host.default_input_device();
return if let Some(dev) = dev {
match dev.name() {
Ok(name) => Some(name),
Err(_) => None,
}
} else {
None
};
}
#[cfg(target_os = "linux")]
{
let input = crate::platform::linux::get_default_pa_source();
return if let Some(input) = input {
Some(input.1)
} else {
None
};
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>) {
let content = if clipboard.compress {
@@ -715,5 +757,5 @@ pub fn make_fd_to_json(id: i32, path: String, entries: &Vec<FileEntry>) -> Strin
#[cfg(test)]
mod test_common {
use super::*;
}