Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy error #107

Open
letscubo opened this issue Aug 8, 2023 · 1 comment
Open

copy error #107

letscubo opened this issue Aug 8, 2023 · 1 comment
Labels
waiting on author Further information is requested

Comments

@letscubo
Copy link

letscubo commented Aug 8, 2023

when i use function of get_text(),it makes error: Err(Unknown { .. } - "Unknown error while interacting with the clipboard: failed to read clipboard string") . this error offen happen. could you resolve it?

my code:

`
pub fn get_selected_text_by_clipboard() -> Result<String, Box> {
use arboard::Clipboard;
use std::{thread, time::Duration};

let old_clipboard = (Clipboard::new()?.get_text(), Clipboard::new()?.get_image());

let mut write_clipboard = Clipboard::new()?;

let not_selected_placeholder = "";

write_clipboard.set_text(not_selected_placeholder)?;

thread::sleep(Duration::from_millis(50));

copy();

thread::sleep(Duration::from_millis(100));

let new_text = Clipboard::new()?.get_text();

println!("new_text: {:?}", new_text);

match old_clipboard {
    (Ok(old_text), _) => {
        // Old Content is Text
        write_clipboard.set_text(old_text.clone())?;
        if let Ok(new) = new_text {
            if new.trim() == not_selected_placeholder.trim() {
                Ok(String::new())
            } else {
                Ok(new)
            }
        } else {
            Ok(String::new())
        }
    }
    (_, Ok(image)) => {
        // Old Content is Image
        write_clipboard.set_image(image)?;
        if let Ok(new) = new_text {
            if new.trim() == not_selected_placeholder.trim() {
                Ok(String::new())
            } else {
                Ok(new)
            }
        } else {
            Ok(String::new())
        }
    }
    _ => {
        // Old Content is Empty
        write_clipboard.clear()?;
        if let Ok(new) = new_text {
            if new.trim() == not_selected_placeholder.trim() {
                Ok(String::new())
            } else {
                Ok(new)
            }
        } else {
            Ok(String::new())
        }
    }
}

}

`

@complexspaces
Copy link
Collaborator

Hi @letscubo. Can I first ask what version of Windows you are on and if you have any non-default locales/text encoding setup? (this shouldn't be an issue but I'd like to confirm) If this is still failing for you I can open a branch with more debug logging if you'd like to try that, which may show more specific details about the error from the system.

Additionally, do you know which of your get_text calls are failing?

@complexspaces complexspaces added the waiting on author Further information is requested label Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting on author Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants