feat: clipboard, multi format (#8672)

* feat: clipboard, multi format

Signed-off-by: fufesou <linlong1266@gmail.com>

* inline

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2024-07-11 00:05:25 +08:00
committed by GitHub
parent e2d217a138
commit 011647511c
10 changed files with 376 additions and 501 deletions

View File

@@ -1,7 +1,7 @@
use super::*;
pub use crate::clipboard::{
check_clipboard, ClipboardContext, CLIPBOARD_INTERVAL as INTERVAL, CLIPBOARD_NAME as NAME,
CONTENT,
check_clipboard, get_cache_msg, ClipboardContext, ClipboardSide,
CLIPBOARD_INTERVAL as INTERVAL, CLIPBOARD_NAME as NAME,
};
#[derive(Default)]
@@ -11,7 +11,7 @@ struct State {
impl super::service::Reset for State {
fn reset(&mut self) {
*CONTENT.lock().unwrap() = Default::default();
crate::clipboard::reset_cache();
self.ctx = None;
}
@@ -34,14 +34,14 @@ pub fn new() -> GenericService {
}
fn run(sp: EmptyExtraFieldService, state: &mut State) -> ResultType<()> {
if let Some(msg) = check_clipboard(&mut state.ctx, None) {
if let Some(msg) = check_clipboard(&mut state.ctx, ClipboardSide::Host) {
sp.send(msg);
}
sp.snapshot(|sps| {
let data = CONTENT.lock().unwrap().clone();
if !data.is_empty() {
let msg_out = data.create_msg();
sps.send_shared(Arc::new(msg_out));
// Just create a message with multi clipboards here
// The actual peer version and peer platform will be checked again before sending.
if let Some(msg) = get_cache_msg("1.2.7", "Windows") {
sps.send_shared(Arc::new(msg));
}
Ok(())
})?;

View File

@@ -1,6 +1,6 @@
use super::{input_service::*, *};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::clipboard::update_clipboard;
use crate::clipboard::{update_clipboard, ClipboardSide};
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
use crate::clipboard_file::*;
#[cfg(target_os = "android")]
@@ -685,8 +685,19 @@ impl Connection {
msg = Arc::new(new_msg);
}
}
Some(message::Union::MultiClipboards(_multi_clipboards)) => {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if let Some(msg_out) = crate::clipboard::get_msg_if_not_support_multi_clip(&conn.lr.version, &conn.lr.my_platform, _multi_clipboards) {
if let Err(err) = conn.stream.send(&msg_out).await {
conn.on_close(&err.to_string(), false).await;
break;
}
continue;
}
}
_ => {}
}
let msg: &Message = &msg;
if let Err(err) = conn.stream.send(msg).await {
conn.on_close(&err.to_string(), false).await;
@@ -2053,7 +2064,14 @@ impl Connection {
{
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.clipboard {
update_clipboard(_cb, None);
update_clipboard(vec![_cb], ClipboardSide::Host);
}
}
Some(message::Union::MultiClipboards(_mcb)) =>
{
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.clipboard {
update_clipboard(_mcb.clipboards, ClipboardSide::Host);
}
}
Some(message::Union::Cliprdr(_clip)) =>