From e0f4cdd18cad8f7f816ec53a152d944826ad7cef Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 10 Apr 2023 16:58:58 +0800 Subject: [PATCH] remove session's old_clipboard Signed-off-by: fufesou --- src/client.rs | 16 +++++----------- src/client/io_loop.rs | 13 +++++++------ src/common.rs | 7 +------ src/flutter.rs | 4 ++-- src/ui_session_interface.rs | 2 -- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/client.rs b/src/client.rs index 843befd4e..4b06074eb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -95,9 +95,10 @@ lazy_static::lazy_static! { static ref TEXT_CLIPBOARD_STATE: Arc> = Arc::new(Mutex::new(TextClipboardState::new())); } +#[inline] #[cfg(not(any(target_os = "android", target_os = "ios")))] -pub fn update_clipboard_text(text: String) { - *OLD_CLIPBOARD_TEXT.lock().unwrap() = text; +pub fn get_old_clipboard_text() -> &'static Arc> { + &OLD_CLIPBOARD_TEXT } #[cfg(not(any(target_os = "android", target_os = "ios")))] @@ -666,16 +667,10 @@ impl Client { if let Some(msg) = check_clipboard(&mut ctx, Some(&OLD_CLIPBOARD_TEXT)) { #[cfg(feature = "flutter")] - crate::flutter::send_text_clipboard_msg( - &*OLD_CLIPBOARD_TEXT.lock().unwrap(), - msg, - ); + crate::flutter::send_text_clipboard_msg(msg); #[cfg(not(feature = "flutter"))] if let Some(ctx) = &_ctx { - if ctx.cfg.is_text_clipboard_required() - && *OLD_CLIPBOARD_TEXT.lock().unwrap() - != *ctx.old.lock().unwrap() - { + if ctx.cfg.is_text_clipboard_required() { let _ = ctx.tx.send(Data::Message(msg)); } } @@ -2444,6 +2439,5 @@ pub(crate) struct ClientClipboardContext; #[cfg(not(any(target_os = "android", target_os = "ios")))] pub(crate) struct ClientClipboardContext { pub cfg: SessionPermissionConfig, - pub old: Arc>, pub tx: UnboundedSender, } diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index eb2c96b06..1c009d84e 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -935,11 +935,12 @@ impl Remote { Client::try_start_clipboard(None); #[cfg(not(feature = "flutter"))] #[cfg(not(any(target_os = "android", target_os = "ios")))] - Client::try_start_clipboard(Some(crate::client::ClientClipboardContext { - cfg: permission_config.clone(), - old: self.handler.old_clipboard.clone(), - tx: sender.clone(), - })); + Client::try_start_clipboard(Some( + crate::client::ClientClipboardContext { + cfg: permission_config.clone(), + tx: sender.clone(), + }, + )); #[cfg(not(any(target_os = "android", target_os = "ios")))] tokio::spawn(async move { @@ -972,7 +973,7 @@ impl Remote { 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(&self.handler.old_clipboard)); + update_clipboard(cb, Some(&crate::client::get_old_clipboard_text())); #[cfg(any(target_os = "android", target_os = "ios"))] { let content = if cb.compress { diff --git a/src/common.rs b/src/common.rs index 43776820e..3cf10eaba 100644 --- a/src/common.rs +++ b/src/common.rs @@ -187,14 +187,9 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc>>) } match ClipboardContext::new() { Ok(mut ctx) => { - let host_side = "host"; - let client_side = "client"; - let side = if old.is_none() { host_side } else { client_side }; + let side = if old.is_none() { "host" } else { "client" }; let old = if let Some(old) = old { old } else { &CONTENT }; *old.lock().unwrap() = content.clone(); - if side == client_side { - crate::client::update_clipboard_text(content.clone()); - } let _lock = ARBOARD_MTX.lock().unwrap(); allow_err!(ctx.set_text(content)); log::debug!("{} updated on {}", CLIPBOARD_NAME, side); diff --git a/src/flutter.rs b/src/flutter.rs index e49f04043..6c9ff7f37 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -725,9 +725,9 @@ pub fn other_sessions_running(id: &str) -> bool { } #[cfg(not(any(target_os = "android", target_os = "ios")))] -pub fn send_text_clipboard_msg(text: &str, msg: Message) { +pub fn send_text_clipboard_msg(msg: Message) { for (_id, session) in SESSIONS.read().unwrap().iter() { - if session.is_text_clipboard_required() && text != *session.old_clipboard.lock().unwrap() { + if session.is_text_clipboard_required() { session.send(Data::Message(msg.clone())); } } diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 7ae1d5b24..504982f50 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -43,8 +43,6 @@ pub struct Session { pub server_keyboard_enabled: Arc>, pub server_file_transfer_enabled: Arc>, pub server_clipboard_enabled: Arc>, - #[cfg(not(any(target_os = "android", target_os = "ios")))] - pub old_clipboard: Arc>, } #[derive(Clone)]