use std::sync::mpsc;
use copypasta::{ClipboardContext, ClipboardProvider};
use crate::events::messages::Message;
pub fn copy_to_clipboard(content: String, msg_tx: mpsc::Sender<Message>) {
tokio::spawn(handle_copy_to_clipboard(content, msg_tx));
}
async fn handle_copy_to_clipboard(content: String, msg_tx: mpsc::Sender<Message>) {
match ClipboardContext::new() {
Ok(mut ctx) => match ctx.set_contents(content) {
Ok(_) => {
msg_tx.send(Message::PrintSuccess(String::from(
"Public key copied to clipboard",
))).expect("Failed to send success message");
}
Err(err) => {
msg_tx.send(Message::PrintError(format!(
"Failed to copy to clipboard: {}",
err
))).expect("Failed to send error notice");
}
},
Err(err) => {
msg_tx.send(Message::PrintError(format!(
"Failed to load clipboard: {}",
err
))).expect("Failed to send error notice");
}
};
}