This commit is contained in:
open-trade
2021-12-23 17:44:44 +08:00
parent 252d3cb797
commit a30aaebc72
5 changed files with 79 additions and 48 deletions

View File

@@ -95,7 +95,10 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>)
let side = if old.is_none() { "host" } else { "client" };
let old = if let Some(old) = old { old } else { &CONTENT };
*old.lock().unwrap() = content.clone();
allow_err!(ctx.set_text(content));
if !content.is_empty() {
// empty content make ctx.set_text crash
allow_err!(ctx.set_text(content));
}
log::debug!("{} updated on {}", CLIPBOARD_NAME, side);
}
Err(err) => {
@@ -240,7 +243,8 @@ async fn test_nat_type_() -> ResultType<bool> {
let rendezvous_server = get_rendezvous_server(100).await;
let server1 = rendezvous_server;
let mut server2 = server1;
if server1.port() == 0 { // offline
if server1.port() == 0 {
// offline
// avoid overflow crash
bail!("Offline");
}

View File

@@ -97,8 +97,12 @@ mod listen {
fn trigger(ctx: &mut ClipboardContext) {
let _ = match ctx.get_text() {
Ok(text) => ctx.set_text(text),
Err(_) => ctx.set_text(Default::default()),
Ok(text) => {
if !text.is_empty() {
ctx.set_text(text).ok();
}
}
Err(_) => {}
};
}
}

View File

@@ -220,7 +220,7 @@ fn run(sp: GenericService) -> ResultType<()> {
let start = time::Instant::now();
let mut last_check_displays = time::Instant::now();
#[cfg(windows)]
let mut try_gdi = true;
let mut try_gdi = 1;
#[cfg(windows)]
log::info!("gdi: {}", c.is_gdi());
while sp.ok() {
@@ -261,7 +261,7 @@ fn run(sp: GenericService) -> ResultType<()> {
frame_controller.set_send(now, send_conn_ids);
#[cfg(windows)]
{
try_gdi = false;
try_gdi = 0;
}
}
Err(ref e) if e.kind() == WouldBlock => {
@@ -271,10 +271,13 @@ fn run(sp: GenericService) -> ResultType<()> {
wait = 0
}
#[cfg(windows)]
if try_gdi && !c.is_gdi() {
c.set_gdi();
try_gdi = false;
log::info!("No image, fall back to gdi");
if try_gdi > 0 && !c.is_gdi() {
if try_gdi > 3 {
c.set_gdi();
try_gdi = 0;
log::info!("No image, fall back to gdi");
}
try_gdi += 1;
}
continue;
}