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

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-07-29 15:40:02 +08:00 committed by GitHub
parent 0a1d3c4afb
commit 0e98a51775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 16 deletions

View File

@ -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) => {

View File

@ -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);
}
}
}