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

2
Cargo.lock generated
View File

@ -2623,6 +2623,7 @@ dependencies = [
"serde_json 1.0.89",
"socket2 0.3.19",
"sodiumoxide",
"sysinfo",
"tokio",
"tokio-socks",
"tokio-util",
@ -4887,7 +4888,6 @@ dependencies = [
"shutdown_hooks",
"simple_rc",
"sys-locale",
"sysinfo",
"system_shutdown",
"tao",
"tray-icon",

View File

@ -55,7 +55,6 @@ uuid = { version = "1.0", features = ["v4"] }
clap = "3.0"
rpassword = "7.0"
base64 = "0.13"
sysinfo = "0.24"
num_cpus = "1.13"
bytes = { version = "1.2", features = ["serde"] }
default-net = "0.12.0"

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();
}
}
};
});
}

View File

@ -549,7 +549,7 @@ async fn check_pid(postfix: &str) {
file.read_to_string(&mut content).ok();
let pid = content.parse::<i32>().unwrap_or(0);
if pid > 0 {
use sysinfo::{ProcessExt, System, SystemExt};
use hbb_common::sysinfo::{ProcessExt, System, SystemExt};
let mut sys = System::new();
sys.refresh_processes();
if let Some(p) = sys.process(pid.into()) {

View File

@ -558,7 +558,7 @@ pub fn hide_dock() {
}
fn check_main_window() -> bool {
use sysinfo::{ProcessExt, System, SystemExt};
use hbb_common::sysinfo::{ProcessExt, System, SystemExt};
let mut sys = System::new();
sys.refresh_processes();
let app = format!("/Applications/{}.app", crate::get_app_name());