From 0e9576265c0063b1e73e8883e4c26510a2fb33c2 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Sat, 21 Oct 2023 14:34:18 +0300 Subject: [PATCH] refactor of code --- src/ffmpeg_interface.rs | 53 ++++++++++++++++++++--------------------- src/main.rs | 6 ++++- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 3cc669b..94cc7e8 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -18,25 +18,26 @@ use subprocess::Exec; #[derive(Clone)] pub struct ProgressWidget { pub progress_dialog: MessageDialog, - pub progressbar: ProgressBar, + pub progress_bar: ProgressBar, } impl ProgressWidget { - pub fn new(progress_dialog: MessageDialog, progressbar: ProgressBar) -> ProgressWidget { + pub fn new(progress_dialog: MessageDialog, progress_bar: ProgressBar) -> ProgressWidget { ProgressWidget { progress_dialog, - progressbar, + progress_bar, } } pub fn set_progress(&self, title: String, value: i32, max: i32) { - let progress_precentage: f64 = value as f64 / max as f64; - self.progressbar.set_text(Some(&title)); - self.progressbar.set_fraction(progress_precentage); + glib::MainContext::default().block_on(async { + let progress_percentage: f64 = value as f64 / max as f64; + self.progress_bar.set_text(Some(&title)); + self.progress_bar.set_fraction(progress_percentage); + }); } pub fn show(&self) { - self.progressbar.set_fraction(0.0); self.progress_dialog.show(); } @@ -171,23 +172,20 @@ impl Ffmpeg { self.video_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap()))); } else if self.record_video.is_active() && is_wayland() { sleep(Duration::from_secs(self.record_delay.value() as u64)); - if !self - .main_context - .block_on(self.record_wayland.start( - format!( - "{}.temp.without.audio.webm", - self.saved_filename.as_ref().unwrap() - ), - RecordTypes::Monitor, - { - if self.record_mouse.is_active() { - CursorModeTypes::Show - } else { - CursorModeTypes::Hidden - } - }, - )) - { + if !self.main_context.block_on(self.record_wayland.start( + format!( + "{}.temp.without.audio.webm", + self.saved_filename.as_ref().unwrap() + ), + RecordTypes::Monitor, + { + if self.record_mouse.is_active() { + CursorModeTypes::Show + } else { + CursorModeTypes::Hidden + } + }, + )) { println!("failed to start recording"); return None; } @@ -213,7 +211,9 @@ impl Ffmpeg { } pub fn stop_record(&mut self) { - self.progress_widget.show(); + glib::MainContext::default().block_on(async { + self.progress_widget.show(); + }); self.progress_widget.set_progress("".to_string(), 1, 7); // kill the process to stop recording @@ -238,8 +238,7 @@ impl Ffmpeg { println!("video killed"); } else if is_wayland() { - self.main_context - .block_on(self.record_wayland.stop()); + self.main_context.block_on(self.record_wayland.stop()); } self.progress_widget.set_progress("".to_string(), 2, 7); diff --git a/src/main.rs b/src/main.rs index 4994122..3c52090 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,7 @@ pub fn build_ui(application: &Application) { config_management::initialize(); // Get Objects from UI + let main_window: Window = builder.object("main_window").unwrap(); let area_chooser_window: Window = builder.object("area_chooser_window").unwrap(); let area_grab_button: ToggleButton = builder.object("area_grab_button").unwrap(); let area_grab_icon: Image = builder.object("area_grab_icon").unwrap(); @@ -89,7 +90,6 @@ pub fn build_ui(application: &Application) { let format_chooser_combobox: ComboBoxText = builder.object("comboboxtext1").unwrap(); let frames_label: Label = builder.object("frames_label").unwrap(); let frames_spin: SpinButton = builder.object("frames").unwrap(); - let main_window: Window = builder.object("main_window").unwrap(); let mouse_switch: CheckButton = builder.object("mouseswitch").unwrap(); let play_button: Button = builder.object("playbutton").unwrap(); let progress_dialog: MessageDialog = builder.object("progress_dialog").unwrap(); @@ -108,6 +108,10 @@ pub fn build_ui(application: &Application) { main_window.set_title(Some(&gettext("Blue Recorder"))); main_window.set_application(Some(application)); area_chooser_window.set_title(Some(&gettext("Area Chooser"))); // Title is hidden + + // disable interaction with main window + // main_window.set_can_focus(false); + // main_window.set_can_target(false); // Hide stop & play buttons stop_button.hide();