From cd3db3a6864ebc2bbc49d6abcd3390420c8add30 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Tue, 11 Jun 2024 19:51:11 +0800 Subject: [PATCH] try to fix https://github.com/rustdesk/rustdesk-server-pro/issues/266 --- libs/hbb_common/src/config.rs | 50 ++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index cd5d4c565..d2f568fd4 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -912,7 +912,7 @@ impl Config { #[inline] fn purify_options(v: &mut HashMap) { - v.retain(|k, _| is_option_can_save(&OVERWRITE_SETTINGS, k)); + v.retain(|k, v| is_option_can_save(&OVERWRITE_SETTINGS, k, &DEFAULT_SETTINGS, v)); } pub fn set_options(mut v: HashMap) { @@ -936,7 +936,7 @@ impl Config { } pub fn set_option(k: String, v: String) { - if !is_option_can_save(&OVERWRITE_SETTINGS, &k) { + if !is_option_can_save(&OVERWRITE_SETTINGS, &k, &DEFAULT_SETTINGS, &v) { return; } let mut config = CONFIG2.write().unwrap(); @@ -1449,7 +1449,7 @@ impl LocalConfig { } pub fn set_option(k: String, v: String) { - if !is_option_can_save(&OVERWRITE_LOCAL_SETTINGS, &k) { + if !is_option_can_save(&OVERWRITE_LOCAL_SETTINGS, &k, &DEFAULT_LOCAL_SETTINGS, &v) { return; } let mut config = LOCAL_CONFIG.write().unwrap(); @@ -1636,7 +1636,12 @@ impl UserDefaultConfig { } pub fn set(&mut self, key: String, value: String) { - if !is_option_can_save(&OVERWRITE_DISPLAY_SETTINGS, &key) { + if !is_option_can_save( + &OVERWRITE_DISPLAY_SETTINGS, + &key, + &DEFAULT_DISPLAY_SETTINGS, + &value, + ) { return; } if value.is_empty() { @@ -1959,8 +1964,15 @@ fn get_or( } #[inline] -fn is_option_can_save(overwrite: &RwLock>, k: &str) -> bool { - if overwrite.read().unwrap().contains_key(k) { +fn is_option_can_save( + overwrite: &RwLock>, + k: &str, + defaults: &RwLock>, + v: &str, +) -> bool { + if overwrite.read().unwrap().contains_key(k) + || defaults.read().unwrap().get(k).map_or(false, |x| x == v) + { return false; } true @@ -2100,6 +2112,11 @@ pub mod keys { pub const OPTION_ALLOW_LINUX_HEADLESS: &str = "allow-linux-headless"; pub const OPTION_ENABLE_HWCODEC: &str = "enable-hwcodec"; pub const OPTION_APPROVE_MODE: &str = "approve-mode"; + pub const OPTION_CUSTOM_RENDEZVOUS_SERVER: &str = "custom-rendezvous-server"; + pub const OPTION_API_SERVER: &str = "api-server"; + pub const OPTION_KEY: &str = "key"; + pub const OPTION_PRESET_ADDRESS_BOOK_NAME: &str = "preset-address-book-name"; + pub const OPTION_PRESET_ADDRESS_BOOK_TAG: &str = "preset-address-book-tag"; // flutter local options pub const OPTION_FLUTTER_REMOTE_MENUBAR_STATE: &str = "remoteMenubarState"; @@ -2117,6 +2134,9 @@ pub mod keys { pub const OPTION_FLOATING_WINDOW_TRANSPARENCY: &str = "floating-window-transparency"; pub const OPTION_FLOATING_WINDOW_SVG: &str = "floating-window-svg"; + pub const OPTION_DISABLE_GROUP_PANEL: &str = "disable-group-panel"; + pub const OPTION_PRE_ELEVATE_SERVICE: &str = "pre-elevate-service"; + // proxy settings // The following options are not real keys, they are just used for custom client advanced settings. // The real keys are in Config2::socks. @@ -2177,6 +2197,8 @@ pub mod keys { OPTION_FLOATING_WINDOW_UNTOUCHABLE, OPTION_FLOATING_WINDOW_TRANSPARENCY, OPTION_FLOATING_WINDOW_SVG, + OPTION_DISABLE_GROUP_PANEL, + OPTION_PRE_ELEVATE_SERVICE, ]; // DEFAULT_SETTINGS, OVERWRITE_SETTINGS pub const KEYS_SETTINGS: &[&str] = &[ @@ -2208,6 +2230,11 @@ pub mod keys { OPTION_PROXY_URL, OPTION_PROXY_USERNAME, OPTION_PROXY_PASSWORD, + OPTION_CUSTOM_RENDEZVOUS_SERVER, + OPTION_API_SERVER, + OPTION_KEY, + OPTION_PRESET_ADDRESS_BOOK_NAME, + OPTION_PRESET_ADDRESS_BOOK_TAG, ]; } @@ -2283,7 +2310,18 @@ mod tests { res.insert("c".to_owned(), "d".to_string()); res.insert("d".to_owned(), "cc".to_string()); Config::purify_options(&mut res); + DEFAULT_SETTINGS + .write() + .unwrap() + .insert("f".to_string(), "c".to_string()); + Config::purify_options(&mut res); assert!(res.len() == 2); + DEFAULT_SETTINGS + .write() + .unwrap() + .insert("f".to_string(), "a".to_string()); + Config::purify_options(&mut res); + assert!(res.len() == 1); let res = Config::get_options(); assert!(res["a"] == "b"); assert!(res["c"] == "f");