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(())
})?;