From c601747c79f5aada65f1a00c12cf32c9d5c3bdfa Mon Sep 17 00:00:00 2001 From: ochibani <11yzyv86j@relay.firefox.com> Date: Sat, 29 Jun 2024 01:48:57 +0200 Subject: [PATCH 1/3] add start recording error dialog --- locales/en.ftl | 12 +++++++++--- src/ffmpeg_interface.rs | 10 +++++----- src/main.rs | 23 +++++++++++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/locales/en.ftl b/locales/en.ftl index c5c7e87..ee9921a 100644 --- a/locales/en.ftl +++ b/locales/en.ftl @@ -63,6 +63,9 @@ blue-recorder = Blue Recorder # Copy right copy-right = © 2021 Salem Yaslem +# Close error dialog +close-error-dialog = Close + # Run command label default-command = Default command: @@ -78,15 +81,18 @@ delay-title = Start Recording in… # Stop delay timer delay-window-stop = Stop -# About message -dialog-comment = A simple screen recorder for Linux desktop. Supports Wayland & Xorg. - # Details button details-button = Details +# About message +dialog-comment = A simple screen recorder for Linux desktop. Supports Wayland & Xorg. + # Run command input enter-command = Enter your command here.. +# Error dialog +error-dialog = Error + # Frames label file-name = Default filename: diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 860d2d5..381c2d3 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -17,6 +17,7 @@ use std::thread::sleep; use std::time::Duration; use subprocess::Exec; use filename::Filename; +use std::io::{Error, ErrorKind}; #[derive(Clone)] pub struct Ffmpeg { @@ -45,7 +46,7 @@ pub struct Ffmpeg { } impl Ffmpeg { - pub fn start_record(&mut self, x: u16, y: u16, width: u16, height: u16) -> Option<()> { + pub fn start_record(&mut self, x: u16, y: u16, width: u16, height: u16) -> Result<(), Error> { self.saved_filename = Some( self.filename .0 @@ -83,7 +84,7 @@ impl Ffmpeg { message_dialog.close(); if answer != ResponseType::Yes { - return None; + return Err(Error::new(ErrorKind::Interrupted, "failed to overwrite file")); } } @@ -247,8 +248,7 @@ impl Ffmpeg { } }, )) { - println!("failed to start recording"); - return None; + return Err(Error::new(ErrorKind::Interrupted,"failed to start recording")); } } @@ -265,7 +265,7 @@ impl Ffmpeg { self.audio_process = Some(Rc::new(RefCell::new(ffmpeg_command.spawn().unwrap()))); } - Some(()) + Ok(()) } pub fn stop_record(&mut self) { diff --git a/src/main.rs b/src/main.rs index d0be7d4..2efbce7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod utils; use ffmpeg_interface::Ffmpeg; use gtk::glib; use gtk::prelude::*; +use gtk::TextBuffer; use gtk::{ AboutDialog, Application, Builder, Button, CheckButton, ComboBoxText, CssProvider, Entry, FileChooserAction, FileChooserNative, Image, Label, MessageDialog, SpinButton, @@ -18,6 +19,7 @@ use gtk::{ }; use utils::{get_bundle, is_wayland}; use std::cell::RefCell; +use std::io::ErrorKind; use std::ops::Add; use std::path::Path; use std::rc::Rc; @@ -597,14 +599,22 @@ pub fn build_ui(application: &Application) { ); } else if _delay_spin.value() as u64 == 0 { let _area_capture = area_capture.borrow_mut(); - match _ffmpeg_record_interface.borrow_mut().start_record( + let start_record = _ffmpeg_record_interface.borrow_mut().start_record( _area_capture.x, _area_capture.y, _area_capture.width, _area_capture.height, - ) { - None => { - // Do nothing if the start_record function return nothing + ); + match start_record { + Err(ref error) => { + if error.kind() == ErrorKind::Interrupted { + // Do nothing if the start_record function interrupted + } else { + error_dialog_label.set_label(&get_bundle("start-error", None)); + let text_buffer = TextBuffer::new(None); + text_buffer.set_text(&error.to_string()); + error_message.set_buffer(Some(&text_buffer)); + } } _ => { start_timer(record_time_label.clone()); @@ -645,6 +655,11 @@ pub fn build_ui(application: &Application) { _ffmpeg_record_interface.borrow_mut().clone().play_record(); }); + // Error Dialog + error_dialog.set_title(Some(&get_bundle("error-dialog", None))); + error_dialog_button.set_label(&get_bundle("close-error-dialog", None)); + error_expander_label.set_label(&get_bundle("details-button", None)); + // About Dialog let mut about_icon_path = { let mut current_exec_dir = std::env::current_exe().unwrap(); From feeaf31e07c480e373789afeb36108332ef870e0 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Wed, 4 Dec 2024 22:25:14 +0300 Subject: [PATCH 2/3] default to 0 --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2efbce7..efad93f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,7 +150,7 @@ pub fn build_ui(application: &Application) { format_chooser_combobox.append(Some("avi"), &get_bundle("avi-format", None)); format_chooser_combobox.append(Some("wmv"), &get_bundle("wmv-format", None)); format_chooser_combobox.append(Some("nut"), &get_bundle("nut-format", None)); - format_chooser_combobox.set_active(Some(config_management::get("default", "format").parse::().unwrap())); + format_chooser_combobox.set_active(Some(config_management::get("default", "format").parse::().unwrap_or(0u32))); // Get audio sources let input_device = host_audio_device.input_devices().unwrap(); @@ -348,12 +348,12 @@ pub fn build_ui(application: &Application) { ("frame-{}", &format_chooser_combobox.active().unwrap().to_string())) .parse::() - .unwrap(), + .unwrap_or(0f64), ); delay_spin.set_value( config_management::get("default", "delay") .parse::() - .unwrap(), + .unwrap_or(0f64), ); video_bitrate_spin.set_value( config_management::get("default", @@ -361,12 +361,12 @@ pub fn build_ui(application: &Application) { ("videobitrate-{}", &format_chooser_combobox.active().unwrap().to_string())) .parse::() - .unwrap(), + .unwrap_or(0f64), ); audio_bitrate_spin.set_value( config_management::get("default", "audiobitrate") .parse::() - .unwrap(), + .unwrap_or(0f64), ); let _format_chooser_combobox = format_chooser_combobox.clone(); From 7f036c2049d1ebcc5838ec6d26333f5d6690b408 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Wed, 4 Dec 2024 22:43:06 +0300 Subject: [PATCH 3/3] default configs to zeros when not exists --- src/ui.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 19d61dc..f0f64ff 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -170,7 +170,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag format_chooser_combobox.append(Some("avi"), &get_bundle("avi-format", None)); format_chooser_combobox.append(Some("wmv"), &get_bundle("wmv-format", None)); format_chooser_combobox.append(Some("nut"), &get_bundle("nut-format", None)); - format_chooser_combobox.set_active(Some(config_management::get("default", "format").parse::().unwrap())); + format_chooser_combobox.set_active(Some(config_management::get("default", "format").parse::().unwrap_or(0u32))); // Get audio sources let input_device = host_audio_device.input_devices().unwrap(); @@ -373,17 +373,17 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag ("frame-{}", &format_chooser_combobox.active().unwrap().to_string())) .parse::() - .unwrap(), + .unwrap_or(0f64), ); audio_bitrate_spin.set_value( config_management::get("default", "audiobitrate") .parse::() - .unwrap(), + .unwrap_or(0f64), ); delay_spin.set_value( config_management::get("default", "delay") .parse::() - .unwrap(), + .unwrap_or(0f64), ); video_bitrate_spin.set_value( config_management::get("default", @@ -391,7 +391,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag ("videobitrate-{}", &format_chooser_combobox.active().unwrap().to_string())) .parse::() - .unwrap(), + .unwrap_or(0f64), ); let _format_chooser_combobox = format_chooser_combobox.clone(); @@ -411,7 +411,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag ("frame-{}", &format_chooser_combobox.active().unwrap().to_string())) .parse::() - .unwrap(), + .unwrap_or(0f64), ); _video_bitrate_spin.set_value( config_management::get("default", @@ -419,7 +419,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag ("videobitrate-{}", &format_chooser_combobox.active().unwrap().to_string())) .parse::() - .unwrap(), + .unwrap_or(0f64), ); } });