diff --git a/src/gui.rs b/src/gui.rs index dc31e67..a3db7cd 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -25,8 +25,6 @@ use crate::toggle::toggle; use crate::FileOptions; use crate::{APP_INFO, PREFS_KEY}; -const MAX_FPS: f64 = 60.0; - const DEFAULT_FONT_ID: FontId = FontId::new(14.0, FontFamily::Monospace); pub const RIGHT_PANEL_WIDTH: f32 = 350.0; const BAUD_RATES: &[u32] = &[ @@ -494,8 +492,6 @@ impl MyApp { self.command = self.history[self.index].clone(); } } - - ctx.request_repaint() }); ui.add_space(left_border); }); @@ -979,8 +975,6 @@ impl eframe::App for MyApp { eprintln!("Image saved to {path:?}."); } } - - std::thread::sleep(Duration::from_millis((1000.0 / MAX_FPS) as u64)); } fn save(&mut self, _storage: &mut dyn Storage) { diff --git a/src/main.rs b/src/main.rs index a15bbae..376117b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ fn split(payload: &str) -> Vec { } fn main_thread( + sync_tx: Sender, data_lock: Arc>, print_lock: Arc>>, raw_data_rx: Receiver, @@ -65,6 +66,7 @@ fn main_thread( if let Ok(packet) = raw_data_rx.recv_timeout(Duration::from_millis(1)) { if !packet.payload.is_empty() { + sync_tx.send(true).expect("unable to send sync tx"); data.raw_traffic.push(packet.clone()); let split_data = split(&packet.payload); if data.dataset.is_empty() || failed_format_counter > 10 { @@ -134,6 +136,7 @@ fn main() { let (send_tx, send_rx): (Sender, Receiver) = mpsc::channel(); let (clear_tx, clear_rx): (Sender, Receiver) = mpsc::channel(); let (raw_data_tx, raw_data_rx): (Sender, Receiver) = mpsc::channel(); + let (sync_tx, sync_rx): (Sender, Receiver) = mpsc::channel(); let serial_device_lock = device_lock.clone(); let serial_devices_lock = devices_lock.clone(); @@ -158,6 +161,7 @@ fn main() { println!("starting main thread.."); let _main_thread_handler = thread::spawn(|| { main_thread( + sync_tx, main_data_lock, main_print_lock, raw_data_rx, @@ -191,6 +195,15 @@ fn main() { egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular); _cc.egui_ctx.set_fonts(fonts); _cc.egui_ctx.set_visuals(Visuals::dark()); + + let repaint_signal = _cc.egui_ctx.clone(); + thread::spawn(move || loop { + if let Ok(_) = sync_rx.recv() { + println!("requested repaint!"); + repaint_signal.request_repaint(); + } + }); + Ok(Box::new(MyApp::new( gui_print_lock, gui_data_lock,