working version of tray_icon events
This commit is contained in:
parent
1d97546bbe
commit
fdb60f6e00
2 changed files with 31 additions and 21 deletions
43
src/main.rs
43
src/main.rs
|
@ -48,29 +48,36 @@ fn main() {
|
|||
let mut state = StreamState::new();
|
||||
//until control_c is caught, check the queue of incoming
|
||||
//requests from the socket handler.
|
||||
while !control_c_called_flag_rx.get() {
|
||||
match from_socket_rx.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(message) => {
|
||||
println!("main recieved: {}", message);
|
||||
let update = StateUpdate::json_to_state_update(
|
||||
serde_json::from_str(&message).unwrap());
|
||||
if update == StateUpdate::UpdateClient {
|
||||
update_all(&state, &socket);
|
||||
} else {
|
||||
handle_instructions(vec![update], &mut state, &socket, &hotkeys);
|
||||
}
|
||||
},
|
||||
Err(_) => {},
|
||||
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() {
|
||||
match from_socket_rx.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(message) => {
|
||||
println!("main recieved: {}", message);
|
||||
let update = StateUpdate::json_to_state_update(
|
||||
serde_json::from_str(&message).unwrap());
|
||||
if update == StateUpdate::UpdateClient {
|
||||
update_all(&state, &socket);
|
||||
} else {
|
||||
handle_instructions(vec![update], &mut state, &socket, &hotkeys);
|
||||
}
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
|
||||
let tick_update = state.tick();
|
||||
handle_instructions(tick_update, &mut state, &socket, &hotkeys);
|
||||
println!("{:?}", messages.recv());
|
||||
}
|
||||
|
||||
let tick_update = state.tick();
|
||||
handle_instructions(tick_update, &mut state, &socket, &hotkeys);
|
||||
|
||||
socket.close();
|
||||
});
|
||||
while !stop_flag.get() {
|
||||
tray_icon.process_tray_messages();
|
||||
//tray_icon.check_tray_messages();
|
||||
}
|
||||
|
||||
println!("closing main thread");
|
||||
socket.close();
|
||||
hotkey_handle.join().unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ pub enum Events {
|
|||
|
||||
pub struct TrayIcon {
|
||||
tray_icon: trayicon::TrayIcon<Events>,
|
||||
message_channel: crossbeam_channel::Receiver<Events>,
|
||||
pub message_channel: crossbeam_channel::Receiver<Events>,
|
||||
}
|
||||
|
||||
impl TrayIcon {
|
||||
|
@ -35,7 +35,7 @@ impl TrayIcon {
|
|||
let first_icon = Icon::from_buffer(icon1, None, None).unwrap();
|
||||
|
||||
// Needlessly complicated tray icon with all the whistles and bells
|
||||
let mut tray_icon = TrayIconBuilder::new()
|
||||
let tray_icon = TrayIconBuilder::new()
|
||||
.sender_crossbeam(s)
|
||||
.icon_from_buffer(icon1)
|
||||
.tooltip("Cool Tray 👀 Icon")
|
||||
|
@ -76,7 +76,7 @@ impl TrayIcon {
|
|||
pub fn process_tray_messages(&self) {
|
||||
unsafe {
|
||||
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 {
|
||||
winuser::TranslateMessage(msg.as_ptr());
|
||||
|
@ -85,6 +85,9 @@ impl TrayIcon {
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_tray_messages(&self){
|
||||
|
||||
let message = self.message_channel.recv_timeout(Duration::from_millis(10));
|
||||
match message {
|
||||
|
|
Loading…
Reference in a new issue