mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 21:24:05 +02:00
better hotkey handeling
This commit is contained in:
parent
1b6e700c7b
commit
2446f7320f
1 changed files with 36 additions and 17 deletions
|
@ -6,24 +6,43 @@ pub fn setup(app_handle: tauri::AppHandle) {
|
|||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
listen(move |event| match event.event_type {
|
||||
EventType::KeyPress(Key::MetaLeft | Key::MetaRight) => {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
listen(move |event| {
|
||||
tx.send(event).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();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue