refact: custom client, more advanced settings (#8085)

* refact: custom client, more advanced settings

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

* feat: custom client, more advanced settings

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

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-05-18 23:13:54 +08:00
committed by GitHub
parent c2b7810c33
commit 96f41fcc02
34 changed files with 356 additions and 258 deletions

View File

@@ -1503,9 +1503,9 @@ impl LoginConfigHandler {
BoolOption::Yes
})
.into();
} else if name == "enable-file-transfer" {
config.enable_file_transfer.v = !config.enable_file_transfer.v;
option.enable_file_transfer = (if config.enable_file_transfer.v {
} else if name == "enable-file-copy-paste" {
config.enable_file_copy_paste.v = !config.enable_file_copy_paste.v;
option.enable_file_transfer = (if config.enable_file_copy_paste.v {
BoolOption::Yes
} else {
BoolOption::No
@@ -1538,7 +1538,7 @@ impl LoginConfigHandler {
option.disable_keyboard = f(false);
option.disable_clipboard = f(self.get_toggle_option("disable-clipboard"));
option.show_remote_cursor = f(self.get_toggle_option("show-remote-cursor"));
option.enable_file_transfer = f(self.config.enable_file_transfer.v);
option.enable_file_transfer = f(self.config.enable_file_copy_paste.v);
option.lock_after_session_end = f(self.config.lock_after_session_end.v);
}
} else {
@@ -1631,7 +1631,7 @@ impl LoginConfigHandler {
if self.get_toggle_option("disable-audio") {
msg.disable_audio = BoolOption::Yes.into();
}
if !view_only && self.get_toggle_option("enable-file-transfer") {
if !view_only && self.get_toggle_option(config::keys::OPTION_ENABLE_FILE_COPY_PASTE) {
msg.enable_file_transfer = BoolOption::Yes.into();
}
if view_only || self.get_toggle_option("disable-clipboard") {
@@ -1704,8 +1704,8 @@ impl LoginConfigHandler {
self.config.lock_after_session_end.v
} else if name == "privacy-mode" {
self.config.privacy_mode.v
} else if name == "enable-file-transfer" {
self.config.enable_file_transfer.v
} else if name == config::keys::OPTION_ENABLE_FILE_COPY_PASTE {
self.config.enable_file_copy_paste.v
} else if name == "disable-audio" {
self.config.disable_audio.v
} else if name == "disable-clipboard" {

View File

@@ -319,8 +319,13 @@ impl<T: InvokeUiSession> Remote<T> {
let is_stopping_allowed = clip.is_stopping_allowed();
let server_file_transfer_enabled =
*self.handler.server_file_transfer_enabled.read().unwrap();
let file_transfer_enabled =
self.handler.lc.read().unwrap().enable_file_transfer.v;
let file_transfer_enabled = self
.handler
.lc
.read()
.unwrap()
.enable_file_copy_paste
.v;
let view_only = self.handler.lc.read().unwrap().view_only.v;
let stop = is_stopping_allowed
&& (view_only
@@ -1760,7 +1765,13 @@ impl<T: InvokeUiSession> Remote<T> {
))]
{
let enabled = *self.handler.server_file_transfer_enabled.read().unwrap()
&& self.handler.lc.read().unwrap().enable_file_transfer.v;
&& self
.handler
.lc
.read()
.unwrap()
.enable_file_copy_paste
.v;
ContextSend::enable(enabled);
}
}
@@ -1783,7 +1794,13 @@ impl<T: InvokeUiSession> Remote<T> {
};
let is_stopping_allowed = clip.is_stopping_allowed_from_peer();
let file_transfer_enabled = self.handler.lc.read().unwrap().enable_file_transfer.v;
let file_transfer_enabled = self
.handler
.lc
.read()
.unwrap()
.enable_file_copy_paste
.v;
let stop = is_stopping_allowed && !file_transfer_enabled;
log::debug!(
"Process clipboard message from server peer, stop: {}, is_stopping_allowed: {}, file_transfer_enabled: {}",

View File

@@ -1572,6 +1572,56 @@ pub fn load_custom_client() {
}
}
fn read_custom_client_advanced_settings(
settings: serde_json::Value,
map_display_settings: &HashMap<String, &&str>,
map_local_settings: &HashMap<String, &&str>,
map_settings: &HashMap<String, &&str>,
is_override: bool,
) {
let mut display_settings = if is_override {
config::OVERWRITE_DISPLAY_SETTINGS.write().unwrap()
} else {
config::DEFAULT_DISPLAY_SETTINGS.write().unwrap()
};
let mut local_settings = if is_override {
config::OVERWRITE_LOCAL_SETTINGS.write().unwrap()
} else {
config::DEFAULT_LOCAL_SETTINGS.write().unwrap()
};
let mut server_settings = if is_override {
config::OVERWRITE_SETTINGS.write().unwrap()
} else {
config::DEFAULT_SETTINGS.write().unwrap()
};
if let Some(settings) = settings.as_object() {
for (k, v) in settings {
let Some(v) = v.as_str() else {
continue;
};
if let Some(k2) = map_display_settings.get(k) {
display_settings.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_local_settings.get(k) {
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 {
let k2 = k.replace("_", "-");
let k = k2.replace("-", "_");
// display
display_settings.insert(k.clone(), v.to_owned());
display_settings.insert(k2.clone(), v.to_owned());
// local
local_settings.insert(k.clone(), v.to_owned());
local_settings.insert(k2.clone(), v.to_owned());
// server
server_settings.insert(k.clone(), v.to_owned());
server_settings.insert(k2.clone(), v.to_owned());
}
}
}
}
pub fn read_custom_client(config: &str) {
let Ok(data) = decode64(config) else {
log::error!("Failed to decode custom client config");
@@ -1611,66 +1661,23 @@ pub fn read_custom_client(config: &str) {
for s in config::keys::KEYS_SETTINGS {
map_settings.insert(s.replace("_", "-"), s);
}
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 let Some(k2) = map_display_settings.get(k) {
config::DEFAULT_DISPLAY_SETTINGS
.write()
.unwrap()
.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_local_settings.get(k) {
config::DEFAULT_LOCAL_SETTINGS
.write()
.unwrap()
.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_settings.get(k) {
config::DEFAULT_SETTINGS
.write()
.unwrap()
.insert(k2.to_string(), v.to_owned());
} else {
config::DEFAULT_SETTINGS
.write()
.unwrap()
.insert(k.clone(), v.to_owned());
}
}
}
read_custom_client_advanced_settings(
default_settings,
&map_display_settings,
&map_local_settings,
&map_settings,
false,
);
}
if let Some(overwrite_settings) = data.remove("override-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 let Some(k2) = map_display_settings.get(k) {
config::OVERWRITE_DISPLAY_SETTINGS
.write()
.unwrap()
.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_local_settings.get(k) {
config::OVERWRITE_LOCAL_SETTINGS
.write()
.unwrap()
.insert(k2.to_string(), v.to_owned());
} else if let Some(k2) = map_settings.get(k) {
config::OVERWRITE_SETTINGS
.write()
.unwrap()
.insert(k2.to_string(), v.to_owned());
} else {
config::OVERWRITE_SETTINGS
.write()
.unwrap()
.insert(k.clone(), v.to_owned());
}
}
}
read_custom_client_advanced_settings(
overwrite_settings,
&map_display_settings,
&map_local_settings,
&map_settings,
true,
);
}
for (k, v) in data {
if let Some(v) = v.as_str() {

View File

@@ -775,7 +775,7 @@ pub fn main_get_error() -> String {
pub fn main_show_option(_key: String) -> SyncReturn<bool> {
#[cfg(target_os = "linux")]
if _key.eq(config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS) {
if _key.eq(config::keys::OPTION_ALLOW_LINUX_HEADLESS) {
return SyncReturn(true);
}
SyncReturn(false)

View File

@@ -1,6 +1,6 @@
use super::{CursorData, ResultType};
use desktop::Desktop;
use hbb_common::config::CONFIG_OPTION_ALLOW_LINUX_HEADLESS;
use hbb_common::config::keys::OPTION_ALLOW_LINUX_HEADLESS;
pub use hbb_common::platform::linux::*;
use hbb_common::{
allow_err,
@@ -95,7 +95,7 @@ pub struct xcb_xfixes_get_cursor_image {
#[inline]
pub fn is_headless_allowed() -> bool {
Config::get_option(CONFIG_OPTION_ALLOW_LINUX_HEADLESS) == "Y"
Config::get_option(OPTION_ALLOW_LINUX_HEADLESS) == "Y"
}
#[inline]

View File

@@ -28,7 +28,7 @@ use hbb_common::platform::linux::run_cmds;
#[cfg(target_os = "android")]
use hbb_common::protobuf::EnumOrUnknown;
use hbb_common::{
config::Config,
config::{self, Config},
fs::{self, can_enable_overwrite_detection},
futures::{SinkExt, StreamExt},
get_time, get_version_number,
@@ -337,7 +337,7 @@ impl Connection {
clipboard: Connection::permission("enable-clipboard"),
audio: Connection::permission("enable-audio"),
// to-do: make sure is the option correct here
file: Connection::permission("enable-file-transfer"),
file: Connection::permission(config::keys::OPTION_ENABLE_FILE_TRANSFER),
restart: Connection::permission("enable-remote-restart"),
recording: Connection::permission("enable-record-session"),
block_input: Connection::permission("enable-block-input"),
@@ -1614,7 +1614,7 @@ impl Connection {
}
match lr.union {
Some(login_request::Union::FileTransfer(ft)) => {
if !Connection::permission("enable-file-transfer") {
if !Connection::permission(config::keys::OPTION_ENABLE_FILE_TRANSFER) {
self.send_login_error("No permission of file transfer")
.await;
sleep(1.).await;

View File

@@ -198,7 +198,7 @@ class Header: Reactor.Component {
{<li #follow-remote-window .toggle-option><span>{svg_checkmark}</span>{translate('Follow remote window focus')}</li>}
<li #show-quality-monitor .toggle-option><span>{svg_checkmark}</span>{translate('Show quality monitor')}</li>
{audio_enabled ? <li #disable-audio .toggle-option><span>{svg_checkmark}</span>{translate('Mute')}</li> : ""}
{(is_win && pi.platform == "Windows") && file_enabled ? <li #enable-file-transfer .toggle-option><span>{svg_checkmark}</span>{translate('Enable file copy and paste')}</li> : ""}
{(is_win && pi.platform == "Windows") && file_enabled ? <li #enable-file-copy-paste .toggle-option><span>{svg_checkmark}</span>{translate('Enable file copy and paste')}</li> : ""}
{keyboard_enabled && clipboard_enabled ? <li #disable-clipboard .toggle-option><span>{svg_checkmark}</span>{translate('Disable clipboard')}</li> : ""}
{keyboard_enabled ? <li #lock-after-session-end .toggle-option><span>{svg_checkmark}</span>{translate('Lock after session end')}</li> : ""}
{keyboard_enabled && pi.platform == "Windows" ? <li #privacy-mode><span>{svg_checkmark}</span>{translate('Privacy mode')}</li> : ""}
@@ -481,7 +481,7 @@ function toggleMenuState() {
for (var el in $$(menu#keyboard-options>li)) {
el.attributes.toggleClass("selected", values.indexOf(el.id) >= 0);
}
for (var id in ["show-remote-cursor", "follow-remote-cursor", "follow-remote-window", "show-quality-monitor", "disable-audio", "enable-file-transfer", "disable-clipboard", "lock-after-session-end", "allow_swap_key", "i444"]) {
for (var id in ["show-remote-cursor", "follow-remote-cursor", "follow-remote-window", "show-quality-monitor", "disable-audio", "enable-file-copy-paste", "disable-clipboard", "lock-after-session-end", "allow_swap_key", "i444"]) {
var el = self.select('#' + id);
if (el) {
var value = handler.get_toggle_option(id);

View File

@@ -79,7 +79,7 @@ struct IpcTaskRunner<T: InvokeUiCM> {
lazy_static::lazy_static! {
static ref CLIENTS: RwLock<HashMap<i32, Client>> = Default::default();
}
static CLICK_TIME: AtomicI64 = AtomicI64::new(0);
#[derive(Clone)]
@@ -574,7 +574,9 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
feature = "unix-file-copy-paste"
),
))]
ContextSend::enable(Config::get_option("enable-file-transfer").is_empty());
ContextSend::enable(
Config::get_option(hbb_common::config::keys::OPTION_ENABLE_FILE_TRANSFER).is_empty(),
);
match ipc::new_listener("_cm").await {
Ok(mut incoming) => {

View File

@@ -1120,7 +1120,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
)
))]
{
let b = OPTIONS.lock().unwrap().get("enable-file-transfer").map(|x| x.to_string()).unwrap_or_default();
let b = OPTIONS.lock().unwrap().get(config::keys::OPTION_ENABLE_FILE_TRANSFER).map(|x| x.to_string()).unwrap_or_default();
if b != enable_file_transfer {
clipboard::ContextSend::enable(b.is_empty());
enable_file_transfer = b;

View File

@@ -312,7 +312,7 @@ impl<T: InvokeUiSession> Session<T> {
pub fn toggle_option(&self, name: String) {
let msg = self.lc.write().unwrap().toggle_option(name.clone());
#[cfg(not(feature = "flutter"))]
if name == "enable-file-transfer" {
if name == hbb_common::config::keys::OPTION_ENABLE_FILE_COPY_PASTE {
self.send(Data::ToggleClipboardFile);
}
if let Some(msg) = msg {