execute command after finish recording

This commit is contained in:
Salem Yaslem 2021-02-16 09:50:43 +03:00
parent ca70f4a81e
commit 3a40b7ec8b
4 changed files with 33 additions and 6 deletions

11
Cargo.lock generated
View File

@ -122,6 +122,7 @@ dependencies = [
"libappindicator", "libappindicator",
"regex", "regex",
"rust-ini", "rust-ini",
"subprocess",
] ]
[[package]] [[package]]
@ -1027,6 +1028,16 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "subprocess"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69b9ad6c3e1b525a55872a4d2f2d404b3c959b7bbcbfd83c364580f68ed157bd"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.60" version = "1.0.60"

View File

@ -14,6 +14,7 @@ regex = "1.4.3"
chrono = "0.4.19" chrono = "0.4.19"
libappindicator = "0.5.2" libappindicator = "0.5.2"
gettext-rs = "0.5.0" gettext-rs = "0.5.0"
subprocess = "0.2.6"
[dependencies.gtk] [dependencies.gtk]
version = "0.9.0" version = "0.9.0"

View File

@ -1,3 +1,5 @@
extern crate subprocess;
use chrono::prelude::*;
use gtk::{ use gtk::{
CheckButton, ComboBoxExt, ComboBoxText, Entry, EntryExt, FileChooser, FileChooserExt, CheckButton, ComboBoxExt, ComboBoxText, Entry, EntryExt, FileChooser, FileChooserExt,
SpinButton, SpinButtonExt, ToggleButtonExt, SpinButton, SpinButtonExt, ToggleButtonExt,
@ -6,7 +8,7 @@ use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use chrono::prelude::*; use subprocess::Exec;
#[derive(Clone)] #[derive(Clone)]
pub struct Ffmpeg { pub struct Ffmpeg {
@ -18,6 +20,7 @@ pub struct Ffmpeg {
pub follow_mouse: CheckButton, pub follow_mouse: CheckButton,
pub record_frames: SpinButton, pub record_frames: SpinButton,
pub record_delay: SpinButton, pub record_delay: SpinButton,
pub command: Entry,
pub process_id: Option<u32>, pub process_id: Option<u32>,
pub saved_filename: Option<String>, pub saved_filename: Option<String>,
} }
@ -109,18 +112,26 @@ impl Ffmpeg {
} }
pub fn stop_record(self) { pub fn stop_record(self) {
// kill the process to stop recording
if self.process_id.is_some() { if self.process_id.is_some() {
Command::new("kill") Command::new("kill")
.arg(format!("{}", self.process_id.unwrap())) .arg(format!("{}", self.process_id.unwrap()))
.output() .output()
.unwrap(); .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) { pub fn play_record(self) {
if self.saved_filename.is_some() { if self.saved_filename.is_some() {
Command::new("xdg-open") Command::new("xdg-open")
.arg(self.saved_filename.unwrap()).spawn().unwrap(); .arg(self.saved_filename.unwrap())
.spawn()
.unwrap();
} }
} }
} }

View File

@ -89,7 +89,10 @@ fn main() {
command_entry.set_text(&config_management::get("default", "command")); command_entry.set_text(&config_management::get("default", "command"));
// CheckBox // 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("avi"), &gettext("AVI (Audio Video Interleaved)"));
format_chooser_combobox.append(Some("mp4"), &gettext("MP4 (MPEG-4 Part 14)")); format_chooser_combobox.append(Some("mp4"), &gettext("MP4 (MPEG-4 Part 14)"));
format_chooser_combobox.append(Some("wmv"), &gettext("WMV (Windows Media Video)")); 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_copyright(Some("© 2021 Salem Yaslem"));
about_dialog.set_wrap_license(true); 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 <http://www.gnu.org/licenses/>.")); 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 <http://www.gnu.org/licenses/>."));
about_dialog.set_comments(Some( about_dialog.set_comments(Some(&gettext(
&gettext("A simple screen recorder for Linux desktop. Supports Wayland & Xorg."), "A simple screen recorder for Linux desktop. Supports Wayland & Xorg.",
)); )));
about_dialog.set_authors(&[ about_dialog.set_authors(&[
"Salem Yaslem <s@sy.sa>", "Salem Yaslem <s@sy.sa>",
"M.Hanny Sabbagh <mhsabbagh@outlook.com>", "M.Hanny Sabbagh <mhsabbagh@outlook.com>",
@ -264,6 +267,7 @@ fn main() {
follow_mouse: follow_mouse_switch, follow_mouse: follow_mouse_switch,
record_frames: frames_spin, record_frames: frames_spin,
record_delay: delay_spin, record_delay: delay_spin,
command: command_entry,
process_id: None, process_id: None,
saved_filename: None, saved_filename: None,
})); }));