image handeling

This commit is contained in:
pandadev 2024-07-05 03:39:38 +02:00
parent 296a844aaa
commit 2695d8cd4c
No known key found for this signature in database
GPG key ID: C39629DACB8E762F
9 changed files with 427 additions and 112 deletions

29
src-tauri/src/hotkeys.rs Normal file
View file

@ -0,0 +1,29 @@
use rdev::{listen, EventType, Key};
use std::sync::mpsc;
use tauri::Manager;
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();
}
}
}
_ => {}
})
.unwrap();
});
}