diff --git a/src/flutter.rs b/src/flutter.rs index 928be607d..5cd43b8b2 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -1660,9 +1660,6 @@ pub mod connection_manager { #[cfg(any(target_os = "android"))] use scrap::android::call_main_service_set_by_name; - #[cfg(windows)] - use crate::ipc::start_clipboard_file; - use crate::ipc::Data; use crate::ipc::{self, new_listener, Connection}; @@ -1688,11 +1685,12 @@ pub mod connection_manager { static CLICK_TIME: AtomicI64 = AtomicI64::new(0); - enum ClipboardFileData { - #[cfg(windows)] - Clip((i32, ipc::ClipbaordFile)), - Enable((i32, bool)), - } + // // TODO clipboard_file + // enum ClipboardFileData { + // #[cfg(windows)] + // Clip((i32, ipc::ClipbaordFile)), + // Enable((i32, bool)), + // } #[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn start_listen_ipc_thread() { @@ -1702,11 +1700,12 @@ pub mod connection_manager { #[cfg(not(any(target_os = "android", target_os = "ios")))] #[tokio::main(flavor = "current_thread")] async fn start_ipc() { - let (tx_file, _rx_file) = mpsc::unbounded_channel::(); - #[cfg(windows)] - let cm_clip = cm.clone(); - #[cfg(windows)] - std::thread::spawn(move || start_clipboard_file(cm_clip, _rx_file)); + // TODO clipboard_file + // let (tx_file, _rx_file) = mpsc::unbounded_channel::(); + // #[cfg(windows)] + // let cm_clip = cm.clone(); + // #[cfg(windows)] + // std::thread::spawn(move || start_clipboard_file(cm_clip, _rx_file)); #[cfg(windows)] std::thread::spawn(move || { @@ -1730,7 +1729,7 @@ pub mod connection_manager { Ok(stream) => { log::debug!("Got new connection"); let mut stream = Connection::new(stream); - let tx_file = tx_file.clone(); + // let tx_file = tx_file.clone(); tokio::spawn(async move { // for tmp use, without real conn id let conn_id_tmp = -1; @@ -1750,11 +1749,11 @@ pub mod connection_manager { Data::Login{id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, file_transfer_enabled, restart} => { log::debug!("conn_id: {}", id); conn_id = id; - tx_file.send(ClipboardFileData::Enable((id, file_transfer_enabled))).ok(); + // tx_file.send(ClipboardFileData::Enable((id, file_transfer_enabled))).ok(); on_login(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, tx.clone()); } Data::Close => { - tx_file.send(ClipboardFileData::Enable((conn_id, false))).ok(); + // tx_file.send(ClipboardFileData::Enable((conn_id, false))).ok(); log::info!("cm ipc connection closed from connection request"); break; } @@ -1771,18 +1770,19 @@ pub mod connection_manager { Data::FS(fs) => { handle_fs(fs, &mut write_jobs, &tx).await; } - #[cfg(windows)] - Data::ClipbaordFile(_clip) => { - tx_file - .send(ClipboardFileData::Clip((id, _clip))) - .ok(); - } - #[cfg(windows)] - Data::ClipboardFileEnabled(enabled) => { - tx_file - .send(ClipboardFileData::Enable((id, enabled))) - .ok(); - } + // TODO ClipbaordFile + // #[cfg(windows)] + // Data::ClipbaordFile(_clip) => { + // tx_file + // .send(ClipboardFileData::Clip((id, _clip))) + // .ok(); + // } + // #[cfg(windows)] + // Data::ClipboardFileEnabled(enabled) => { + // tx_file + // .send(ClipboardFileData::Enable((id, enabled))) + // .ok(); + // } _ => {} } } diff --git a/src/ipc.rs b/src/ipc.rs index b98b0ad77..0bdc3f43b 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -1,7 +1,3 @@ -#[cfg(windows)] -use clipboard::{ - create_cliprdr_context, empty_clipboard, get_rx_clip_client, server_clip_file, set_conn_enabled, -}; use std::{collections::HashMap, sync::atomic::Ordering}; #[cfg(not(windows))] use std::{fs::File, io::prelude::*}; @@ -494,80 +490,6 @@ pub async fn start_pa() { } } -#[cfg(windows)] -#[tokio::main(flavor = "current_thread")] -pub async fn start_clipboard_file( - cm: ConnectionManager, - mut rx: mpsc::UnboundedReceiver, -) { - let mut cliprdr_context = None; - let mut rx_clip_client = get_rx_clip_client().lock().await; - - loop { - tokio::select! { - clip_file = rx_clip_client.recv() => match clip_file { - Some((conn_id, clip)) => { - cmd_inner_send( - &cm, - conn_id, - Data::ClipbaordFile(clip) - ); - } - None => { - // - } - }, - server_msg = rx.recv() => match server_msg { - Some(ClipboardFileData::Clip((conn_id, clip))) => { - if let Some(ctx) = cliprdr_context.as_mut() { - server_clip_file(ctx, conn_id, clip); - } - } - Some(ClipboardFileData::Enable((id, enabled))) => { - if enabled && cliprdr_context.is_none() { - cliprdr_context = Some(match create_cliprdr_context(true, false) { - Ok(context) => { - log::info!("clipboard context for file transfer created."); - context - } - Err(err) => { - log::error!( - "Create clipboard context for file transfer: {}", - err.to_string() - ); - return; - } - }); - } - set_conn_enabled(id, enabled); - if !enabled { - if let Some(ctx) = cliprdr_context.as_mut() { - empty_clipboard(ctx, id); - } - } - } - None => { - break - } - } - } - } -} - -#[cfg(windows)] -fn cmd_inner_send(cm: &ConnectionManager, id: i32, data: Data) { - let lock = cm.read().unwrap(); - if id != 0 { - if let Some(s) = lock.senders.get(&id) { - allow_err!(s.send(data)); - } - } else { - for s in lock.senders.values() { - allow_err!(s.send(data.clone())); - } - } -} - #[inline] #[cfg(not(windows))] fn get_pid_file(postfix: &str) -> String { diff --git a/src/ui/cm.rs b/src/ui/cm.rs index f1b4eaf72..222b9b5c9 100644 --- a/src/ui/cm.rs +++ b/src/ui/cm.rs @@ -1,7 +1,11 @@ -use crate::ipc::{self, new_listener, Connection, Data, start_pa}; -#[cfg(windows)] -use crate::ipc::start_clipboard_file; +#[cfg(target_os = "linux")] +use crate::ipc::start_pa; +use crate::ipc::{self, new_listener, Connection, Data}; use crate::VERSION; +#[cfg(windows)] +use clipboard::{ + create_cliprdr_context, empty_clipboard, get_rx_clip_client, server_clip_file, set_conn_enabled, +}; use hbb_common::fs::{ can_enable_overwrite_detection, get_string, is_write_need_confirmation, new_send_confirm, DigestCheckResult, @@ -158,7 +162,7 @@ impl ConnectionManager { id, file_num, mut files, - overwrite_detection + overwrite_detection, } => { // cm has no show_hidden context // dummy remote, show_hidden, is_remote @@ -435,7 +439,7 @@ impl sciter::EventHandler for ConnectionManager { } } -enum ClipboardFileData { +pub enum ClipboardFileData { #[cfg(windows)] Clip((i32, ipc::ClipbaordFile)), Enable((i32, bool)), @@ -537,3 +541,76 @@ async fn start_ipc(cm: ConnectionManager) { crate::platform::quit_gui(); } +#[cfg(windows)] +#[tokio::main(flavor = "current_thread")] +pub async fn start_clipboard_file( + cm: ConnectionManager, + mut rx: mpsc::UnboundedReceiver, +) { + let mut cliprdr_context = None; + let mut rx_clip_client = get_rx_clip_client().lock().await; + + loop { + tokio::select! { + clip_file = rx_clip_client.recv() => match clip_file { + Some((conn_id, clip)) => { + cmd_inner_send( + &cm, + conn_id, + Data::ClipbaordFile(clip) + ); + } + None => { + // + } + }, + server_msg = rx.recv() => match server_msg { + Some(ClipboardFileData::Clip((conn_id, clip))) => { + if let Some(ctx) = cliprdr_context.as_mut() { + server_clip_file(ctx, conn_id, clip); + } + } + Some(ClipboardFileData::Enable((id, enabled))) => { + if enabled && cliprdr_context.is_none() { + cliprdr_context = Some(match create_cliprdr_context(true, false) { + Ok(context) => { + log::info!("clipboard context for file transfer created."); + context + } + Err(err) => { + log::error!( + "Create clipboard context for file transfer: {}", + err.to_string() + ); + return; + } + }); + } + set_conn_enabled(id, enabled); + if !enabled { + if let Some(ctx) = cliprdr_context.as_mut() { + empty_clipboard(ctx, id); + } + } + } + None => { + break + } + } + } + } +} + +#[cfg(windows)] +fn cmd_inner_send(cm: &ConnectionManager, id: i32, data: Data) { + let lock = cm.read().unwrap(); + if id != 0 { + if let Some(s) = lock.senders.get(&id) { + allow_err!(s.send(data)); + } + } else { + for s in lock.senders.values() { + allow_err!(s.send(data.clone())); + } + } +}