diff --git a/Cargo.lock b/Cargo.lock index 69ace36..2b8a1d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,6 +122,7 @@ dependencies = [ "libappindicator", "regex", "rust-ini", + "subprocess", ] [[package]] @@ -1027,6 +1028,16 @@ dependencies = [ "syn", ] +[[package]] +name = "subprocess" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b9ad6c3e1b525a55872a4d2f2d404b3c959b7bbcbfd83c364580f68ed157bd" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "syn" version = "1.0.60" diff --git a/Cargo.toml b/Cargo.toml index 2f548f0..e75afb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ regex = "1.4.3" chrono = "0.4.19" libappindicator = "0.5.2" gettext-rs = "0.5.0" +subprocess = "0.2.6" [dependencies.gtk] version = "0.9.0" diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index 02d6aaf..0a1ad9e 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -1,3 +1,5 @@ +extern crate subprocess; +use chrono::prelude::*; use gtk::{ CheckButton, ComboBoxExt, ComboBoxText, Entry, EntryExt, FileChooser, FileChooserExt, SpinButton, SpinButtonExt, ToggleButtonExt, @@ -6,7 +8,7 @@ use std::path::PathBuf; use std::process::Command; use std::thread::sleep; use std::time::Duration; -use chrono::prelude::*; +use subprocess::Exec; #[derive(Clone)] pub struct Ffmpeg { @@ -18,6 +20,7 @@ pub struct Ffmpeg { pub follow_mouse: CheckButton, pub record_frames: SpinButton, pub record_delay: SpinButton, + pub command: Entry, pub process_id: Option, pub saved_filename: Option, } @@ -109,18 +112,26 @@ impl Ffmpeg { } pub fn stop_record(self) { + // kill the process to stop recording if self.process_id.is_some() { Command::new("kill") .arg(format!("{}", self.process_id.unwrap())) .output() .unwrap(); } + + // execute command after finish recording + if !(self.command.get_text().trim() == "") { + Exec::shell(self.command.get_text().trim()).popen().unwrap(); + } } pub fn play_record(self) { if self.saved_filename.is_some() { Command::new("xdg-open") - .arg(self.saved_filename.unwrap()).spawn().unwrap(); + .arg(self.saved_filename.unwrap()) + .spawn() + .unwrap(); } } } diff --git a/src/main.rs b/src/main.rs index e8b7921..4c60ca3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,10 @@ fn main() { command_entry.set_text(&config_management::get("default", "command")); // CheckBox - format_chooser_combobox.append(Some("mkv"), &gettext("MKV (Matroska multimedia container format)")); + format_chooser_combobox.append( + Some("mkv"), + &gettext("MKV (Matroska multimedia container format)"), + ); format_chooser_combobox.append(Some("avi"), &gettext("AVI (Audio Video Interleaved)")); format_chooser_combobox.append(Some("mp4"), &gettext("MP4 (MPEG-4 Part 14)")); format_chooser_combobox.append(Some("wmv"), &gettext("WMV (Windows Media Video)")); @@ -165,9 +168,9 @@ fn main() { about_dialog.set_copyright(Some("© 2021 Salem Yaslem")); about_dialog.set_wrap_license(true); about_dialog.set_license(Some("Blue Recorder is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nBlue Recorder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\nSee the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Blue Recorder. If not, see .")); - about_dialog.set_comments(Some( - &gettext("A simple screen recorder for Linux desktop. Supports Wayland & Xorg."), - )); + about_dialog.set_comments(Some(&gettext( + "A simple screen recorder for Linux desktop. Supports Wayland & Xorg.", + ))); about_dialog.set_authors(&[ "Salem Yaslem ", "M.Hanny Sabbagh ", @@ -264,6 +267,7 @@ fn main() { follow_mouse: follow_mouse_switch, record_frames: frames_spin, record_delay: delay_spin, + command: command_entry, process_id: None, saved_filename: None, }));