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::*;
|
use super::*;
|
||||||
|
|
||||||
static RUNNING: AtomicBool = AtomicBool::new(true);
|
static RUNNING: AtomicBool = AtomicBool::new(true);
|
||||||
static WAIT: Duration = Duration::from_millis(1500);
|
static WAIT: Duration = Duration::from_millis(33);
|
||||||
|
|
||||||
struct ClipHandle {
|
struct ClipHandle {
|
||||||
tx: SyncSender<()>,
|
tx: SyncSender<()>,
|
||||||
@ -69,21 +69,34 @@ mod listen {
|
|||||||
let _ = Master::new(ClipHandle { tx }).run();
|
let _ = Master::new(ClipHandle { tx }).run();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
check_clipboard(&mut ctx, None); // initialize CONTENT for snapshot
|
||||||
while sp.ok() {
|
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 Ok(_) = rx.recv_timeout(WAIT) {
|
||||||
if let Some(msg) = check_clipboard(&mut ctx, None) {
|
if let Some(msg) = check_clipboard(&mut ctx, None) {
|
||||||
sp.send(msg);
|
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);
|
RUNNING.store(false, Ordering::SeqCst);
|
||||||
@ -96,13 +109,13 @@ mod listen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn trigger(ctx: &mut ClipboardContext) {
|
fn trigger(ctx: &mut ClipboardContext) {
|
||||||
|
let mut old_text = "".to_owned();
|
||||||
let _ = match ctx.get_text() {
|
let _ = match ctx.get_text() {
|
||||||
Ok(text) => {
|
Ok(text) => {
|
||||||
if !text.is_empty() {
|
old_text = text;
|
||||||
ctx.set_text(text).ok();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
};
|
};
|
||||||
|
ctx.set_text(old_text).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ impl Connection {
|
|||||||
if let Err(e) = handler_input.join() {
|
if let Err(e) = handler_input.join() {
|
||||||
log::error!("Failed to join input thread, {:?}", e);
|
log::error!("Failed to join input thread, {:?}", e);
|
||||||
} else {
|
} else {
|
||||||
log::info!("Blank thread exited");
|
log::info!("input thread exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = crate::platform::block_input(false);
|
let _ = crate::platform::block_input(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user