Skip to content

Commit

Permalink
patch: make linux build ok
Browse files Browse the repository at this point in the history
Signed-off-by: ClSlaid <[email protected]>
  • Loading branch information
ClSlaid committed Oct 29, 2023
1 parent 7aee76f commit 30e85c8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 48 deletions.
1 change: 0 additions & 1 deletion libs/clipboard/src/platform/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions libs/clipboard/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<_>);
Expand All @@ -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;
11 changes: 10 additions & 1 deletion libs/clipboard/src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,6 +69,7 @@ trait SysClipboard: Send + Sync {
fn get_file_list(&self) -> Vec<PathBuf>;
}

#[cfg(target_os = "linux")]
fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, CliprdrError> {
#[cfg(feature = "wayland")]
{
Expand All @@ -79,6 +83,11 @@ fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, Cli
}
}

#[cfg(target_os = "macos")]
fn get_sys_clipboard(ignore_path: &PathBuf) -> Result<Box<dyn SysClipboard>, CliprdrError> {
unimplemented!()
}

#[derive(Debug)]
enum FileContentsRequest {
Size {
Expand Down
28 changes: 14 additions & 14 deletions src/client/io_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct Remote<T: InvokeUiSession> {
last_update_jobs_status: (Instant, HashMap<i32, u64>),
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<AtomicUsize>,
frame_count_map: Arc<RwLock<HashMap<usize, usize>>>,
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<T: InvokeUiSession> Remote<T> {
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,
Expand Down Expand Up @@ -146,14 +146,14 @@ impl<T: InvokeUiSession> Remote<T> {
}

// 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::<i32>();

#[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()
Expand All @@ -164,7 +164,7 @@ impl<T: InvokeUiSession> Remote<T> {
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));
Expand Down Expand Up @@ -210,7 +210,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
_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() => {
Expand Down Expand Up @@ -278,7 +278,7 @@ impl<T: InvokeUiSession> Remote<T> {
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);
Expand All @@ -289,7 +289,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}

#[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,
Expand Down Expand Up @@ -1143,7 +1143,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
}
#[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);
}
Expand Down Expand Up @@ -1718,7 +1718,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}

#[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")]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
14 changes: 7 additions & 7 deletions src/server/connection.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<MediaSender>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")]
{
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions src/ui_cm_interface.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -70,9 +70,9 @@ struct IpcTaskRunner<T: InvokeUiCM> {
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,
}

Expand Down Expand Up @@ -165,7 +165,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
}

#[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()
Expand All @@ -186,7 +186,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
.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)?;
Expand Down Expand Up @@ -330,14 +330,14 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
// for tmp use, without real conn id
let mut write_jobs: Vec<fs::TransferJob> = 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);
Expand All @@ -349,12 +349,12 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
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::<i32>();
}

#[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");
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
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;
}
Expand Down Expand Up @@ -425,7 +425,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
}
#[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();
Expand Down Expand Up @@ -504,7 +504,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
},
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();
Expand Down Expand Up @@ -543,9 +543,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
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,
};

Expand Down
4 changes: 2 additions & 2 deletions src/ui_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
let mut mouse_time = 0;
#[cfg(not(feature = "flutter"))]
let mut id = "".to_owned();
#[cfg(any(target_os = "windows", target_os = "linux"))]
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[allow(unused_mut, dead_code)]
let mut enable_file_transfer = "".to_owned();

Expand All @@ -1032,7 +1032,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
*OPTION_SYNCED.lock().unwrap() = true;

#[cfg(any(
target_os="windows",
target_os = "windows",
all(
any(target_os="linux", target_os = "macos"),
feature = "unix-file-copy-paste"
Expand Down

0 comments on commit 30e85c8

Please sign in to comment.