working version of tray_icon events

This commit is contained in:
Nickiel12 2022-07-16 21:08:52 -07:00
parent 1d97546bbe
commit fdb60f6e00
2 changed files with 31 additions and 21 deletions

View file

@ -48,6 +48,9 @@ fn main() {
let mut state = StreamState::new(); let mut state = StreamState::new();
//until control_c is caught, check the queue of incoming //until control_c is caught, check the queue of incoming
//requests from the socket handler. //requests from the socket handler.
let stop_flag = control_c_called_flag_rx.clone();
let messages = tray_icon.message_channel.clone();
std::thread::spawn(move || {
while !control_c_called_flag_rx.get() { while !control_c_called_flag_rx.get() {
match from_socket_rx.recv_timeout(Duration::from_millis(100)) { match from_socket_rx.recv_timeout(Duration::from_millis(100)) {
Ok(message) => { Ok(message) => {
@ -65,12 +68,16 @@ fn main() {
let tick_update = state.tick(); let tick_update = state.tick();
handle_instructions(tick_update, &mut state, &socket, &hotkeys); handle_instructions(tick_update, &mut state, &socket, &hotkeys);
println!("{:?}", messages.recv());
}
socket.close();
});
while !stop_flag.get() {
tray_icon.process_tray_messages(); tray_icon.process_tray_messages();
//tray_icon.check_tray_messages();
} }
println!("closing main thread"); println!("closing main thread");
socket.close();
hotkey_handle.join().unwrap(); hotkey_handle.join().unwrap();
} }

View file

@ -20,7 +20,7 @@ pub enum Events {
pub struct TrayIcon { pub struct TrayIcon {
tray_icon: trayicon::TrayIcon<Events>, tray_icon: trayicon::TrayIcon<Events>,
message_channel: crossbeam_channel::Receiver<Events>, pub message_channel: crossbeam_channel::Receiver<Events>,
} }
impl TrayIcon { impl TrayIcon {
@ -35,7 +35,7 @@ impl TrayIcon {
let first_icon = Icon::from_buffer(icon1, None, None).unwrap(); let first_icon = Icon::from_buffer(icon1, None, None).unwrap();
// Needlessly complicated tray icon with all the whistles and bells // Needlessly complicated tray icon with all the whistles and bells
let mut tray_icon = TrayIconBuilder::new() let tray_icon = TrayIconBuilder::new()
.sender_crossbeam(s) .sender_crossbeam(s)
.icon_from_buffer(icon1) .icon_from_buffer(icon1)
.tooltip("Cool Tray 👀 Icon") .tooltip("Cool Tray 👀 Icon")
@ -76,7 +76,7 @@ impl TrayIcon {
pub fn process_tray_messages(&self) { pub fn process_tray_messages(&self) {
unsafe { unsafe {
let mut msg = MaybeUninit::uninit(); let mut msg = MaybeUninit::uninit();
let bret = winuser::PeekMessageW(msg.as_mut_ptr(), 0 as _, 0, 0, 1); let bret = winuser::GetMessageA(msg.as_mut_ptr(), 0 as _, 0, 0);
if bret > 0 { if bret > 0 {
winuser::TranslateMessage(msg.as_ptr()); winuser::TranslateMessage(msg.as_ptr());
@ -85,6 +85,9 @@ impl TrayIcon {
return; return;
} }
} }
}
pub fn check_tray_messages(&self){
let message = self.message_channel.recv_timeout(Duration::from_millis(10)); let message = self.message_channel.recv_timeout(Duration::from_millis(10));
match message { match message {