Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: clipboard, set formats and enable option (#8873)

fufesou0e98a517752c
diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs
index a182a5fe0..ea2afff1d 100644
--- a/src/client/io_loop.rs
+++ b/src/client/io_loop.rs
@@ -1367,17 +1367,17 @@ impl<T: InvokeUiSession> Remote<T> {
// https://github.com/rustdesk/rustdesk/issues/3703#issuecomment-1474734754
match p.permission.enum_value() {
Ok(Permission::Keyboard) => {
+ *self.handler.server_keyboard_enabled.write().unwrap() = p.enabled;
#[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
crate::flutter::update_text_clipboard_required();
- *self.handler.server_keyboard_enabled.write().unwrap() = p.enabled;
self.handler.set_permission("keyboard", p.enabled);
}
Ok(Permission::Clipboard) => {
+ *self.handler.server_clipboard_enabled.write().unwrap() = p.enabled;
#[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
crate::flutter::update_text_clipboard_required();
- *self.handler.server_clipboard_enabled.write().unwrap() = p.enabled;
self.handler.set_permission("clipboard", p.enabled);
}
Ok(Permission::Audio) => {
diff --git a/src/clipboard.rs b/src/clipboard.rs
index fe30189ca..44a3c09d3 100644
--- a/src/clipboard.rs
+++ b/src/clipboard.rs
@@ -3,9 +3,7 @@ use clipboard_master::{ClipboardHandler, Master, Shutdown};
use hbb_common::{log, message_proto::*, ResultType};
use std::{
sync::{mpsc::Sender, Arc, Mutex},
- thread,
thread::JoinHandle,
- time::Duration,
};
pub const CLIPBOARD_NAME: &'static str = "clipboard";
@@ -18,6 +16,10 @@ lazy_static::lazy_static! {
static ref ARBOARD_MTX: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
// cache the clipboard msg
static ref LAST_MULTI_CLIPBOARDS: Arc<Mutex<MultiClipboards>> = Arc::new(Mutex::new(MultiClipboards::new()));
+ // Clipboard on Linux is "server--clients" mode.
+ // The clipboard content is owned by the server and passed to the clients when requested.
+ // Plain text is the only exception, it does not require the server to be present.
+ static ref CLIPBOARD_UPDATE_CTX: Arc<Mutex<Option<ClipboardContext>>> = Arc::new(Mutex::new(None));
}
const SUPPORTED_FORMATS: &[ClipboardFormat] = &[
@@ -162,20 +164,27 @@ fn update_clipboard_(multi_clipboards: Vec<Clipboard>, side: ClipboardSide) {
if to_update_data.is_empty() {
return;
}
- match ClipboardContext::new() {
- Ok(mut ctx) => {
- to_update_data.push(ClipboardData::Special((
- RUSTDESK_CLIPBOARD_OWNER_FORMAT.to_owned(),
- side.get_owner_data(),
- )));
- if let Err(e) = ctx.set(&to_update_data) {
- log::debug!("Failed to set clipboard: {}", e);
- } else {
- log::debug!("{} updated on {}", CLIPBOARD_NAME, side);
+ let mut ctx = CLIPBOARD_UPDATE_CTX.lock().unwrap();
+ if ctx.is_none() {
+ match ClipboardContext::new() {
+ Ok(x) => {
+ *ctx = Some(x);
+ }
+ Err(e) => {
+ log::error!("Failed to create clipboard context: {}", e);
+ return;
}
}
- Err(err) => {
- log::error!("Failed to create clipboard context: {}", err);
+ }
+ if let Some(ctx) = ctx.as_mut() {
+ to_update_data.push(ClipboardData::Special((
+ RUSTDESK_CLIPBOARD_OWNER_FORMAT.to_owned(),
+ side.get_owner_data(),
+ )));
+ if let Err(e) = ctx.set(&to_update_data) {
+ log::debug!("Failed to set clipboard: {}", e);
+ } else {
+ log::debug!("{} updated on {}", CLIPBOARD_NAME, side);
}
}
}