(force: bool)
| 528 | |
| 529 | #[cfg(any(target_os = "windows", target_os = "linux"))] |
| 530 | pub 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 | } |
nothing calls this directly
no test coverage detected