mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2025-03-31 23:04:55 +03:00
add kill process
This commit is contained in:
parent
b5d19b5ea6
commit
ac7b3c2d09
@ -138,6 +138,7 @@ impl Ffmpeg {
|
||||
},
|
||||
]);
|
||||
ffmpeg_command.overwrite();
|
||||
ffmpeg_command.print_command();
|
||||
|
||||
// Sleep for delay
|
||||
sleep(Duration::from_secs(self.record_delay as u64));
|
||||
@ -356,4 +357,42 @@ impl Ffmpeg {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Kill process
|
||||
pub fn kill(&mut self) -> Result<()> {
|
||||
if self.video_process.is_some() {
|
||||
std::process::Command::new("kill")
|
||||
.arg(format!(
|
||||
"{}",
|
||||
self.video_process
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Unable to kill the video recording process successfully."))?
|
||||
.borrow_mut()
|
||||
.as_inner().id()
|
||||
)).output()?;
|
||||
}
|
||||
if self.input_audio_process.is_some() {
|
||||
std::process::Command::new("kill")
|
||||
.arg(format!(
|
||||
"{}",
|
||||
self.input_audio_process
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Unable to kill the intput audio recording process successfully."))?
|
||||
.borrow_mut()
|
||||
.as_inner().id()
|
||||
)).output()?;
|
||||
}
|
||||
if self.output_audio_process.is_some() {
|
||||
std::process::Command::new("kill")
|
||||
.arg(format!(
|
||||
"{}",
|
||||
self.output_audio_process
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Unable to kill the output audio recording process successfully."))?
|
||||
.borrow_mut()
|
||||
.as_inner().id()
|
||||
)).output()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -343,4 +343,45 @@ impl Ffmpeg {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Kill process
|
||||
pub fn kill(&mut self) -> Result<()> {
|
||||
if self.video_process.is_some() {
|
||||
let pid = self.video_process
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Unable to kill the video recording process successfully."))?
|
||||
.borrow_mut()
|
||||
.as_inner().id();
|
||||
std::process::Command::new("taskkill")
|
||||
.arg("/PID")
|
||||
.arg(pid.to_string())
|
||||
.arg("/F")
|
||||
.output()?;
|
||||
}
|
||||
if self.input_audio_process.is_some() {
|
||||
let pid = self.input_audio_process
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Unable to kill the input audio recording process successfully."))?
|
||||
.borrow_mut()
|
||||
.as_inner().id();
|
||||
std::process::Command::new("taskkill")
|
||||
.arg("/PID")
|
||||
.arg(pid.to_string())
|
||||
.arg("/F")
|
||||
.output()?;
|
||||
}
|
||||
if self.output_audio_process.is_some() {
|
||||
let pid = self.output_audio_process
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Unable to kill the output audio recording process successfully."))?
|
||||
.borrow_mut()
|
||||
.as_inner().id();
|
||||
std::process::Command::new("taskkill")
|
||||
.arg("/PID")
|
||||
.arg(pid.to_string())
|
||||
.arg("/F")
|
||||
.output()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -918,6 +918,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
|
||||
// Do nothing
|
||||
},
|
||||
Err(error) => {
|
||||
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
|
||||
_audio_input_switch.set_sensitive(true);
|
||||
_audio_output_switch.set_sensitive(true);
|
||||
_video_switch.set_sensitive(true);
|
||||
@ -936,6 +937,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
|
||||
// Do nothing
|
||||
},
|
||||
Err(error) => {
|
||||
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
|
||||
_audio_input_switch.set_sensitive(true);
|
||||
_audio_output_switch.set_sensitive(true);
|
||||
_video_switch.set_sensitive(true);
|
||||
@ -954,6 +956,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
|
||||
// Do nothing
|
||||
},
|
||||
Err(error) => {
|
||||
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
|
||||
_audio_input_switch.set_sensitive(true);
|
||||
_audio_output_switch.set_sensitive(true);
|
||||
_video_switch.set_sensitive(true);
|
||||
@ -1086,42 +1089,7 @@ fn build_ui(application: &Application, error_dialog: MessageDialog, error_messag
|
||||
// Stop recording before close the application
|
||||
let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone();
|
||||
main_window.connect_close_request(move |main_window| {
|
||||
if _ffmpeg_record_interface.borrow_mut().video_process.is_some() {
|
||||
std::process::Command::new("kill")
|
||||
.arg(format!(
|
||||
"{}",
|
||||
_ffmpeg_record_interface.borrow_mut()
|
||||
.video_process
|
||||
.clone()
|
||||
.unwrap()
|
||||
.borrow_mut()
|
||||
.as_inner().id()
|
||||
)).output().unwrap();
|
||||
}
|
||||
if _ffmpeg_record_interface.borrow_mut().input_audio_process.is_some() {
|
||||
std::process::Command::new("kill")
|
||||
.arg(format!(
|
||||
"{}",
|
||||
_ffmpeg_record_interface.borrow_mut()
|
||||
.input_audio_process
|
||||
.clone()
|
||||
.unwrap()
|
||||
.borrow_mut()
|
||||
.as_inner().id()
|
||||
)).output().unwrap();
|
||||
}
|
||||
if _ffmpeg_record_interface.borrow_mut().output_audio_process.is_some() {
|
||||
std::process::Command::new("kill")
|
||||
.arg(format!(
|
||||
"{}",
|
||||
_ffmpeg_record_interface.borrow_mut()
|
||||
.output_audio_process
|
||||
.clone()
|
||||
.unwrap()
|
||||
.borrow_mut()
|
||||
.as_inner().id()
|
||||
)).output().unwrap();
|
||||
}
|
||||
_ffmpeg_record_interface.borrow_mut().kill().unwrap();
|
||||
main_window.destroy();
|
||||
adw::gtk::Inhibit(true)
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user