use arboard::Clipboard; use clipboard_master::Master; use rklipd::{ClipboardEntry, Handler}; use std::error::Error; use std::sync::mpsc::channel; // X11 #[cfg(feature = "x11")] fn main() -> Result<(), Box> { let mut clipboard = Clipboard::new()?; let path = "clipboard.json"; ClipboardEntry::new_json(path).unwrap_or(()); let (tx, rx) = channel(); let mut master = Master::new(Handler { clipboard_tx: tx })?; // let shutdown = master.shutdown_channel(); std::thread::spawn(move || { if let Err(e) = master.run() { eprintln!("Clipboard monitor error : {}", e); } }); println!("Monitoring clipboard X11..."); for _ in rx { println!("Clipboard changed!"); if let Ok(entry) = ClipboardEntry::new(&mut clipboard) { if let Err(e) = entry.append_json(path) { eprintln!("JSON writing error: {}", e); } else { println!("JSON edited!"); } } } Ok(()) } // X11 #[cfg(not(feature = "x11"))] fn main() -> Result<(), Box> { Ok(()) }