changed tray-message handler to be stateless

This commit is contained in:
Nickiel12 2022-07-16 17:56:22 -07:00
parent 06333b7fe2
commit 3962a48843
2 changed files with 8 additions and 5 deletions

View file

@ -1,4 +1,5 @@
use crossbeam_channel::unbounded; use crossbeam_channel::unbounded;
use tray_icon::TrayIcon;
use std::{io::Read, thread, time::Duration}; use std::{io::Read, thread, time::Duration};
use modules::{ use modules::{
@ -73,12 +74,12 @@ 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()); TrayIcon::handle_tray_messages(&messages);
} }
socket.close(); socket.close();
}); });
while !stop_flag.get() { while !stop_flag.get() {
tray_icon.process_tray_messages(); tray_icon.check_tray_icon_messages();
//tray_icon.check_tray_messages(); //tray_icon.check_tray_messages();
} }

View file

@ -1,7 +1,9 @@
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use std::time::Duration; use std::time::Duration;
use crossbeam_channel::Receiver;
use trayicon::*; use trayicon::*;
use winapi::um::winuser; use winapi::um::winuser;
use workctl::sync_flag::SyncFlagRx;
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Events { pub enum Events {
@ -71,7 +73,7 @@ impl TrayIcon {
} }
} }
pub fn process_tray_messages(&self) { pub fn check_tray_icon_messages(&self) {
unsafe { unsafe {
let mut msg = MaybeUninit::uninit(); let mut msg = MaybeUninit::uninit();
let bret = winuser::PeekMessageA(msg.as_mut_ptr(), 0 as _, 0, 0, 1); let bret = winuser::PeekMessageA(msg.as_mut_ptr(), 0 as _, 0, 0, 1);
@ -85,8 +87,8 @@ impl TrayIcon {
} }
} }
pub fn check_tray_messages(&self) { pub fn handle_tray_messages(message_channel: &Receiver<Events>) {
let message = self.message_channel.recv_timeout(Duration::from_millis(10)); let message = message_channel.recv_timeout(Duration::from_millis(10));
match message { match message {
Err(_) => return, Err(_) => return,
Ok(message) => { Ok(message) => {