From ecffc89f29a7d80c362935f9af66deae213fcabc Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 28 May 2024 18:12:22 -0700 Subject: Fix a performance issue in the UI. --- src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 08c1ded..9fe62b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ fn main() -> ExitCode { let grid = Grid::new(); window.set_child(Some(&grid)); - let input = Entry::new(); + let input = Entry::builder().width_request(300).build(); grid.attach(&input, 0, 0, 1, 1); let output = Entry::builder().editable(false).build(); @@ -59,6 +59,7 @@ fn main() -> ExitCode { window.add_controller(key_controller); glib::spawn_future_local(async move { + let mut prev_input = String::from(""); loop { if ping_recv.recv().await.is_err() { break; @@ -66,17 +67,21 @@ fn main() -> ExitCode { let Some(input) = get_mail(mailbox.as_ref()) else { continue; }; + if input == prev_input { + continue; + } + prev_input = input.clone(); let (output_send, output_recv) = async_channel::bounded(1); let thread_handle = gtk4::gio::spawn_blocking(move || { if let Some(result) = parser::parse(&input) { - output_send.send_blocking(result).unwrap(); + output_send.send_blocking(format!("{result}")).unwrap(); } }); let _ = thread_handle.await; let Ok(result) = output_recv.try_recv() else { continue; }; - output.set_text(&format!("{result}")); + output.set_text(&result); } }); -- cgit v1.3.1