From 79f6b5c181b5869cfe741ba461b07fd423ab9c43 Mon Sep 17 00:00:00 2001 From: ClSlaid Date: Sun, 29 Oct 2023 20:10:39 +0800 Subject: [PATCH] patch: forbid enable cliprdr without feature Signed-off-by: ClSlaid --- libs/clipboard/Cargo.toml | 3 ++- src/client/io_loop.rs | 5 ++++- src/common.rs | 12 ++++++------ src/ui_cm_interface.rs | 10 ++++------ src/ui_interface.rs | 4 +++- src/ui_session_interface.rs | 5 ++++- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/libs/clipboard/Cargo.toml b/libs/clipboard/Cargo.toml index ef2755661..6978ceb9a 100644 --- a/libs/clipboard/Cargo.toml +++ b/libs/clipboard/Cargo.toml @@ -19,7 +19,8 @@ unix-file-copy-paste = [ "dep:libc", "dep:dashmap", "dep:percent-encoding", -"dep:utf16string" +"dep:utf16string", +"dep:once_cell" ] [dependencies] diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index c4ca8dfa4..36cf38715 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -1704,7 +1704,10 @@ impl Remote { } fn check_clipboard_file_context(&self) { - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any( + target_os = "windows", + all(feature = "unix-file-copy-paste", target_os = "linux") + ))] { let enabled = *self.handler.server_file_transfer_enabled.read().unwrap() && self.handler.lc.read().unwrap().enable_file_transfer.v; diff --git a/src/common.rs b/src/common.rs index 4287d5aa3..27e32c98a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -14,22 +14,22 @@ pub enum GrabState { #[cfg(not(any( target_os = "android", target_os = "ios", - all(target_os = "linux", not(feature = "wayland")) + all(target_os = "linux", feature = "unix-file-copy-paste") )))] pub use arboard::Clipboard as ClipboardContext; -#[cfg(all(target_os = "linux", not(feature = "wayland")))] +#[cfg(all(target_os = "linux", feature = "unix-file-copy-paste"))] static X11_CLIPBOARD: once_cell::sync::OnceCell = once_cell::sync::OnceCell::new(); -#[cfg(all(target_os = "linux", not(feature = "wayland")))] +#[cfg(all(target_os = "linux", feature = "unix-file-copy-paste"))] fn get_clipboard() -> Result<&'static x11_clipboard::Clipboard, String> { X11_CLIPBOARD .get_or_try_init(|| x11_clipboard::Clipboard::new()) .map_err(|e| e.to_string()) } -#[cfg(all(target_os = "linux", not(feature = "wayland")))] +#[cfg(all(target_os = "linux", feature = "unix-file-copy-paste"))] pub struct ClipboardContext { string_setter: x11rb::protocol::xproto::Atom, string_getter: x11rb::protocol::xproto::Atom, @@ -39,7 +39,7 @@ pub struct ClipboardContext { prop: x11rb::protocol::xproto::Atom, } -#[cfg(all(target_os = "linux", not(feature = "wayland")))] +#[cfg(all(target_os = "linux", feature = "unix-file-copy-paste"))] fn parse_plain_uri_list(v: Vec) -> Result { let text = String::from_utf8(v).map_err(|_| "ConversionFailure".to_owned())?; let mut list = String::new(); @@ -56,7 +56,7 @@ fn parse_plain_uri_list(v: Vec) -> Result { Ok(list) } -#[cfg(all(target_os = "linux", not(feature = "wayland")))] +#[cfg(all(target_os = "linux", feature = "unix-file-copy-paste"))] impl ClipboardContext { pub fn new() -> Result { let clipboard = get_clipboard()?; diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 5baa852c3..5308305d1 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -575,12 +575,10 @@ pub async fn start_ipc(cm: ConnectionManager) { } }); - log::debug!( - "start_ipc enable context_send: {}", - Config::get_option("enable-file-transfer").is_empty() - ); - - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any( + target_os = "windows", + all(target_os = "linux", feature = "unix-file-copy-paste"), + ))] ContextSend::enable(Config::get_option("enable-file-transfer").is_empty()); match ipc::new_listener("_cm").await { diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 3e0de80db..39dd92158 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -1030,7 +1030,9 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver Session { #[tokio::main(flavor = "current_thread")] pub async fn io_loop(handler: Session, round: u32) { // It is ok to call this function multiple times. - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any( + target_os = "windows", + all(target_os = "linux", feature = "unix-file-copy-paste") + ))] if !handler.is_file_transfer() && !handler.is_port_forward() { clipboard::ContextSend::enable(true); }