mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-19 00:13:01 +08:00
fix clipboard initial sync issue introduced in the PR
This commit is contained in:
parent
aa1c0df08f
commit
d313fa92e1
@ -24,7 +24,7 @@ mod listen {
|
||||
use super::*;
|
||||
|
||||
static RUNNING: AtomicBool = AtomicBool::new(true);
|
||||
static WAIT: Duration = Duration::from_millis(1500);
|
||||
static WAIT: Duration = Duration::from_millis(33);
|
||||
|
||||
struct ClipHandle {
|
||||
tx: SyncSender<()>,
|
||||
@ -69,21 +69,34 @@ mod listen {
|
||||
let _ = Master::new(ClipHandle { tx }).run();
|
||||
});
|
||||
|
||||
check_clipboard(&mut ctx, None); // initialize CONTENT for snapshot
|
||||
while sp.ok() {
|
||||
let mut update = None;
|
||||
sp.snapshot(|sps| {
|
||||
if sps.has_subscribes() {
|
||||
update = check_clipboard(&mut ctx, None);
|
||||
}
|
||||
// if there is update, msg will be later together,
|
||||
// otherwise it will be only sent to new subscriber,
|
||||
// but old subscribers ignored
|
||||
if update.is_none() {
|
||||
let txt = crate::CONTENT.lock().unwrap().clone();
|
||||
if !txt.is_empty() {
|
||||
let msg_out = crate::create_clipboard_msg(txt);
|
||||
sps.send_shared(Arc::new(msg_out));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
if let Some(msg) = update {
|
||||
sp.send(msg);
|
||||
}
|
||||
|
||||
if let Ok(_) = rx.recv_timeout(WAIT) {
|
||||
if let Some(msg) = check_clipboard(&mut ctx, None) {
|
||||
sp.send(msg);
|
||||
}
|
||||
}
|
||||
|
||||
sp.snapshot(|sps| {
|
||||
let txt = crate::CONTENT.lock().unwrap().clone();
|
||||
if !txt.is_empty() {
|
||||
let msg_out = crate::create_clipboard_msg(txt);
|
||||
sps.send_shared(Arc::new(msg_out));
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
|
||||
RUNNING.store(false, Ordering::SeqCst);
|
||||
@ -96,13 +109,13 @@ mod listen {
|
||||
}
|
||||
|
||||
fn trigger(ctx: &mut ClipboardContext) {
|
||||
let mut old_text = "".to_owned();
|
||||
let _ = match ctx.get_text() {
|
||||
Ok(text) => {
|
||||
if !text.is_empty() {
|
||||
ctx.set_text(text).ok();
|
||||
}
|
||||
old_text = text;
|
||||
}
|
||||
Err(_) => {}
|
||||
};
|
||||
ctx.set_text(old_text).ok();
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ impl Connection {
|
||||
if let Err(e) = handler_input.join() {
|
||||
log::error!("Failed to join input thread, {:?}", e);
|
||||
} else {
|
||||
log::info!("Blank thread exited");
|
||||
log::info!("input thread exited");
|
||||
}
|
||||
|
||||
let _ = crate::platform::block_input(false);
|
||||
|
Loading…
Reference in New Issue
Block a user