mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Remove some arc, and add some custom client
This commit is contained in:
@@ -1467,6 +1467,102 @@ impl ClipboardContext {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_custom_client() {
|
||||
let Ok(cmd) = std::env::current_exe() else {
|
||||
return;
|
||||
};
|
||||
let Some(path) = cmd.parent().map(|x| x.join("custom.txt")) else {
|
||||
return;
|
||||
};
|
||||
if path.is_file() {
|
||||
let Ok(data) = std::fs::read_to_string(&path) else {
|
||||
log::error!("Failed to read custom client config");
|
||||
return;
|
||||
};
|
||||
read_custom_client(&data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_custom_client(config: &str) {
|
||||
let Ok(data) = decode64(config) else {
|
||||
log::error!("Failed to decode custom client config");
|
||||
return;
|
||||
};
|
||||
const KEY: &str = "5Qbwsde3unUcJBtrx9ZkvUmwFNoExHzpryHuPUdqlWM=";
|
||||
let Some(pk) = get_rs_pk(KEY) else {
|
||||
log::error!("Failed to parse public key of custom client");
|
||||
return;
|
||||
};
|
||||
let Ok(data) = sign::verify(&data, &pk) else {
|
||||
log::error!("Failed to dec custom client config");
|
||||
return;
|
||||
};
|
||||
let Ok(mut data) =
|
||||
serde_json::from_slice::<std::collections::HashMap<String, serde_json::Value>>(&data)
|
||||
else {
|
||||
log::error!("Failed to parse custom client config");
|
||||
return;
|
||||
};
|
||||
if let Some(default_settings) = data.remove("default_settings") {
|
||||
if let Some(default_settings) = default_settings.as_object() {
|
||||
for (k, v) in default_settings {
|
||||
let Some(v) = v.as_str() else {
|
||||
continue;
|
||||
};
|
||||
if k.starts_with("$$") {
|
||||
config::DEFAULT_DISPLAY_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k.clone(), v[2..].to_owned());
|
||||
} else if k.starts_with("$") {
|
||||
config::DEFAULT_LOCAL_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k.clone(), v[1..].to_owned());
|
||||
} else {
|
||||
config::DEFAULT_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k.clone(), v.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(overwrite_settings) = data.remove("overwrite_settings") {
|
||||
if let Some(overwrite_settings) = overwrite_settings.as_object() {
|
||||
for (k, v) in overwrite_settings {
|
||||
let Some(v) = v.as_str() else {
|
||||
continue;
|
||||
};
|
||||
if k.starts_with("$$") {
|
||||
config::OVERWRITE_DISPLAY_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k.clone(), v[2..].to_owned());
|
||||
} else if k.starts_with("$") {
|
||||
config::OVERWRITE_LOCAL_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k.clone(), v[1..].to_owned());
|
||||
} else {
|
||||
config::OVERWRITE_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k.clone(), v.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (k, v) in data {
|
||||
if let Some(v) = v.as_str() {
|
||||
config::HARD_SETTINGS
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(k, v.to_owned());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -38,6 +38,7 @@ fn is_empty_uni_link(arg: &str) -> bool {
|
||||
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn core_main() -> Option<Vec<String>> {
|
||||
crate::load_custom_client();
|
||||
#[cfg(windows)]
|
||||
crate::platform::windows::bootstrap();
|
||||
let mut args = Vec::new();
|
||||
|
||||
@@ -1814,7 +1814,7 @@ pub fn main_support_remove_wallpaper() -> bool {
|
||||
}
|
||||
|
||||
pub fn is_qs() -> SyncReturn<bool> {
|
||||
SyncReturn(false)
|
||||
SyncReturn(get_hard_option("connection-type") == "incoming");
|
||||
}
|
||||
|
||||
/// Send a url scheme throught the ipc.
|
||||
@@ -2052,6 +2052,10 @@ pub fn main_has_valid_2fa_sync() -> SyncReturn<bool> {
|
||||
SyncReturn(has_valid_2fa())
|
||||
}
|
||||
|
||||
pub fn main_get_hard_option(key: String) -> SyncReturn<String> {
|
||||
SyncReturn(get_hard_option(key))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub mod server_side {
|
||||
use hbb_common::{config, log};
|
||||
|
||||
@@ -3,8 +3,9 @@ use hbb_common::password_security;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
bytes::Bytes,
|
||||
config::{self, Config, LocalConfig, PeerConfig},
|
||||
config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT},
|
||||
config::{
|
||||
self, Config, LocalConfig, PeerConfig, CONNECT_TIMEOUT, HARD_SETTINGS, RENDEZVOUS_PORT,
|
||||
},
|
||||
directories_next,
|
||||
futures::future::join_all,
|
||||
log,
|
||||
@@ -171,6 +172,16 @@ pub fn get_local_option(key: String) -> String {
|
||||
LocalConfig::get_option(&key)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_hard_option(key: String) -> String {
|
||||
config::HARD_SETTINGS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&key)
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_local_option(key: String, value: String) {
|
||||
LocalConfig::set_option(key, value);
|
||||
|
||||
Reference in New Issue
Block a user