From 05f415e2abc47bc4fed135518d6cbd869890831d Mon Sep 17 00:00:00 2001 From: ochibani <11yzyv86j@relay.firefox.com> Date: Wed, 8 Jan 2025 08:58:59 +0200 Subject: [PATCH] update gui --- core/src/utils.rs | 64 +++++++++++++++++++++++------------------------ gui/src/ui.rs | 9 +++++-- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/core/src/utils.rs b/core/src/utils.rs index 001214e..bed59ff 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -9,6 +9,38 @@ pub enum RecordMode { Window, } +// Get audio output source +#[cfg(feature = "gtk")] +pub fn audio_output_source() -> Result { + // Get the default sink + let default_sink_output = Command::new("pactl") + .arg("get-default-sink") + .output()?; + + let default_sink = String::from_utf8_lossy(&default_sink_output.stdout) + .trim() + .to_string(); + + // List sinks and filter for the monitor of the default sink + let sinks_output = Command::new("pactl") + .arg("list") + .arg("sinks") + .output()?; + + let sinks = String::from_utf8_lossy(&sinks_output.stdout); + let monitor_line = sinks + .lines() + .find(|line| line.contains(&format!("{}.monitor", default_sink))) + .unwrap_or(""); + + // Extract the part after the colon + let output_source = monitor_line.split(':') + .nth(1) + .unwrap_or("") + .trim().to_string(); + Ok(output_source) +} + #[cfg(feature = "gtk")] // Disable GtkWidget pub fn disable_input_widgets(input_widgets: Vec) { @@ -105,38 +137,6 @@ pub fn is_wayland() -> bool { .eq_ignore_ascii_case("wayland") } -// Get audio output source -#[cfg(feature = "gtk")] -pub fn audio_output_source() -> Result { - // Get the default sink - let default_sink_output = Command::new("pactl") - .arg("get-default-sink") - .output()?; - - let default_sink = String::from_utf8_lossy(&default_sink_output.stdout) - .trim() - .to_string(); - - // List sinks and filter for the monitor of the default sink - let sinks_output = Command::new("pactl") - .arg("list") - .arg("sinks") - .output()?; - - let sinks = String::from_utf8_lossy(&sinks_output.stdout); - let monitor_line = sinks - .lines() - .find(|line| line.contains(&format!("{}.monitor", default_sink))) - .unwrap_or(""); - - // Extract the part after the colon - let output_source = monitor_line.split(':') - .nth(1) - .unwrap_or("") - .trim().to_string(); - Ok(output_source) -} - #[cfg(feature = "gtk")] // Play recorded file pub fn play_record(file_name: &str) -> Result<()> { diff --git a/gui/src/ui.rs b/gui/src/ui.rs index 565e52c..dd9c8a5 100644 --- a/gui/src/ui.rs +++ b/gui/src/ui.rs @@ -8,10 +8,10 @@ use anyhow::Result; use blue_recorder_core::ffmpeg_linux::Ffmpeg; #[cfg(target_os = "windows")] use blue_recorder_core::ffmpeg_windows::Ffmpeg; -use blue_recorder_core::utils::{audio_output_source, disable_input_widgets, enable_input_widgets, +use blue_recorder_core::utils::{disable_input_widgets, enable_input_widgets, is_overwrite, is_wayland, play_record, RecordMode}; #[cfg(any(target_os = "freebsd", target_os = "linux"))] -use blue_recorder_core::utils::sources_descriptions_list; +use blue_recorder_core::utils::{audio_output_source, sources_descriptions_list}; #[cfg(target_os = "windows")] use cpal::traits::{DeviceTrait, HostTrait}; use std::cell::RefCell; @@ -202,12 +202,17 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag } else { String::new() }; + audio_source_combobox.append(Some("default"), &get_bundle("audio-input", None)); + for (id, audio_source) in sources_descriptions.iter().enumerate() { + audio_source_combobox.append(Some(id.to_string().as_str()), audio_source); + } } #[cfg(any(target_os = "freebsd", target_os = "linux"))] let sources_descriptions: Vec = sources_descriptions_list().unwrap_or_else(|_| Vec::new()); #[cfg(any(target_os = "freebsd", target_os = "linux"))] let audio_output_source: String = audio_output_source().unwrap_or_else(|_| String::new()); + #[cfg(any(target_os = "freebsd", target_os = "linux"))] audio_source_combobox.append(Some("default"), &get_bundle("audio-input", None)); for (id, audio_source) in sources_descriptions.iter().enumerate() { audio_source_combobox.append(Some(id.to_string().as_str()), audio_source);