fixed return key press issue

This commit is contained in:
WanderingPenwing 2024-08-01 17:48:30 +02:00
parent ea7905fa8e
commit 83fdad8c2c

View file

@ -1,4 +1,4 @@
use rdev::{grab, Event, EventType, Key}; use rdev::{grab, Event, EventType, Key, simulate};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::task; use tokio::task;
use tokio::process::Command; use tokio::process::Command;
@ -22,7 +22,7 @@ struct History {
impl History { impl History {
fn new() -> Self { fn new() -> Self {
Self { Self {
entries: vec!["1".into(), "2".into(), "3".into()], entries: vec![],
clipboard: Clipboard::new().unwrap(), clipboard: Clipboard::new().unwrap(),
} }
} }
@ -39,13 +39,13 @@ impl History {
self.entries.insert(0, clip); self.entries.insert(0, clip);
} }
async fn paste(&self) { async fn paste(&mut self) {
if self.entries.len() == 0 { if self.entries.len() == 0 {
return return
} }
match self.select_entry().await { match self.select_entry().await {
Ok(entry) => { Ok(entry) => {
println!("# {}", entry); let _ = self.clipboard.set_text(entry);
} }
Err(why) => { Err(why) => {
eprintln!("error pasting clipboard : {}", why); eprintln!("error pasting clipboard : {}", why);
@ -112,6 +112,8 @@ async fn main() {
Some(event) Some(event)
}; };
let _ = simulate(&EventType::KeyRelease(Key::Return));
// Spawn a task to handle the event grabbing // Spawn a task to handle the event grabbing
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
@ -142,13 +144,11 @@ async fn main() {
} }
Hotkey::KeyC => { Hotkey::KeyC => {
if ctrl_pressed { if ctrl_pressed {
println!("copied");
history.update(); history.update();
} }
} }
Hotkey::KeyV => { Hotkey::KeyV => {
if mod_pressed { if mod_pressed {
println!("paste");
history.paste().await; history.paste().await;
} }
} }