feat: add x11 clipboard support

Signed-off-by: 蔡略 <cailue@bupt.edu.cn>
This commit is contained in:
蔡略
2023-09-08 19:39:00 +08:00
parent 4f7036a405
commit 25cf36a948
12 changed files with 1233 additions and 512 deletions

View File

@@ -5,7 +5,7 @@ use std::sync::{
Arc,
};
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
use clipboard::ContextSend;
use crossbeam_queue::ArrayQueue;
use hbb_common::config::{PeerConfig, TransferSerde};
@@ -20,7 +20,7 @@ use hbb_common::rendezvous_proto::ConnType;
use hbb_common::sleep;
#[cfg(not(target_os = "ios"))]
use hbb_common::tokio::sync::mpsc::error::TryRecvError;
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
use hbb_common::tokio::sync::Mutex as TokioMutex;
use hbb_common::tokio::{
self,
@@ -57,7 +57,7 @@ pub struct Remote<T: InvokeUiSession> {
timer: Interval,
last_update_jobs_status: (Instant, HashMap<i32, u64>),
first_frame: bool,
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
client_conn_id: i32, // used for file clipboard
data_count: Arc<AtomicUsize>,
frame_count: Arc<AtomicUsize>,
@@ -91,7 +91,7 @@ impl<T: InvokeUiSession> Remote<T> {
timer: time::interval(SEC30),
last_update_jobs_status: (Instant::now(), Default::default()),
first_frame: false,
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
client_conn_id: 0,
data_count: Arc::new(AtomicUsize::new(0)),
frame_count,
@@ -131,14 +131,14 @@ impl<T: InvokeUiSession> Remote<T> {
}
// just build for now
#[cfg(not(windows))]
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
let (_tx_holder, mut rx_clip_client) = mpsc::unbounded_channel::<i32>();
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
let (_tx_holder, rx) = mpsc::unbounded_channel();
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
let mut rx_clip_client_lock = Arc::new(TokioMutex::new(rx));
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
let is_conn_not_default = self.handler.is_file_transfer()
|| self.handler.is_port_forward()
@@ -148,7 +148,7 @@ impl<T: InvokeUiSession> Remote<T> {
clipboard::get_rx_cliprdr_client(&self.handler.session_id);
};
}
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
let mut rx_clip_client = rx_clip_client_lock.lock().await;
let mut status_timer = time::interval(Duration::new(1, 0));
@@ -204,7 +204,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
_msg = rx_clip_client.recv() => {
#[cfg(windows)]
#[cfg(any(target_os="windows", target_os="linux"))]
match _msg {
Some(clip) => match clip {
clipboard::ClipboardFile::NotifyCallback{r#type, title, text} => {
@@ -278,11 +278,11 @@ impl<T: InvokeUiSession> Remote<T> {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Client::try_stop_clipboard(&self.handler.session_id);
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
let conn_id = self.client_conn_id;
let _ = ContextSend::proc(|context| -> ResultType<()> {
context.empty_clipboard(conn_id);
context.empty_clipboard(conn_id)?;
Ok(())
});
}
@@ -1031,7 +1031,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
}
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
Some(message::Union::Cliprdr(clip)) => {
self.handle_cliprdr_msg(clip);
}
@@ -1551,7 +1551,7 @@ impl<T: InvokeUiSession> Remote<T> {
#[cfg(not(feature = "flutter"))]
fn check_clipboard_file_context(&self) {
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
let enabled = *self.handler.server_file_transfer_enabled.read().unwrap()
&& self.handler.lc.read().unwrap().enable_file_transfer.v;
@@ -1559,7 +1559,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
}
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
fn handle_cliprdr_msg(&self, clip: hbb_common::message_proto::Cliprdr) {
#[cfg(feature = "flutter")]
if let Some(hbb_common::message_proto::cliprdr::Union::FormatList(_)) = &clip.union {

View File

@@ -59,7 +59,7 @@ mod ui_session_interface;
mod hbbs_http;
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
pub mod clipboard_file;
#[cfg(windows)]

View File

@@ -63,8 +63,8 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
let open_func = move || {
#[cfg(not(feature = "flutter"))]
{
crate::run_me::<&str>(vec![]).ok();
return;
crate::run_me::<&str>(vec![]).ok();
return;
}
#[cfg(target_os = "macos")]
crate::platform::macos::handle_application_should_open_untitled_file();

View File

@@ -1,6 +1,6 @@
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
use std::iter::FromIterator;
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
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(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
use clipboard::ContextSend;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::tokio::sync::mpsc::unbounded_channel;
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
use hbb_common::tokio::sync::Mutex as TokioMutex;
use hbb_common::{
allow_err,
@@ -71,9 +71,9 @@ struct IpcTaskRunner<T: InvokeUiCM> {
running: bool,
authorized: bool,
conn_id: i32,
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
file_transfer_enabled: bool,
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
file_transfer_enabled_peer: bool,
}
@@ -174,10 +174,10 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
.map(|c| c.disconnected = true);
}
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
let _ = ContextSend::proc(|context| -> ResultType<()> {
context.empty_clipboard(id);
context.empty_clipboard(id)?;
Ok(())
});
}
@@ -318,11 +318,11 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
// for tmp use, without real conn id
let mut write_jobs: Vec<fs::TransferJob> = Vec::new();
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
let rx_clip1;
let mut rx_clip;
let _tx_clip;
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
if self.conn_id > 0 && self.authorized {
rx_clip1 = clipboard::get_rx_cliprdr_server(self.conn_id);
rx_clip = rx_clip1.lock().await;
@@ -332,12 +332,12 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
rx_clip1 = Arc::new(TokioMutex::new(rx_clip2));
rx_clip = rx_clip1.lock().await;
}
#[cfg(not(windows))]
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
{
(_tx_clip, rx_clip) = unbounded_channel::<i32>();
}
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
if ContextSend::is_enabled() {
allow_err!(
@@ -402,7 +402,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Data::ClipboardFile(_clip) => {
#[cfg(windows)]
#[cfg(any(windows, linux))]
{
let is_stopping_allowed = _clip.is_stopping_allowed_from_peer();
let is_clipboard_enabled = ContextSend::is_enabled();
@@ -423,7 +423,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
}
}
Data::ClipboardFileEnabled(_enabled) => {
#[cfg(windows)]
#[cfg(any(target_os= "windows",target_os ="linux"))]
{
self.file_transfer_enabled_peer = _enabled;
}
@@ -468,7 +468,7 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
}
clip_file = rx_clip.recv() => match clip_file {
Some(_clip) => {
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os ="linux"))]
{
let is_stopping_allowed = _clip.is_stopping_allowed();
let is_clipboard_enabled = ContextSend::is_enabled();
@@ -505,9 +505,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
running: true,
authorized: false,
conn_id: 0,
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
file_transfer_enabled: false,
#[cfg(windows)]
#[cfg(any(target_os = "windows", target_os = "linux"))]
file_transfer_enabled_peer: false,
};