change update_clipboard to threaded, since creating a context may take long

This commit is contained in:
rustdesk 2024-06-30 17:05:09 +08:00
parent 25d0ced8ba
commit 1f129e6ef3
5 changed files with 52 additions and 14 deletions

38
Cargo.lock generated
View File

@ -967,10 +967,24 @@ dependencies = [
"serde_derive",
"thiserror",
"utf16string",
"x11-clipboard",
"x11-clipboard 0.8.1",
"x11rb 0.12.0",
]
[[package]]
name = "clipboard-master"
version = "4.0.0-beta.6"
source = "git+https://github.com/rustdesk-org/clipboard-master#38c0a5c0e5e0cab48abf1209900e3543487fc474"
dependencies = [
"objc",
"objc-foundation",
"objc_id",
"windows-win",
"wl-clipboard-rs",
"x11-clipboard 0.9.2",
"x11rb 0.13.1",
]
[[package]]
name = "clipboard-win"
version = "5.3.1"
@ -5456,6 +5470,7 @@ dependencies = [
"cidr-utils",
"clap 4.5.8",
"clipboard",
"clipboard-master",
"cocoa 0.24.1",
"core-foundation 0.9.4",
"core-graphics 0.22.3",
@ -5532,7 +5547,7 @@ dependencies = [
"winreg 0.11.0",
"winres",
"wol-rs",
"x11-clipboard",
"x11-clipboard 0.8.1",
"x11rb 0.12.0",
"zip",
]
@ -7571,6 +7586,15 @@ dependencies = [
"windows-targets 0.52.5",
]
[[package]]
name = "windows-win"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58e23e33622b3b52f948049acbec9bcc34bf6e26d74176b88941f213c75cf2dc"
dependencies = [
"error-code",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
@ -7862,6 +7886,16 @@ dependencies = [
"x11rb 0.12.0",
]
[[package]]
name = "x11-clipboard"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98785a09322d7446e28a13203d2cae1059a0dd3dfb32cb06d0a225f023d8286"
dependencies = [
"libc",
"x11rb 0.13.1",
]
[[package]]
name = "x11-dl"
version = "2.21.0"

View File

@ -91,6 +91,8 @@ clipboard = { path = "libs/clipboard" }
ctrlc = "3.2"
# arboard = { version = "3.4.0", features = ["wayland-data-control"] }
arboard = { git = "https://github.com/rustdesk-org/arboard", features = ["wayland-data-control"] }
clipboard-master = { git = "https://github.com/rustdesk-org/clipboard-master"}
system_shutdown = "4.0"
qrcode-generator = "4.1"

View File

@ -144,8 +144,8 @@ const PUBLIC_SERVER: &str = "public";
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn get_old_clipboard_text() -> &'static Arc<Mutex<String>> {
&OLD_CLIPBOARD_TEXT
pub fn get_old_clipboard_text() -> Arc<Mutex<String>> {
OLD_CLIPBOARD_TEXT.clone()
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]

View File

@ -1180,7 +1180,7 @@ impl<T: InvokeUiSession> Remote<T> {
Some(message::Union::Clipboard(cb)) => {
if !self.handler.lc.read().unwrap().disable_clipboard.v {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
update_clipboard(cb, Some(&crate::client::get_old_clipboard_text()));
update_clipboard(cb, Some(crate::client::get_old_clipboard_text()));
#[cfg(any(target_os = "android", target_os = "ios"))]
{
let content = if cb.compress {

View File

@ -364,7 +364,7 @@ pub fn get_default_sound_input() -> Option<String> {
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>) {
fn update_clipboard_(clipboard: Clipboard, old: Option<Arc<Mutex<String>>>) {
let content = if clipboard.compress {
decompress(&clipboard.content)
} else {
@ -378,7 +378,7 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>)
match ClipboardContext::new() {
Ok(mut ctx) => {
let side = if old.is_none() { "host" } else { "client" };
let old = if let Some(old) = old { old } else { &CONTENT };
let old = if let Some(old) = old { old } else { CONTENT.clone() };
*old.lock().unwrap() = content.clone();
let _lock = ARBOARD_MTX.lock().unwrap();
allow_err!(ctx.set_text(content));
@ -391,6 +391,13 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>)
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn update_clipboard(clipboard: Clipboard, old: Option<Arc<Mutex<String>>>) {
std::thread::spawn(move || {
update_clipboard_(clipboard, old);
});
}
#[cfg(feature = "use_rubato")]
pub fn resample_channels(
data: &[f32],
@ -1519,6 +1526,8 @@ impl ClipboardContext {
#[inline]
#[cfg(any(target_os = "windows", target_os = "macos"))]
pub fn new() -> ResultType<ClipboardContext> {
let x: Option<()> = None;
x.unwrap();
Ok(ClipboardContext(arboard::Clipboard::new()?))
}
@ -1543,13 +1552,6 @@ impl ClipboardContext {
}
}
#[inline]
#[cfg(any(target_os = "windows", target_os = "macos"))]
pub fn get_text(&mut self) -> ResultType<String> {
Ok(self.0.get_text()?)
}
#[cfg(target_os = "linux")]
pub fn get_text(&mut self) -> ResultType<String> {
Ok(self.0.get_text()?)
}