better hotkey handeling

This commit is contained in:
pandadev 2024-07-05 18:44:14 +02:00
parent 1b6e700c7b
commit 2446f7320f
No known key found for this signature in database
GPG key ID: C39629DACB8E762F

View file

@ -6,24 +6,43 @@ pub fn setup(app_handle: tauri::AppHandle) {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
std::thread::spawn(move || { std::thread::spawn(move || {
listen(move |event| match event.event_type { listen(move |event| {
EventType::KeyPress(Key::MetaLeft | Key::MetaRight) => { tx.send(event).unwrap();
let _ = tx.send(true);
}
EventType::KeyRelease(Key::KeyV) => {
if rx.try_recv().is_ok() {
let window = app_handle.get_window("main").unwrap();
let is_visible = window.is_visible().unwrap();
if is_visible {
window.hide().unwrap();
} else {
window.show().unwrap();
window.set_focus().unwrap();
}
}
}
_ => {}
}) })
.unwrap(); .unwrap();
}); });
std::thread::spawn(move || {
let mut meta_pressed = false;
while let Ok(event) = rx.recv() {
match event.event_type {
EventType::KeyPress(Key::MetaLeft) | EventType::KeyPress(Key::MetaRight) => {
meta_pressed = true;
println!("Meta key pressed");
}
EventType::KeyRelease(Key::MetaLeft) | EventType::KeyRelease(Key::MetaRight) => {
meta_pressed = false;
println!("Meta key released");
}
EventType::KeyPress(Key::KeyV) => {
println!("V key pressed");
if meta_pressed {
println!("Meta+V detected");
let window = app_handle.get_window("main").unwrap();
let is_visible = window.is_visible().unwrap();
if is_visible {
println!("Hiding window");
window.hide().unwrap();
} else {
println!("Showing window");
window.show().unwrap();
window.set_focus().unwrap();
}
}
}
_ => {}
}
}
});
} }