blob: c4444e3c5e8ca92ed23e4d8e5e6a5571754f0525 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
lazy_static::lazy_static! {
static ref CLIPBOARD: std::sync::Arc<std::sync::Mutex<Option<arboard::Clipboard>>> =
std::sync::Arc::new(std::sync::Mutex::new(arboard::Clipboard::new().ok()));
}
#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
pub fn set_text(text: &str) -> anyhow::Result<()> {
let mut clipboard = CLIPBOARD.lock().unwrap();
match clipboard.as_mut() {
Some(clipboard) => {
clipboard.set_text(text)?;
#[cfg(target_os = "linux")]
std::thread::sleep(std::time::Duration::from_millis(50));
}
None => anyhow::bail!("Failed to copy the text; no available clipboard"),
}
Ok(())
}
#[cfg(any(target_os = "android", target_os = "emscripten"))]
pub fn set_text(_text: &str) -> anyhow::Result<()> {
anyhow::bail!("Failed to copy the text; no available clipboard")
}
|