mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
@@ -192,7 +192,10 @@ pub struct PeerConfig {
|
||||
deserialize_with = "PeerConfig::deserialize_image_quality"
|
||||
)]
|
||||
pub image_quality: String,
|
||||
#[serde(default)]
|
||||
#[serde(
|
||||
default = "PeerConfig::default_custom_image_quality",
|
||||
deserialize_with = "PeerConfig::deserialize_custom_image_quality"
|
||||
)]
|
||||
pub custom_image_quality: Vec<i32>,
|
||||
#[serde(default)]
|
||||
pub show_remote_cursor: bool,
|
||||
@@ -961,26 +964,51 @@ impl PeerConfig {
|
||||
serde_field_string!(
|
||||
default_view_style,
|
||||
deserialize_view_style,
|
||||
"original".to_owned()
|
||||
UserDefaultConfig::load().get("view_style")
|
||||
);
|
||||
serde_field_string!(
|
||||
default_scroll_style,
|
||||
deserialize_scroll_style,
|
||||
"scrollauto".to_owned()
|
||||
UserDefaultConfig::load().get("scroll_style")
|
||||
);
|
||||
serde_field_string!(
|
||||
default_image_quality,
|
||||
deserialize_image_quality,
|
||||
"balanced".to_owned()
|
||||
UserDefaultConfig::load().get("image_quality")
|
||||
);
|
||||
|
||||
fn default_custom_image_quality() -> Vec<i32> {
|
||||
let f: f64 = UserDefaultConfig::load()
|
||||
.get("custom_image_quality")
|
||||
.parse()
|
||||
.unwrap_or(50.0);
|
||||
vec![f as _]
|
||||
}
|
||||
|
||||
fn deserialize_custom_image_quality<'de, D>(deserializer: D) -> Result<Vec<i32>, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
let v: Vec<i32> = de::Deserialize::deserialize(deserializer)?;
|
||||
if v.len() == 1 && v[0] >= 10 && v[0] <= 100 {
|
||||
Ok(v)
|
||||
} else {
|
||||
Ok(Self::default_custom_image_quality())
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_options<'de, D>(deserializer: D) -> Result<HashMap<String, String>, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
let mut mp: HashMap<String, String> = de::Deserialize::deserialize(deserializer)?;
|
||||
if !mp.contains_key("codec-preference") {
|
||||
mp.insert("codec-preference".to_owned(), "auto".to_owned());
|
||||
let mut key = "codec-preference";
|
||||
if !mp.contains_key(key) {
|
||||
mp.insert(key.to_owned(), UserDefaultConfig::load().get(key));
|
||||
}
|
||||
key = "custom-fps";
|
||||
if !mp.contains_key(key) {
|
||||
mp.insert(key.to_owned(), UserDefaultConfig::load().get(key));
|
||||
}
|
||||
Ok(mp)
|
||||
}
|
||||
@@ -1192,6 +1220,73 @@ impl HwCodecConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct UserDefaultConfig {
|
||||
#[serde(default)]
|
||||
options: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl UserDefaultConfig {
|
||||
pub fn load() -> UserDefaultConfig {
|
||||
Config::load_::<UserDefaultConfig>("_default")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn store(&self) {
|
||||
Config::store_(self, "_default");
|
||||
}
|
||||
|
||||
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" => self.get_string(key, "auto", vec!["vp9", "h264", "h265"]),
|
||||
"custom_image_quality" => self.get_double_string(key, 50.0, 10.0, 100.0),
|
||||
"custom-fps" => self.get_double_string(key, 30.0, 10.0, 120.0),
|
||||
_ => self
|
||||
.options
|
||||
.get(key)
|
||||
.map(|v| v.to_string())
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, key: String, value: String) {
|
||||
self.options.insert(key, value);
|
||||
self.store();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_string(&self, key: &str, default: &str, others: Vec<&str>) -> String {
|
||||
match self.options.get(key) {
|
||||
Some(option) => {
|
||||
if others.contains(&option.as_str()) {
|
||||
option.to_owned()
|
||||
} else {
|
||||
default.to_owned()
|
||||
}
|
||||
}
|
||||
None => default.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_double_string(&self, key: &str, default: f64, min: f64, max: f64) -> String {
|
||||
match self.options.get(key) {
|
||||
Some(option) => {
|
||||
let v: f64 = option.parse().unwrap_or(default);
|
||||
if v >= min && v <= max {
|
||||
v.to_string()
|
||||
} else {
|
||||
default.to_string()
|
||||
}
|
||||
}
|
||||
None => default.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user