changed tray-message handler to be stateless
This commit is contained in:
parent
06333b7fe2
commit
3962a48843
2 changed files with 8 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
|||
use crossbeam_channel::unbounded;
|
||||
use tray_icon::TrayIcon;
|
||||
use std::{io::Read, thread, time::Duration};
|
||||
|
||||
use modules::{
|
||||
|
@ -73,12 +74,12 @@ fn main() {
|
|||
|
||||
let tick_update = state.tick();
|
||||
handle_instructions(tick_update, &mut state, &socket, &hotkeys);
|
||||
println!("{:?}", messages.recv());
|
||||
TrayIcon::handle_tray_messages(&messages);
|
||||
}
|
||||
socket.close();
|
||||
});
|
||||
while !stop_flag.get() {
|
||||
tray_icon.process_tray_messages();
|
||||
tray_icon.check_tray_icon_messages();
|
||||
//tray_icon.check_tray_messages();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use core::mem::MaybeUninit;
|
||||
use std::time::Duration;
|
||||
use crossbeam_channel::Receiver;
|
||||
use trayicon::*;
|
||||
use winapi::um::winuser;
|
||||
use workctl::sync_flag::SyncFlagRx;
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum Events {
|
||||
|
@ -71,7 +73,7 @@ impl TrayIcon {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn process_tray_messages(&self) {
|
||||
pub fn check_tray_icon_messages(&self) {
|
||||
unsafe {
|
||||
let mut msg = MaybeUninit::uninit();
|
||||
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) {
|
||||
let message = self.message_channel.recv_timeout(Duration::from_millis(10));
|
||||
pub fn handle_tray_messages(message_channel: &Receiver<Events>) {
|
||||
let message = message_channel.recv_timeout(Duration::from_millis(10));
|
||||
match message {
|
||||
Err(_) => return,
|
||||
Ok(message) => {
|
||||
|
|
Loading…
Reference in a new issue