From 37f763f3eb6ca44b8397d6c15483a9ecdbb17e0a Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 4 Sep 2023 15:30:07 +0300 Subject: [PATCH] chore: fix egui example, loop in the thread --- examples/egui.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/egui.rs b/examples/egui.rs index 20ced21..76cef93 100644 --- a/examples/egui.rs +++ b/examples/egui.rs @@ -1,5 +1,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +use std::time::Duration; + use eframe::egui; use global_hotkey::{hotkey::HotKey, GlobalHotKeyEvent, GlobalHotKeyManager}; use keyboard_types::{Code, Modifiers}; @@ -8,10 +10,12 @@ fn main() -> Result<(), eframe::Error> { let manager = GlobalHotKeyManager::new().unwrap(); let hotkey = HotKey::new(Some(Modifiers::SHIFT), Code::KeyD); manager.register(hotkey).unwrap(); - std::thread::spawn(|| { - if let Ok(event) = GlobalHotKeyEvent::receiver().try_recv() { + let receiver = GlobalHotKeyEvent::receiver(); + std::thread::spawn(|| loop { + if let Ok(event) = receiver.try_recv() { println!("tray event: {event:?}"); } + std::thread::sleep(Duration::from_millis(100)); }); let options = eframe::NativeOptions {