kill check-hwcodec-config process

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-02-21 15:07:44 +08:00
parent 95a0d90891
commit 4beacf93d7
7 changed files with 31 additions and 16 deletions

View File

@@ -33,6 +33,7 @@ tokio-socks = { git = "https://github.com/open-trade/tokio-socks" }
chrono = "0.4"
backtrace = "0.3"
libc = "0.2"
sysinfo = "0.24"
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
mac_address = "1.1"

View File

@@ -42,6 +42,7 @@ pub use chrono;
pub use libc;
pub use directories_next;
pub mod keyboard;
pub use sysinfo;
#[cfg(feature = "quic")]
pub type Stream = quic::Connection;

View File

@@ -317,16 +317,30 @@ pub fn check_config() {
}
pub fn check_config_process(force_reset: bool) {
if force_reset {
HwCodecConfig::remove();
}
if let Ok(exe) = std::env::current_exe() {
std::thread::spawn(move || {
std::process::Command::new(exe)
.arg("--check-hwcodec-config")
.status()
.ok();
HwCodecConfig::refresh();
});
};
use hbb_common::sysinfo::{ProcessExt, System, SystemExt};
std::thread::spawn(move || {
if force_reset {
HwCodecConfig::remove();
}
if let Ok(exe) = std::env::current_exe() {
if let Some(file_name) = exe.file_name().to_owned() {
let s = System::new_all();
let arg = "--check-hwcodec-config";
for process in s.processes_by_name(&file_name.to_string_lossy().to_string()) {
if process.cmd().iter().any(|cmd| cmd.contains(arg)) {
log::warn!("already have process {}", arg);
return;
}
}
if let Ok(mut child) = std::process::Command::new(exe).arg(arg).spawn() {
let second = 3;
std::thread::sleep(std::time::Duration::from_secs(second));
// kill: Different platforms have different results
child.kill().ok();
HwCodecConfig::refresh();
}
}
};
});
}