diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 9354b4079..5fc974462 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -50,6 +50,7 @@ lazy_static::lazy_static! { pub static ref PROD_RENDEZVOUS_SERVER: Arc> = Default::default(); pub static ref APP_NAME: Arc> = Arc::new(RwLock::new("RustDesk".to_owned())); static ref KEY_PAIR: Arc, Vec)>>> = Default::default(); + static ref HW_CODEC_CONFIG: Arc> = Arc::new(RwLock::new(HwCodecConfig::load())); } // #[cfg(any(target_os = "android", target_os = "ios"))] @@ -1023,6 +1024,16 @@ impl HwCodecConfig { pub fn remove() { std::fs::remove_file(Config::file_("_hwcodec")).ok(); } + + /// refresh current global HW_CODEC_CONFIG, usually uesd after HwCodecConfig::remove() + pub fn refresh() { + *HW_CODEC_CONFIG.write().unwrap() = HwCodecConfig::load(); + log::debug!("HW_CODEC_CONFIG refreshed successfully"); + } + + pub fn get() -> HwCodecConfig { + return HW_CODEC_CONFIG.read().unwrap().clone(); + } } #[cfg(test)] diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs index ee81627d8..4fdef5462 100644 --- a/libs/scrap/src/common/hwcodec.rs +++ b/libs/scrap/src/common/hwcodec.rs @@ -267,7 +267,7 @@ impl HwDecoderImage<'_> { } fn get_config(k: &str) -> ResultType { - let v = HwCodecConfig::load() + let v = HwCodecConfig::get() .options .get(k) .unwrap_or(&"".to_owned()) @@ -323,7 +323,8 @@ pub fn check_config_process(force_reset: bool) { std::process::Command::new(exe) .arg("--check-hwcodec-config") .status() - .ok() + .ok(); + HwCodecConfig::refresh(); }); }; }