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();
|
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.
|
||||||
while !control_c_called_flag_rx.get() {
|
let stop_flag = control_c_called_flag_rx.clone();
|
||||||
match from_socket_rx.recv_timeout(Duration::from_millis(100)) {
|
let messages = tray_icon.message_channel.clone();
|
||||||
Ok(message) => {
|
std::thread::spawn(move || {
|
||||||
println!("main recieved: {}", message);
|
while !control_c_called_flag_rx.get() {
|
||||||
let update = StateUpdate::json_to_state_update(
|
match from_socket_rx.recv_timeout(Duration::from_millis(100)) {
|
||||||
serde_json::from_str(&message).unwrap());
|
Ok(message) => {
|
||||||
if update == StateUpdate::UpdateClient {
|
println!("main recieved: {}", message);
|
||||||
update_all(&state, &socket);
|
let update = StateUpdate::json_to_state_update(
|
||||||
} else {
|
serde_json::from_str(&message).unwrap());
|
||||||
handle_instructions(vec![update], &mut state, &socket, &hotkeys);
|
if update == StateUpdate::UpdateClient {
|
||||||
}
|
update_all(&state, &socket);
|
||||||
},
|
} else {
|
||||||
Err(_) => {},
|
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());
|
||||||
}
|
}
|
||||||
|
socket.close();
|
||||||
let tick_update = state.tick();
|
});
|
||||||
handle_instructions(tick_update, &mut state, &socket, &hotkeys);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue