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",
"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"

View File

@ -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"

View File

@ -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<u32>,
pub saved_filename: Option<String>,
}
@ -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();
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>."));
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 <s@sy.sa>",
"M.Hanny Sabbagh <mhsabbagh@outlook.com>",
@ -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,
}));