buildin options and add to mobile (#8759)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-07-19 23:55:52 +08:00
committed by GitHub
parent 85ded0a3e5
commit 2b54a553c7
14 changed files with 114 additions and 38 deletions

View File

@@ -60,7 +60,7 @@ use crate::{
check_port,
common::input::{MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP},
create_symmetric_key_msg, decode_id_pk, get_rs_pk, is_keyboard_mode_supported, secure_tcp,
ui_interface::use_texture_render,
ui_interface::{get_buildin_option, use_texture_render},
ui_session_interface::{InvokeUiSession, Session},
};
@@ -2027,7 +2027,7 @@ impl LoginConfigHandler {
} else {
(my_id, self.id.clone())
};
let mut display_name = LocalConfig::get_option(&config::keys::OPTION_DISPLAY_NAME);
let mut display_name = get_buildin_option(config::keys::OPTION_DISPLAY_NAME);
if display_name.is_empty() {
display_name = crate::username();
}

View File

@@ -1341,6 +1341,7 @@ fn read_custom_client_advanced_settings(
map_display_settings: &HashMap<String, &&str>,
map_local_settings: &HashMap<String, &&str>,
map_settings: &HashMap<String, &&str>,
map_buildin_settings: &HashMap<String, &&str>,
is_override: bool,
) {
let mut display_settings = if is_override {
@@ -1358,6 +1359,8 @@ fn read_custom_client_advanced_settings(
} else {
config::DEFAULT_SETTINGS.write().unwrap()
};
let mut buildin_settings = config::BUILDIN_SETTINGS.write().unwrap();
if let Some(settings) = settings.as_object() {
for (k, v) in settings {
let Some(v) = v.as_str() else {
@@ -1369,6 +1372,8 @@ fn read_custom_client_advanced_settings(
local_settings.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_settings.get(k) {
server_settings.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_buildin_settings.get(k) {
buildin_settings.insert(k2.to_string(), v.to_owned());
} else {
let k2 = k.replace("_", "-");
let k = k2.replace("-", "_");
@@ -1381,6 +1386,9 @@ fn read_custom_client_advanced_settings(
// server
server_settings.insert(k.clone(), v.to_owned());
server_settings.insert(k2.clone(), v.to_owned());
// buildin
buildin_settings.insert(k.clone(), v.to_owned());
buildin_settings.insert(k2.clone(), v.to_owned());
}
}
}
@@ -1443,12 +1451,17 @@ pub fn read_custom_client(config: &str) {
for s in config::keys::KEYS_SETTINGS {
map_settings.insert(s.replace("_", "-"), s);
}
let mut buildin_settings = HashMap::new();
for s in config::keys::KEYS_BUILDIN_SETTINGS {
buildin_settings.insert(s.replace("_", "-"), s);
}
if let Some(default_settings) = data.remove("default-settings") {
read_custom_client_advanced_settings(
default_settings,
&map_display_settings,
&map_local_settings,
&map_settings,
&buildin_settings,
false,
);
}
@@ -1458,6 +1471,7 @@ pub fn read_custom_client(config: &str) {
&map_display_settings,
&map_local_settings,
&map_settings,
&buildin_settings,
true,
);
}

View File

@@ -2213,6 +2213,10 @@ pub fn main_get_hard_option(key: String) -> SyncReturn<String> {
SyncReturn(get_hard_option(key))
}
pub fn main_get_buildin_option(key: String) -> SyncReturn<String> {
SyncReturn(get_buildin_option(&key))
}
pub fn main_check_hwcodec() {
check_hwcodec()
}

View File

@@ -5,7 +5,7 @@ use std::{
};
#[cfg(not(any(target_os = "ios")))]
use crate::Connection;
use crate::{ui_interface::get_buildin_option, Connection};
use hbb_common::{
config::{keys, Config, LocalConfig},
tokio::{self, sync::broadcast, time::Instant},
@@ -91,11 +91,11 @@ async fn start_hbbs_sync_async() {
if !ab_tag.is_empty() {
v[keys::OPTION_PRESET_ADDRESS_BOOK_TAG] = json!(ab_tag);
}
let username = Config::get_option(keys::OPTION_PRESET_USERNAME);
let username = get_buildin_option(keys::OPTION_PRESET_USERNAME);
if !username.is_empty() {
v[keys::OPTION_PRESET_USERNAME] = json!(username);
}
let strategy_name = Config::get_option(keys::OPTION_PRESET_STRATEGY_NAME);
let strategy_name = get_buildin_option(keys::OPTION_PRESET_STRATEGY_NAME);
if !strategy_name.is_empty() {
v[keys::OPTION_PRESET_STRATEGY_NAME] = json!(strategy_name);
}

View File

@@ -29,6 +29,7 @@ use hbb_common::{
use crate::{
check_port,
server::{check_zombie, new as new_server, ServerPtr},
ui_interface::get_buildin_option,
};
type Message = RendezvousMessage;
@@ -387,7 +388,7 @@ impl RendezvousMediator {
};
if (cfg!(debug_assertions) && option_env!("TEST_TCP").is_some())
|| is_http_proxy
|| Config::get_option(config::keys::OPTION_DISABLE_UDP) == "Y"
|| get_buildin_option(config::keys::OPTION_DISABLE_UDP) == "Y"
{
Self::start_tcp(server, host).await
} else {

View File

@@ -202,6 +202,16 @@ pub fn get_hard_option(key: String) -> String {
.unwrap_or_default()
}
#[inline]
pub fn get_buildin_option(key: &str) -> String {
config::BUILDIN_SETTINGS
.read()
.unwrap()
.get(key)
.cloned()
.unwrap_or_default()
}
#[inline]
pub fn set_local_option(key: String, value: String) {
LocalConfig::set_option(key, value);