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)]
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,9 +172,7 @@ 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(
if !self.main_context.block_on(self.record_wayland.start(
format!(
"{}.temp.without.audio.webm",
self.saved_filename.as_ref().unwrap()
@ -186,8 +185,7 @@ impl Ffmpeg {
CursorModeTypes::Hidden
}
},
))
{
)) {
println!("failed to start recording");
return None;
}
@ -213,7 +211,9 @@ impl Ffmpeg {
}
pub fn stop_record(&mut self) {
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);

View File

@ -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();
@ -109,6 +109,10 @@ pub fn build_ui(application: &Application) {
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();
play_button.hide();