diff --git a/Cargo.toml b/Cargo.toml index 2f5d48c44..1670b4fbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,13 @@ linux_headless = ["pam" ] virtual_display_driver = ["virtual_display"] plugin_framework = [] linux-pkg-config = ["magnum-opus/linux-pkg-config", "scrap/linux-pkg-config"] +unix-file-copy-paste = [ + "dep:x11-clipboard", + "dep:x11rb", + "dep:percent-encoding", + "dep:once_cell", + "clipboard/unix-file-copy-paste", +] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -84,7 +91,7 @@ mac_address = "1.1" sciter-rs = { git = "https://github.com/open-trade/rust-sciter", branch = "dyn" } sys-locale = "0.3" enigo = { path = "libs/enigo", features = [ "with_serde" ] } -clipboard = { path = "libs/clipboard" } +clipboard = { path = "libs/clipboard", default-features = false } ctrlc = "3.2" arboard = "3.2" system_shutdown = "4.0" @@ -132,10 +139,10 @@ dbus = "0.9" dbus-crossroads = "0.5" pam = { git="https://github.com/fufesou/pam", optional = true } users = { version = "0.11" } -x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch"} -x11rb = {version = "0.12", features = ["all-extensions"]} -percent-encoding = "2.3" -once_cell = "1.18" +x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch", optional = true} +x11rb = {version = "0.12", features = ["all-extensions"], optional = true} +percent-encoding = {version = "2.3", optional = true} +once_cell = {version = "1.18", optional = true} [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.13" diff --git a/libs/clipboard/Cargo.toml b/libs/clipboard/Cargo.toml index 3de02f768..ef2755661 100644 --- a/libs/clipboard/Cargo.toml +++ b/libs/clipboard/Cargo.toml @@ -9,6 +9,19 @@ build = "build.rs" [build-dependencies] cc = "1.0" +[features] +default = ["unix-file-copy-paste"] +unix-file-copy-paste = [ +"dep:x11rb", +"dep:x11-clipboard", +"dep:rand", +"dep:fuser", +"dep:libc", +"dep:dashmap", +"dep:percent-encoding", +"dep:utf16string" +] + [dependencies] thiserror = "1.0" lazy_static = "1.4" @@ -18,12 +31,12 @@ hbb_common = { path = "../hbb_common" } parking_lot = {version = "0.12"} [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] -once_cell = "1.18" -x11rb = {version = "0.12", features = ["all-extensions"]} -rand = {version = "0.8"} -fuser = {version = "0.13"} -libc = {version = "0.2"} -dashmap = "5.5" -percent-encoding = "2.3" -utf16string = "0.2" -x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch"} +once_cell = {version = "1.18", optional = true} +x11rb = {version = "0.12", features = ["all-extensions"], optional = true} +rand = {version = "0.8", optional = true} +fuser = {version = "0.13", optional = true} +libc = {version = "0.2", optional = true} +dashmap = {version ="5.5", optional = true} +percent-encoding = {version ="2.3", optional = true} +utf16string = {version = "0.2", optional = true} +x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch", optional = true} diff --git a/libs/clipboard/src/lib.rs b/libs/clipboard/src/lib.rs index 822d83a10..0e80cda2d 100644 --- a/libs/clipboard/src/lib.rs +++ b/libs/clipboard/src/lib.rs @@ -108,6 +108,7 @@ pub enum ClipboardFile { struct MsgChannel { peer_id: String, conn_id: i32, + #[allow(dead_code)] sender: UnboundedSender, receiver: Arc>>, } @@ -193,6 +194,7 @@ pub fn get_rx_cliprdr_server(conn_id: i32) -> Arc crate::ResultType> { - use std::{fs::Permissions, os::unix::prelude::PermissionsExt}; + #[cfg(feature = "unix-file-copy-paste")] + { + use std::{fs::Permissions, os::unix::prelude::PermissionsExt}; - use hbb_common::{config::APP_NAME, log}; + use hbb_common::{config::APP_NAME, log}; - if !enable_files { - return Ok(Box::new(DummyCliprdrContext {}) as Box<_>); + if !_enable_files { + return Ok(Box::new(DummyCliprdrContext {}) as Box<_>); + } + + let timeout = std::time::Duration::from_secs(_response_wait_timeout_secs as u64); + + let app_name = APP_NAME.read().unwrap().clone(); + + let mnt_path = format!("/tmp/{}/{}", app_name, "cliprdr"); + + // this function must be called after the main IPC is up + std::fs::create_dir(&mnt_path).ok(); + std::fs::set_permissions(&mnt_path, Permissions::from_mode(0o777)).ok(); + + log::info!("clear previously mounted cliprdr FUSE"); + if let Err(e) = std::process::Command::new("umount").arg(&mnt_path).status() { + log::warn!("umount {:?} may fail: {:?}", mnt_path, e); + } + + let linux_ctx = unix::ClipboardContext::new(timeout, mnt_path.parse().unwrap())?; + log::debug!("start cliprdr FUSE"); + linux_ctx.run().expect("failed to start cliprdr FUSE"); + + Ok(Box::new(linux_ctx) as Box<_>) } - - let timeout = std::time::Duration::from_secs(response_wait_timeout_secs as u64); - - let app_name = APP_NAME.read().unwrap().clone(); - - let mnt_path = format!("/tmp/{}/{}", app_name, "cliprdr"); - - // this function must be called after the main IPC is up - std::fs::create_dir(&mnt_path).ok(); - std::fs::set_permissions(&mnt_path, Permissions::from_mode(0o777)).ok(); - - log::info!("clear previously mounted cliprdr FUSE"); - if let Err(e) = std::process::Command::new("umount").arg(&mnt_path).status() { - log::warn!("umount {:?} may fail: {:?}", mnt_path, e); - } - - let linux_ctx = unix::ClipboardContext::new(timeout, mnt_path.parse().unwrap())?; - log::debug!("start cliprdr FUSE"); - linux_ctx.run().expect("failed to start cliprdr FUSE"); - - Ok(Box::new(linux_ctx) as Box<_>) + #[cfg(not(feature = "unix-file-copy-paste"))] + return Ok(Box::new(DummyCliprdrContext {}) as Box<_>); } struct DummyCliprdrContext {} @@ -73,6 +80,7 @@ impl CliprdrServiceContext for DummyCliprdrContext { } } +#[cfg(feature = "unix-file-copy-paste")] // begin of epoch used by microsoft // 1601-01-01 00:00:00 + LDAP_EPOCH_DELTA*(100 ns) = 1970-01-01 00:00:00 #[cfg(target_os = "linux")]