Fix/custom client advanced settings (#8066)

* fix: custom client, advanced settings

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* refact: custom client, default options

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* fix: cargo test

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* refact: remove prefix $ and unify option keys

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* refact: custom client, advanced options

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* debug custom client, advanced settings

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* custom client, advanced settings. Add filter-transfer to display settings

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* custom client, advanced settings

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* fix: custom client, advanced settings, codec

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* fix: custom client, advanced settings, whitelist

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-05-17 14:19:11 +08:00
committed by GitHub
parent 3a4390e0c7
commit 8357d4675a
18 changed files with 707 additions and 364 deletions

View File

@@ -916,7 +916,7 @@ impl Config {
#[inline]
fn purify_options(v: &mut HashMap<String, String>) {
v.retain(|k, v| is_option_can_save(&OVERWRITE_SETTINGS, &DEFAULT_SETTINGS, k, v));
v.retain(|k, _| is_option_can_save(&OVERWRITE_SETTINGS, k));
}
pub fn set_options(mut v: HashMap<String, String>) {
@@ -940,7 +940,7 @@ impl Config {
}
pub fn set_option(k: String, v: String) {
if !is_option_can_save(&OVERWRITE_SETTINGS, &DEFAULT_SETTINGS, &k, &v) {
if !is_option_can_save(&OVERWRITE_SETTINGS, &k) {
return;
}
let mut config = CONFIG2.write().unwrap();
@@ -1194,36 +1194,36 @@ impl PeerConfig {
serde_field_string!(
default_view_style,
deserialize_view_style,
UserDefaultConfig::read("view_style")
UserDefaultConfig::read(keys::OPTION_VIEW_STYLE)
);
serde_field_string!(
default_scroll_style,
deserialize_scroll_style,
UserDefaultConfig::read("scroll_style")
UserDefaultConfig::read(keys::OPTION_SCROLL_STYLE)
);
serde_field_string!(
default_image_quality,
deserialize_image_quality,
UserDefaultConfig::read("image_quality")
UserDefaultConfig::read(keys::OPTION_IMAGE_QUALITY)
);
serde_field_string!(
default_reverse_mouse_wheel,
deserialize_reverse_mouse_wheel,
UserDefaultConfig::read("reverse_mouse_wheel")
UserDefaultConfig::read(keys::OPTION_REVERSE_MOUSE_WHEEL)
);
serde_field_string!(
default_displays_as_individual_windows,
deserialize_displays_as_individual_windows,
UserDefaultConfig::read("displays_as_individual_windows")
UserDefaultConfig::read(keys::OPTION_DISPLAYS_AS_INDIVIDUAL_WINDOWS)
);
serde_field_string!(
default_use_all_my_displays_for_the_remote_session,
deserialize_use_all_my_displays_for_the_remote_session,
UserDefaultConfig::read("use_all_my_displays_for_the_remote_session")
UserDefaultConfig::read(keys::OPTION_USE_ALL_MY_DISPLAYS_FOR_THE_REMOTE_SESSION)
);
fn default_custom_image_quality() -> Vec<i32> {
let f: f64 = UserDefaultConfig::read("custom_image_quality")
let f: f64 = UserDefaultConfig::read(keys::OPTION_CUSTOM_IMAGE_QUALITY)
.parse()
.unwrap_or(50.0);
vec![f as _]
@@ -1244,12 +1244,12 @@ impl PeerConfig {
fn default_options() -> HashMap<String, String> {
let mut mp: HashMap<String, String> = Default::default();
[
"codec-preference",
"custom-fps",
"zoom-cursor",
"touch-mode",
"i444",
"swap-left-right-mouse",
keys::OPTION_CODEC_PREFERENCE,
keys::OPTION_CUSTOM_FPS,
keys::OPTION_ZOOM_CURSOR,
keys::OPTION_TOUCH_MODE,
keys::OPTION_I444,
keys::OPTION_SWAP_LEFT_RIGHT_MOUSE,
]
.map(|key| {
mp.insert(key.to_owned(), UserDefaultConfig::read(key));
@@ -1415,10 +1415,17 @@ impl LocalConfig {
}
pub fn set_option(k: String, v: String) {
if !is_option_can_save(&OVERWRITE_LOCAL_SETTINGS, &DEFAULT_LOCAL_SETTINGS, &k, &v) {
if !is_option_can_save(&OVERWRITE_LOCAL_SETTINGS, &k) {
return;
}
let mut config = LOCAL_CONFIG.write().unwrap();
// The custom client will explictly set "default" as the default language.
let is_custom_client_default_lang = k == keys::OPTION_LANGUAGE && v == "default";
if is_custom_client_default_lang {
config.options.insert(k, "".to_owned());
config.store();
return;
}
let v2 = if v.is_empty() { None } else { Some(&v) };
if v2 != config.options.get(&k) {
if v2.is_none() {
@@ -1572,15 +1579,19 @@ impl UserDefaultConfig {
pub fn get(&self, key: &str) -> String {
match key {
"view_style" => self.get_string(key, "original", vec!["adaptive"]),
"scroll_style" => self.get_string(key, "scrollauto", vec!["scrollbar"]),
"image_quality" => self.get_string(key, "balanced", vec!["best", "low", "custom"]),
"codec-preference" => {
keys::OPTION_VIEW_STYLE => self.get_string(key, "original", vec!["adaptive"]),
keys::OPTION_SCROLL_STYLE => self.get_string(key, "scrollauto", vec!["scrollbar"]),
keys::OPTION_IMAGE_QUALITY => {
self.get_string(key, "balanced", vec!["best", "low", "custom"])
}
keys::OPTION_CODEC_PREFERENCE => {
self.get_string(key, "auto", vec!["vp8", "vp9", "av1", "h264", "h265"])
}
"custom_image_quality" => self.get_double_string(key, 50.0, 10.0, 0xFFF as f64),
"custom-fps" => self.get_double_string(key, 30.0, 5.0, 120.0),
"enable_file_transfer" => self.get_string(key, "Y", vec![""]),
keys::OPTION_CUSTOM_IMAGE_QUALITY => {
self.get_double_string(key, 50.0, 10.0, 0xFFF as f64)
}
keys::OPTION_CUSTOM_FPS => self.get_double_string(key, 30.0, 5.0, 120.0),
keys::OPTION_ENABLE_FILE_TRANSFER => self.get_string(key, "Y", vec!["", "N"]),
_ => self
.get_after(key)
.map(|v| v.to_string())
@@ -1589,12 +1600,7 @@ impl UserDefaultConfig {
}
pub fn set(&mut self, key: String, value: String) {
if !is_option_can_save(
&OVERWRITE_DISPLAY_SETTINGS,
&DEFAULT_DISPLAY_SETTINGS,
&key,
&value,
) {
if !is_option_can_save(&OVERWRITE_DISPLAY_SETTINGS, &key) {
return;
}
if value.is_empty() {
@@ -1917,18 +1923,10 @@ fn get_or(
}
#[inline]
fn is_option_can_save(
overwrite: &RwLock<HashMap<String, String>>,
defaults: &RwLock<HashMap<String, String>>,
k: &str,
v: &str,
) -> bool {
fn is_option_can_save(overwrite: &RwLock<HashMap<String, String>>, k: &str) -> bool {
if overwrite.read().unwrap().contains_key(k) {
return false;
}
if defaults.read().unwrap().get(k).map_or(false, |x| x == v) {
return false;
}
true
}
@@ -1984,6 +1982,136 @@ pub fn is_disable_installation() -> bool {
is_some_hard_opton("disable-installation")
}
pub mod keys {
pub const OPTION_VIEW_ONLY: &str = "view_only";
pub const OPTION_SHOW_MONITORS_TOOLBAR: &str = "show_monitors_toolbar";
pub const OPTION_COLLAPSE_TOOLBAR: &str = "collapse_toolbar";
pub const OPTION_SHOW_REMOTE_CURSOR: &str = "show_remote_cursor";
pub const OPTION_FOLLOW_REMOTE_CURSOR: &str = "follow_remote_cursor";
pub const OPTION_FOLLOW_REMOTE_WINDOW: &str = "follow_remote_window";
pub const OPTION_ZOOM_CURSOR: &str = "zoom-cursor";
pub const OPTION_SHOW_QUALITY_MONITOR: &str = "show_quality_monitor";
pub const OPTION_DISABLE_AUDIO: &str = "disable_audio";
pub const OPTION_DISABLE_CLIPBOARD: &str = "disable_clipboard";
pub const OPTION_LOCK_AFTER_SESSION_END: &str = "lock_after_session_end";
pub const OPTION_PRIVACY_MODE: &str = "privacy_mode";
pub const OPTION_TOUCH_MODE: &str = "touch-mode";
pub const OPTION_I444: &str = "i444";
pub const OPTION_REVERSE_MOUSE_WHEEL: &str = "reverse_mouse_wheel";
pub const OPTION_SWAP_LEFT_RIGHT_MOUSE: &str = "swap-left-right-mouse";
pub const OPTION_DISPLAYS_AS_INDIVIDUAL_WINDOWS: &str = "displays_as_individual_windows";
pub const OPTION_USE_ALL_MY_DISPLAYS_FOR_THE_REMOTE_SESSION: &str =
"use_all_my_displays_for_the_remote_session";
pub const OPTION_VIEW_STYLE: &str = "view_style";
pub const OPTION_SCROLL_STYLE: &str = "scroll_style";
pub const OPTION_IMAGE_QUALITY: &str = "image_quality";
pub const OPTION_CUSTOM_IMAGE_QUALITY: &str = "custom_image_quality";
pub const OPTION_CUSTOM_FPS: &str = "custom-fps";
pub const OPTION_CODEC_PREFERENCE: &str = "codec-preference";
pub const OPTION_THEME: &str = "theme";
pub const OPTION_LANGUAGE: &str = "lang";
pub const OPTION_ENABLE_CONFIRM_CLOSING_TABS: &str = "enable-confirm-closing-tabs";
pub const OPTION_ENABLE_OPEN_NEW_CONNECTIONS_IN_TABS: &str =
"enable-open-new-connections-in-tabs";
pub const OPTION_ENABLE_CHECK_UPDATE: &str = "enable-check-update";
pub const OPTION_SYNC_AB_WITH_RECENT_SESSIONS: &str = "sync-ab-with-recent-sessions";
pub const OPTION_SYNC_AB_TAGS: &str = "sync-ab-tags";
pub const OPTION_FILTER_AB_BY_INTERSECTION: &str = "filter-ab-by-intersection";
pub const OPTION_ACCESS_MODE: &str = "access-mode";
pub const OPTION_ENABLE_KEYBOARD: &str = "enable-keyboard";
pub const OPTION_ENABLE_CLIPBOARD: &str = "enable-clipboard";
pub const OPTION_ENABLE_FILE_TRANSFER: &str = "enable-file-transfer";
pub const OPTION_ENABLE_AUDIO: &str = "enable-audio";
pub const OPTION_ENABLE_TUNNEL: &str = "enable-tunnel";
pub const OPTION_ENABLE_REMOTE_RESTART: &str = "enable-remote-restart";
pub const OPTION_ENABLE_RECORD_SESSION: &str = "enable-record-session";
pub const OPTION_ENABLE_BLOCK_INPUT: &str = "enable-block-input";
pub const OPTION_ALLOW_REMOTE_CONFIG_MODIFICATION: &str = "allow-remote-config-modification";
pub const OPTION_ENABLE_LAN_DISCOVERY: &str = "enable-lan-discovery";
pub const OPTION_DIRECT_SERVER: &str = "direct-server";
pub const OPTION_DIRECT_ACCESS_PORT: &str = "direct-access-port";
pub const OPTION_WHITELIST: &str = "whitelist";
pub const OPTION_ALLOW_AUTO_DISCONNECT: &str = "allow-auto-disconnect";
pub const OPTION_AUTO_DISCONNECT_TIMEOUT: &str = "auto-disconnect-timeout";
pub const OPTION_ALLOW_ONLY_CONN_WINDOW_OPEN: &str = "allow-only-conn-window-open";
pub const OPTION_ALLOW_AUTO_RECORD_INCOMING: &str = "allow-auto-record-incoming";
pub const OPTION_VIDEO_SAVE_DIRECTORY: &str = "video-save-directory";
pub const OPTION_ENABLE_ABR: &str = "enable-abr";
pub const OPTION_ALLOW_REMOVE_WALLPAPER: &str = "allow-remove-wallpaper";
pub const OPTION_ALLOW_ALWAYS_SOFTWARE_RENDER: &str = "allow-always-software-render";
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";
// DEFAULT_DISPLAY_SETTINGS, OVERWRITE_DISPLAY_SETTINGS
pub const KEYS_DISPLAY_SETTINGS: &[&str] = &[
OPTION_VIEW_ONLY,
OPTION_SHOW_MONITORS_TOOLBAR,
OPTION_COLLAPSE_TOOLBAR,
OPTION_SHOW_REMOTE_CURSOR,
OPTION_FOLLOW_REMOTE_CURSOR,
OPTION_FOLLOW_REMOTE_WINDOW,
OPTION_ZOOM_CURSOR,
OPTION_SHOW_QUALITY_MONITOR,
OPTION_DISABLE_AUDIO,
OPTION_ENABLE_FILE_TRANSFER,
OPTION_DISABLE_CLIPBOARD,
OPTION_LOCK_AFTER_SESSION_END,
OPTION_PRIVACY_MODE,
OPTION_TOUCH_MODE,
OPTION_I444,
OPTION_REVERSE_MOUSE_WHEEL,
OPTION_SWAP_LEFT_RIGHT_MOUSE,
OPTION_DISPLAYS_AS_INDIVIDUAL_WINDOWS,
OPTION_USE_ALL_MY_DISPLAYS_FOR_THE_REMOTE_SESSION,
OPTION_VIEW_STYLE,
OPTION_SCROLL_STYLE,
OPTION_IMAGE_QUALITY,
OPTION_CUSTOM_IMAGE_QUALITY,
OPTION_CUSTOM_FPS,
OPTION_CODEC_PREFERENCE,
];
// DEFAULT_LOCAL_SETTINGS, OVERWRITE_LOCAL_SETTINGS
pub const KEYS_LOCAL_SETTINGS: &[&str] = &[
OPTION_THEME,
OPTION_LANGUAGE,
OPTION_ENABLE_CONFIRM_CLOSING_TABS,
OPTION_ENABLE_OPEN_NEW_CONNECTIONS_IN_TABS,
OPTION_ENABLE_CHECK_UPDATE,
OPTION_SYNC_AB_WITH_RECENT_SESSIONS,
OPTION_SYNC_AB_TAGS,
OPTION_FILTER_AB_BY_INTERSECTION,
];
// DEFAULT_SETTINGS, OVERWRITE_SETTINGS
pub const KEYS_SETTINGS: &[&str] = &[
OPTION_ACCESS_MODE,
OPTION_ENABLE_KEYBOARD,
OPTION_ENABLE_CLIPBOARD,
OPTION_ENABLE_FILE_TRANSFER,
OPTION_ENABLE_AUDIO,
OPTION_ENABLE_TUNNEL,
OPTION_ENABLE_REMOTE_RESTART,
OPTION_ENABLE_RECORD_SESSION,
OPTION_ENABLE_BLOCK_INPUT,
OPTION_ALLOW_REMOTE_CONFIG_MODIFICATION,
OPTION_ENABLE_LAN_DISCOVERY,
OPTION_DIRECT_SERVER,
OPTION_DIRECT_ACCESS_PORT,
OPTION_WHITELIST,
OPTION_ALLOW_AUTO_DISCONNECT,
OPTION_AUTO_DISCONNECT_TIMEOUT,
OPTION_ALLOW_ONLY_CONN_WINDOW_OPEN,
OPTION_ALLOW_AUTO_RECORD_INCOMING,
OPTION_VIDEO_SAVE_DIRECTORY,
OPTION_ENABLE_ABR,
OPTION_ALLOW_REMOVE_WALLPAPER,
OPTION_ALLOW_ALWAYS_SOFTWARE_RENDER,
OPTION_ALLOW_LINUX_HEADLESS,
OPTION_ENABLE_HWCODEC,
OPTION_APPROVE_MODE,
];
}
#[cfg(test)]
mod tests {
use super::*;
@@ -2022,6 +2150,10 @@ mod tests {
.write()
.unwrap()
.insert("b".to_string(), "c".to_string());
OVERWRITE_SETTINGS
.write()
.unwrap()
.insert("c".to_string(), "f".to_string());
OVERWRITE_SETTINGS
.write()
.unwrap()
@@ -2042,7 +2174,7 @@ mod tests {
res.insert("d".to_owned(), "c".to_string());
res.insert("c".to_owned(), "a".to_string());
res.insert("f".to_owned(), "a".to_string());
res.insert("c".to_owned(), "d".to_string());
res.insert("e".to_owned(), "d".to_string());
Config::purify_options(&mut res);
assert!(res.len() == 2);
res.insert("b".to_owned(), "c".to_string());
@@ -2055,11 +2187,11 @@ mod tests {
assert!(res.len() == 2);
let res = Config::get_options();
assert!(res["a"] == "b");
assert!(res["c"] == "a");
assert!(res["c"] == "f");
assert!(res["b"] == "c");
assert!(res["d"] == "c");
assert!(Config::get_option("a") == "b");
assert!(Config::get_option("c") == "a");
assert!(Config::get_option("c") == "f");
assert!(Config::get_option("b") == "c");
assert!(Config::get_option("d") == "c");
DEFAULT_SETTINGS.write().unwrap().clear();