optimisations
This commit is contained in:
@ -1,7 +1,44 @@
|
||||
use crate::database::Database;
|
||||
use crate::{database::Database, models::ClipboardEntry};
|
||||
use arboard::Clipboard;
|
||||
use std::error::Error;
|
||||
use std::time::Duration;
|
||||
use std::{error::Error, sync::mpsc::channel};
|
||||
use wayland_clipboard_listener::{WlClipboardPasteStream, WlListenType};
|
||||
|
||||
pub fn start(db: Database, mut clipboard: Clipboard) -> Result<(), Box<dyn Error>> {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
std::thread::spawn(
|
||||
move || match WlClipboardPasteStream::init(WlListenType::ListenOnCopy) {
|
||||
Ok(mut stream) => {
|
||||
for _ in stream.paste_stream().flatten() {
|
||||
std::thread::sleep(Duration::new(1, 0));
|
||||
if let Err(e) = tx.send(()) {
|
||||
eprintln!("{}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
for _ in rx {
|
||||
println!("Clipboard update!");
|
||||
// if let Ok(entry) = ClipboardEntry::new(&mut clipboard) {
|
||||
// if let Err(e) = db.append(entry) {
|
||||
// eprintln!("SQLite writing error: {}", e);
|
||||
// } else {
|
||||
// println!("SQLite edited!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
match ClipboardEntry::new(&mut clipboard) {
|
||||
Ok(entry) => db.append(entry)?,
|
||||
Err(e) => eprintln!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user