diff --git a/libs/clipboard/src/platform/fuse.rs b/libs/clipboard/src/platform/fuse.rs index 9294ac1db..6c5bbcdd2 100644 --- a/libs/clipboard/src/platform/fuse.rs +++ b/libs/clipboard/src/platform/fuse.rs @@ -40,7 +40,6 @@ use utf16string::WStr; use crate::{send_data, ClipboardFile, CliprdrError}; -#[cfg(target_os = "linux")] use super::LDAP_EPOCH_DELTA; /// fuse server ready retry max times diff --git a/libs/clipboard/src/platform/mod.rs b/libs/clipboard/src/platform/mod.rs index 1d9a96644..9f76fa8bb 100644 --- a/libs/clipboard/src/platform/mod.rs +++ b/libs/clipboard/src/platform/mod.rs @@ -21,7 +21,7 @@ pub mod fuse; #[cfg(feature = "unix-file-copy-paste")] #[cfg(any(target_os = "linux", target_os = "macos"))] pub mod unix; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "macos"))] pub fn create_cliprdr_context( _enable_files: bool, _enable_others: bool, @@ -52,11 +52,11 @@ pub fn create_cliprdr_context( log::warn!("umount {:?} may fail: {:?}", mnt_path, e); } - let linux_ctx = unix::ClipboardContext::new(timeout, mnt_path.parse().unwrap())?; + let unix_ctx = unix::ClipboardContext::new(timeout, mnt_path.parse().unwrap())?; log::debug!("start cliprdr FUSE"); - linux_ctx.run().expect("failed to start cliprdr FUSE"); + unix_ctx.run().expect("failed to start cliprdr FUSE"); - Ok(Box::new(linux_ctx) as Box<_>) + Ok(Box::new(unix_ctx) as Box<_>) } #[cfg(not(feature = "unix-file-copy-paste"))] return Ok(Box::new(DummyCliprdrContext {}) as Box<_>); @@ -83,5 +83,4 @@ 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")] const LDAP_EPOCH_DELTA: u64 = 116444772610000000; diff --git a/libs/clipboard/src/platform/unix/mod.rs b/libs/clipboard/src/platform/unix/mod.rs index b74c583c8..39b851e10 100644 --- a/libs/clipboard/src/platform/unix/mod.rs +++ b/libs/clipboard/src/platform/unix/mod.rs @@ -19,14 +19,17 @@ use crate::{ }; use self::local_file::LocalFile; +#[cfg(target_os = "linux")] use self::url::{encode_path_to_uri, parse_plain_uri_list}; use super::fuse::FuseServer; -#[cfg(not(feature = "wayland"))] +#[cfg(target_os = "linux")] pub mod x11; pub mod local_file; + +#[cfg(target_os = "linux")] pub mod url; // not actual format id, just a placeholder @@ -66,6 +69,7 @@ trait SysClipboard: Send + Sync { fn get_file_list(&self) -> Vec; } +#[cfg(target_os = "linux")] fn get_sys_clipboard(ignore_path: &PathBuf) -> Result, CliprdrError> { #[cfg(feature = "wayland")] { @@ -79,6 +83,11 @@ fn get_sys_clipboard(ignore_path: &PathBuf) -> Result, Cli } } +#[cfg(target_os = "macos")] +fn get_sys_clipboard(ignore_path: &PathBuf) -> Result, CliprdrError> { + unimplemented!() +} + #[derive(Debug)] enum FileContentsRequest { Size { diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index 2d46097ed..377da85e3 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -7,14 +7,14 @@ use std::{ }, }; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] use clipboard::ContextSend; use crossbeam_queue::ArrayQueue; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::sleep; #[cfg(not(target_os = "ios"))] use hbb_common::tokio::sync::mpsc::error::TryRecvError; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] use hbb_common::tokio::sync::Mutex as TokioMutex; use hbb_common::{ allow_err, @@ -66,7 +66,7 @@ pub struct Remote { last_update_jobs_status: (Instant, HashMap), is_connected: bool, first_frame: bool, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] client_conn_id: i32, // used for file clipboard data_count: Arc, frame_count_map: Arc>>, @@ -101,7 +101,7 @@ impl Remote { last_update_jobs_status: (Instant::now(), Default::default()), is_connected: false, first_frame: false, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] client_conn_id: 0, data_count: Arc::new(AtomicUsize::new(0)), frame_count_map, @@ -146,14 +146,14 @@ impl Remote { } // just build for now - #[cfg(not(any(target_os = "windows", target_os = "linux")))] + #[cfg(not(any(target_os = "windows", target_os = "linux", target_os = "macos")))] let (_tx_holder, mut rx_clip_client) = mpsc::unbounded_channel::(); - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let (_tx_holder, rx) = mpsc::unbounded_channel(); - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let mut rx_clip_client_lock = Arc::new(TokioMutex::new(rx)); - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] { let is_conn_not_default = self.handler.is_file_transfer() || self.handler.is_port_forward() @@ -164,7 +164,7 @@ impl Remote { clipboard::get_rx_cliprdr_client(&self.handler.id); }; } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let mut rx_clip_client = rx_clip_client_lock.lock().await; let mut status_timer = time::interval(Duration::new(1, 0)); @@ -210,7 +210,7 @@ impl Remote { } } _msg = rx_clip_client.recv() => { - #[cfg(any(target_os="windows", target_os="linux"))] + #[cfg(any(target_os="windows", target_os="linux", target_os = "macos"))] self.handle_local_clipboard_msg(&mut peer, _msg).await; } _ = self.timer.tick() => { @@ -278,7 +278,7 @@ impl Remote { Client::try_stop_clipboard(&self.handler.id); } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] if _set_disconnected_ok { let conn_id = self.client_conn_id; log::debug!("try empty cliprdr for conn_id {}", conn_id); @@ -289,7 +289,7 @@ impl Remote { } } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] async fn handle_local_clipboard_msg( &self, peer: &mut crate::client::FramedStream, @@ -1143,7 +1143,7 @@ impl Remote { } } } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] Some(message::Union::Cliprdr(clip)) => { self.handle_cliprdr_msg(clip); } @@ -1718,7 +1718,7 @@ impl Remote { } } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] fn handle_cliprdr_msg(&self, clip: hbb_common::message_proto::Cliprdr) { log::debug!("handling cliprdr msg from server peer"); #[cfg(feature = "flutter")] diff --git a/src/lib.rs b/src/lib.rs index 631766a2d..8aa520579 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ mod ui_session_interface; mod hbbs_http; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] pub mod clipboard_file; #[cfg(windows)] diff --git a/src/server/connection.rs b/src/server/connection.rs index 9601f3ca9..4bbfd6211 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1,5 +1,5 @@ use super::{input_service::*, *}; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] use crate::clipboard_file::*; #[cfg(not(any(target_os = "android", target_os = "ios")))] use crate::common::update_clipboard; @@ -192,7 +192,7 @@ pub struct Connection { // by peer disable_audio: bool, // by peer - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] enable_file_transfer: bool, // by peer audio_sender: Option, @@ -330,7 +330,7 @@ impl Connection { show_remote_cursor: false, ip: "".to_owned(), disable_audio: false, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] enable_file_transfer: false, disable_clipboard: false, disable_keyboard: false, @@ -1032,7 +1032,7 @@ impl Connection { pi.hostname = DEVICE_NAME.lock().unwrap().clone(); pi.platform = "Android".into(); } - #[cfg(any(target_os = "linux", target_os = "windows"))] + #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))] let mut platform_additions = serde_json::Map::new(); #[cfg(target_os = "linux")] { @@ -1247,7 +1247,7 @@ impl Connection { self.audio && !self.disable_audio } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] fn file_transfer_enabled(&self) -> bool { self.file && self.enable_file_transfer } @@ -1817,7 +1817,7 @@ impl Connection { } Some(message::Union::Cliprdr(_clip)) => { - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] if let Some(clip) = msg_2_clip(_clip) { log::debug!("got clipfile from client peer"); self.send_to_cm(ipc::Data::ClipboardFile(clip)) @@ -2401,7 +2401,7 @@ impl Connection { } } } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] if let Ok(q) = o.enable_file_transfer.enum_value() { if q != BoolOption::NotSet { self.enable_file_transfer = q == BoolOption::Yes; diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index 83c43d24b..a20997dc9 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -1,6 +1,6 @@ #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] use std::iter::FromIterator; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] use std::sync::Arc; use std::{ collections::HashMap, @@ -15,11 +15,11 @@ use std::{ use crate::ipc::Connection; #[cfg(not(any(target_os = "ios")))] use crate::ipc::{self, Data}; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] use clipboard::ContextSend; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::tokio::sync::mpsc::unbounded_channel; -#[cfg(any(target_os = "windows", target_os = "linux"))] +#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] use hbb_common::tokio::sync::Mutex as TokioMutex; use hbb_common::{ allow_err, @@ -70,9 +70,9 @@ struct IpcTaskRunner { close: bool, running: bool, conn_id: i32, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] file_transfer_enabled: bool, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] file_transfer_enabled_peer: bool, } @@ -165,7 +165,7 @@ impl ConnectionManager { } #[inline] - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] fn is_authorized(&self, id: i32) -> bool { CLIENTS .read() @@ -186,7 +186,7 @@ impl ConnectionManager { .map(|c| c.disconnected = true); } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] { let _ = ContextSend::proc(|context| -> ResultType<()> { context.empty_clipboard(id)?; @@ -330,14 +330,14 @@ impl IpcTaskRunner { // for tmp use, without real conn id let mut write_jobs: Vec = Vec::new(); - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let is_authorized = self.cm.is_authorized(self.conn_id); - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] let rx_clip1; let mut rx_clip; let _tx_clip; - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] if self.conn_id > 0 && is_authorized { log::debug!("Clipboard is enabled from client peer: type 1"); rx_clip1 = clipboard::get_rx_cliprdr_server(self.conn_id); @@ -349,12 +349,12 @@ impl IpcTaskRunner { rx_clip1 = Arc::new(TokioMutex::new(rx_clip2)); rx_clip = rx_clip1.lock().await; } - #[cfg(not(any(target_os = "windows", target_os = "linux")))] + #[cfg(not(any(target_os = "windows", target_os = "linux", target_os = "macos")))] { (_tx_clip, rx_clip) = unbounded_channel::(); } - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] { if ContextSend::is_enabled() { log::debug!("Clipboard is enabled"); @@ -382,7 +382,7 @@ impl IpcTaskRunner { log::debug!("conn_id: {}", id); self.cm.add_connection(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, recording, from_switch,self.tx.clone()); self.conn_id = id; - #[cfg(any(target_os = "linux", target_os = "windows"))] + #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))] { self.file_transfer_enabled = _file_transfer_enabled; } @@ -425,7 +425,7 @@ impl IpcTaskRunner { } #[cfg(not(any(target_os = "android", target_os = "ios")))] Data::ClipboardFile(_clip) => { - #[cfg(any(target_os = "windows", target_os="linux"))] + #[cfg(any(target_os = "windows", target_os="linux", target_os = "macos"))] { let is_stopping_allowed = _clip.is_stopping_allowed_from_peer(); let is_clipboard_enabled = ContextSend::is_enabled(); @@ -504,7 +504,7 @@ impl IpcTaskRunner { }, clip_file = rx_clip.recv() => match clip_file { Some(_clip) => { - #[cfg(any(target_os = "windows", target_os ="linux"))] + #[cfg(any(target_os = "windows", target_os ="linux", target_os = "macos"))] { let is_stopping_allowed = _clip.is_stopping_allowed(); let is_clipboard_enabled = ContextSend::is_enabled(); @@ -543,9 +543,9 @@ impl IpcTaskRunner { close: true, running: true, conn_id: 0, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] file_transfer_enabled: false, - #[cfg(any(target_os = "windows", target_os = "linux"))] + #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] file_transfer_enabled_peer: false, }; diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 5379b4a55..7cabdf790 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -1007,7 +1007,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver