refactor of code

This commit is contained in:
Salem Yaslem 2023-10-21 14:34:18 +03:00
parent b959262fba
commit 0e9576265c
2 changed files with 31 additions and 28 deletions

View File

@ -18,25 +18,26 @@ use subprocess::Exec;
#[derive(Clone)] #[derive(Clone)]
pub struct ProgressWidget { pub struct ProgressWidget {
pub progress_dialog: MessageDialog, pub progress_dialog: MessageDialog,
pub progressbar: ProgressBar, pub progress_bar: ProgressBar,
} }
impl ProgressWidget { impl ProgressWidget {
pub fn new(progress_dialog: MessageDialog, progressbar: ProgressBar) -> ProgressWidget { pub fn new(progress_dialog: MessageDialog, progress_bar: ProgressBar) -> ProgressWidget {
ProgressWidget { ProgressWidget {
progress_dialog, progress_dialog,
progressbar, progress_bar,
} }
} }
pub fn set_progress(&self, title: String, value: i32, max: i32) { pub fn set_progress(&self, title: String, value: i32, max: i32) {
let progress_precentage: f64 = value as f64 / max as f64; glib::MainContext::default().block_on(async {
self.progressbar.set_text(Some(&title)); let progress_percentage: f64 = value as f64 / max as f64;
self.progressbar.set_fraction(progress_precentage); self.progress_bar.set_text(Some(&title));
self.progress_bar.set_fraction(progress_percentage);
});
} }
pub fn show(&self) { pub fn show(&self) {
self.progressbar.set_fraction(0.0);
self.progress_dialog.show(); self.progress_dialog.show();
} }
@ -171,23 +172,20 @@ impl Ffmpeg {
self.video_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap()))); self.video_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap())));
} else if self.record_video.is_active() && is_wayland() { } else if self.record_video.is_active() && is_wayland() {
sleep(Duration::from_secs(self.record_delay.value() as u64)); sleep(Duration::from_secs(self.record_delay.value() as u64));
if !self if !self.main_context.block_on(self.record_wayland.start(
.main_context format!(
.block_on(self.record_wayland.start( "{}.temp.without.audio.webm",
format!( self.saved_filename.as_ref().unwrap()
"{}.temp.without.audio.webm", ),
self.saved_filename.as_ref().unwrap() RecordTypes::Monitor,
), {
RecordTypes::Monitor, if self.record_mouse.is_active() {
{ CursorModeTypes::Show
if self.record_mouse.is_active() { } else {
CursorModeTypes::Show CursorModeTypes::Hidden
} else { }
CursorModeTypes::Hidden },
} )) {
},
))
{
println!("failed to start recording"); println!("failed to start recording");
return None; return None;
} }
@ -213,7 +211,9 @@ impl Ffmpeg {
} }
pub fn stop_record(&mut self) { 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); self.progress_widget.set_progress("".to_string(), 1, 7);
// kill the process to stop recording // kill the process to stop recording
@ -238,8 +238,7 @@ impl Ffmpeg {
println!("video killed"); println!("video killed");
} else if is_wayland() { } else if is_wayland() {
self.main_context self.main_context.block_on(self.record_wayland.stop());
.block_on(self.record_wayland.stop());
} }
self.progress_widget.set_progress("".to_string(), 2, 7); self.progress_widget.set_progress("".to_string(), 2, 7);

View File

@ -65,6 +65,7 @@ pub fn build_ui(application: &Application) {
config_management::initialize(); config_management::initialize();
// Get Objects from UI // 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_chooser_window: Window = builder.object("area_chooser_window").unwrap();
let area_grab_button: ToggleButton = builder.object("area_grab_button").unwrap(); let area_grab_button: ToggleButton = builder.object("area_grab_button").unwrap();
let area_grab_icon: Image = builder.object("area_grab_icon").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 format_chooser_combobox: ComboBoxText = builder.object("comboboxtext1").unwrap();
let frames_label: Label = builder.object("frames_label").unwrap(); let frames_label: Label = builder.object("frames_label").unwrap();
let frames_spin: SpinButton = builder.object("frames").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 mouse_switch: CheckButton = builder.object("mouseswitch").unwrap();
let play_button: Button = builder.object("playbutton").unwrap(); let play_button: Button = builder.object("playbutton").unwrap();
let progress_dialog: MessageDialog = builder.object("progress_dialog").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_title(Some(&gettext("Blue Recorder")));
main_window.set_application(Some(application)); main_window.set_application(Some(application));
area_chooser_window.set_title(Some(&gettext("Area Chooser"))); // Title is hidden 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 // Hide stop & play buttons
stop_button.hide(); stop_button.hide();