mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
move clipboard file service to cm module
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
81
src/ui/cm.rs
81
src/ui/cm.rs
@@ -1,4 +1,6 @@
|
||||
use crate::ipc::{self, new_listener, Connection, Data};
|
||||
#[cfg(windows)]
|
||||
use clipboard::{create_cliprdr_context, get_rx_clip_client, server_clip_file, ConnID};
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
config::{Config, ICON},
|
||||
@@ -106,6 +108,7 @@ impl ConnectionManager {
|
||||
&self,
|
||||
id: i32,
|
||||
data: Data,
|
||||
_tx_clip_file: &mpsc::UnboundedSender<(i32, ipc::ClipbaordFile)>,
|
||||
write_jobs: &mut Vec<fs::TransferJob>,
|
||||
conn: &mut Connection,
|
||||
) {
|
||||
@@ -186,6 +189,10 @@ impl ConnectionManager {
|
||||
}
|
||||
}
|
||||
},
|
||||
Data::ClipbaordFile(_clip) => {
|
||||
#[cfg(windows)]
|
||||
allow_err!(_tx_clip_file.send((id, _clip)));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -326,6 +333,12 @@ impl sciter::EventHandler for ConnectionManager {
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn start_ipc(cm: ConnectionManager) {
|
||||
let (tx_file, _rx_file) = mpsc::unbounded_channel::<(i32, ipc::ClipbaordFile)>();
|
||||
#[cfg(windows)]
|
||||
let cm_clip = cm.clone();
|
||||
#[cfg(windows)]
|
||||
std::thread::spawn(move || start_clipboard_file(cm_clip, _rx_file));
|
||||
|
||||
match new_listener("_cm").await {
|
||||
Ok(mut incoming) => {
|
||||
while let Some(result) = incoming.next().await {
|
||||
@@ -333,6 +346,7 @@ async fn start_ipc(cm: ConnectionManager) {
|
||||
Ok(stream) => {
|
||||
let mut stream = Connection::new(stream);
|
||||
let cm = cm.clone();
|
||||
let tx_file = tx_file.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut conn_id: i32 = 0;
|
||||
let (tx, mut rx) = mpsc::unbounded_channel::<Data>();
|
||||
@@ -356,7 +370,7 @@ async fn start_ipc(cm: ConnectionManager) {
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
cm.handle_data(conn_id, data, &mut write_jobs, &mut stream).await;
|
||||
cm.handle_data(conn_id, data, &tx_file, &mut write_jobs, &mut stream).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,3 +479,68 @@ async fn start_pa() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn start_clipboard_file(
|
||||
cm: ConnectionManager,
|
||||
mut rx: mpsc::UnboundedReceiver<(i32, ipc::ClipbaordFile)>,
|
||||
) {
|
||||
let mut cliprdr_context = 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;
|
||||
}
|
||||
};
|
||||
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.server_conn_id as i32,
|
||||
Data::ClipbaordFile(clip)
|
||||
);
|
||||
}
|
||||
None => {
|
||||
//
|
||||
}
|
||||
},
|
||||
server_msg = rx.recv() => match server_msg {
|
||||
Some((server_conn_id, clip)) => {
|
||||
let conn_id = ConnID {
|
||||
server_conn_id: server_conn_id as u32,
|
||||
remote_conn_id: 0,
|
||||
};
|
||||
server_clip_file(&mut cliprdr_context, conn_id, clip);
|
||||
}
|
||||
None => {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn cmd_inner_send<'a>(cm: &'a 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
use crate::client::*;
|
||||
use crate::common::{
|
||||
self, check_clipboard, update_clipboard, ClipboardContext, CLIPBOARD_INTERVAL,
|
||||
#[cfg(windows)]
|
||||
use crate::{
|
||||
client::*,
|
||||
clipboard_file::*,
|
||||
common::{self, check_clipboard, update_clipboard, ClipboardContext, CLIPBOARD_INTERVAL},
|
||||
};
|
||||
#[cfg(not(windows))]
|
||||
use crate::{
|
||||
client::*,
|
||||
common::{self, check_clipboard, update_clipboard, ClipboardContext, CLIPBOARD_INTERVAL},
|
||||
};
|
||||
#[cfg(windows)]
|
||||
use clipboard::{
|
||||
cliprdr::CliprdrClientContext, create_cliprdr_context as create_clipboard_file_context,
|
||||
get_rx_client_msg as get_clipboard_file_rx_client_msg, server_msg as clipboard_file_msg,
|
||||
ConnID as ClipboardFileConnID,
|
||||
get_rx_clip_client, server_clip_file, ConnID as ClipboardFileConnID,
|
||||
};
|
||||
use enigo::{self, Enigo, KeyboardControllable};
|
||||
use hbb_common::{
|
||||
@@ -1313,9 +1319,9 @@ impl Remote {
|
||||
|
||||
// just build for now
|
||||
#[cfg(not(windows))]
|
||||
let (_, mut clipboard_file_client_rx) = mpsc::unbounded_channel::<i32>();
|
||||
let (_, mut rx_clip_client) = mpsc::unbounded_channel::<i32>();
|
||||
#[cfg(windows)]
|
||||
let mut clipboard_file_client_rx = get_clipboard_file_rx_client_msg().lock().await;
|
||||
let mut rx_clip_client = get_rx_clip_client().lock().await;
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
@@ -1347,12 +1353,12 @@ impl Remote {
|
||||
}
|
||||
}
|
||||
}
|
||||
_msg = clipboard_file_client_rx.recv() => {
|
||||
_msg = rx_clip_client.recv() => {
|
||||
#[cfg(windows)]
|
||||
match _msg {
|
||||
Some((conn_id, msg)) => {
|
||||
Some((conn_id, clip)) => {
|
||||
if conn_id.remote_conn_id == 0 || conn_id.remote_conn_id == self.pid {
|
||||
allow_err!(peer.send(&msg).await);
|
||||
allow_err!(peer.send(&clip_2_msg(clip)).await);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
@@ -1740,14 +1746,16 @@ impl Remote {
|
||||
Some(message::Union::cliprdr(clip)) => {
|
||||
if !self.handler.lc.read().unwrap().disable_clipboard {
|
||||
if let Some(context) = &mut self.clipboard_file_context {
|
||||
clipboard_file_msg(
|
||||
context,
|
||||
ClipboardFileConnID {
|
||||
server_conn_id: 0,
|
||||
remote_conn_id: self.pid,
|
||||
},
|
||||
clip,
|
||||
);
|
||||
if let Some(clip) = msg_2_clip(clip) {
|
||||
server_clip_file(
|
||||
context,
|
||||
ClipboardFileConnID {
|
||||
server_conn_id: 0,
|
||||
remote_conn_id: self.pid,
|
||||
},
|
||||
clip,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user