MCPcopy Create free account
hub / github.com/Recordscript/recordscript / start_check_process

Function start_check_process

libs/scrap/src/common/hwcodec.rs:530–581  ·  view source on GitHub ↗
(force: bool)

Source from the content-addressed store, hash-verified

528
529#[cfg(any(target_os = "windows", target_os = "linux"))]
530pub fn start_check_process(force: bool) {
531 if !force && !enable_hwcodec_option() {
532 return;
533 }
534 use hbb_common::allow_err;
535 use std::sync::Once;
536 let f = || {
537 // Clear to avoid checking process errors
538 // But when the program is just started, the configuration file has not been updated, and the new connection will read an empty configuration
539 // TODO: --server start multi times on windows startup, which will clear the last config and cause concurrent file writing
540 HwCodecConfig::clear();
541 if let Ok(exe) = std::env::current_exe() {
542 if let Some(_) = exe.file_name().to_owned() {
543 let arg = "--check-hwcodec-config";
544 if let Ok(mut child) = std::process::Command::new(exe).arg(arg).spawn() {
545 // wait up to 30 seconds, it maybe slow on windows startup for poorly performing machines
546 for _ in 0..30 {
547 std::thread::sleep(std::time::Duration::from_secs(1));
548 if let Ok(Some(_)) = child.try_wait() {
549 break;
550 }
551 }
552 allow_err!(child.kill());
553 std::thread::sleep(std::time::Duration::from_millis(30));
554 match child.try_wait() {
555 Ok(Some(status)) => {
556 log::info!("Check hwcodec config, exit with: {status}")
557 }
558 Ok(None) => {
559 log::info!(
560 "Check hwcodec config, status not ready yet, let's really wait"
561 );
562 let res = child.wait();
563 log::info!("Check hwcodec config, wait result: {res:?}");
564 }
565 Err(e) => {
566 log::error!("Check hwcodec config, error attempting to wait: {e}")
567 }
568 }
569 }
570 }
571 };
572 };
573 static ONCE: Once = Once::new();
574 if force && ONCE.is_completed() {
575 std::thread::spawn(f);
576 } else {
577 ONCE.call_once(|| {
578 std::thread::spawn(f);
579 });
580 }
581}

Callers

nothing calls this directly

Calls 3

enable_hwcodec_optionFunction · 0.85
sleepFunction · 0.85
file_nameMethod · 0.80

Tested by

no test coverage detected