#[cfg(not(test))]
use objc2_app_kit::{NSPasteboard, NSPasteboardTypeString};
#[cfg(not(test))]
use objc2_foundation::NSString;
#[cfg(not(test))]
use tracing::warn;
#[cfg(test)]
static TEST_CLIPBOARD: std::sync::Mutex<Option<String>> = std::sync::Mutex::new(None);
#[cfg(test)]
pub fn get_test_clipboard() -> Option<String> {
TEST_CLIPBOARD.lock().unwrap().clone()
}
pub fn copy_to_clipboard(text: &str) -> bool {
#[cfg(test)]
{
*TEST_CLIPBOARD.lock().unwrap() = Some(text.to_owned());
true
}
#[cfg(not(test))]
{
let pasteboard = NSPasteboard::generalPasteboard();
pasteboard.clearContents();
let string_type = unsafe { NSPasteboardTypeString };
let copied = pasteboard.setString_forType(&NSString::from_str(text), string_type);
if !copied {
warn!("unable to write to the general pasteboard");
}
copied
}
}