fix chain update

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-04-10 16:02:21 +08:00
parent a767df185f
commit 6e61cfb381
2 changed files with 11 additions and 1 deletions

View File

@ -95,6 +95,11 @@ lazy_static::lazy_static! {
static ref TEXT_CLIPBOARD_STATE: Arc<Mutex<TextClipboardState>> = Arc::new(Mutex::new(TextClipboardState::new()));
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn update_clipboard_text(text: String) {
*OLD_CLIPBOARD_TEXT.lock().unwrap() = text;
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn get_key_state(key: enigo::Key) -> bool {
use enigo::KeyboardControllable;

View File

@ -187,9 +187,14 @@ pub fn update_clipboard(clipboard: Clipboard, old: Option<&Arc<Mutex<String>>>)
}
match ClipboardContext::new() {
Ok(mut ctx) => {
let side = if old.is_none() { "host" } else { "client" };
let host_side = "host";
let client_side = "client";
let side = if old.is_none() { host_side } else { client_side };
let old = if let Some(old) = old { old } else { &CONTENT };
*old.lock().unwrap() = content.clone();
if side == client_side {
crate::client::update_clipboard_text(content.clone());
}
let _lock = ARBOARD_MTX.lock().unwrap();
allow_err!(ctx.set_text(content));
log::debug!("{} updated on {}", CLIPBOARD_NAME, side);