From 1b8ea9d447a0357b0ddfdd4b788503e5e7d5a8fb Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Fri, 30 Dec 2022 13:57:06 +1300 Subject: [PATCH] Prevent UI lockup by doing try_lock() in a few places, and rendering -1 if we couldn't get a lock --- src/ui/feed.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 22a593a7..fa806761 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -14,11 +14,15 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram //let screen_rect = ctx.input().screen_rect; // Rect - let desired_count = { - Globals::trim_desired_events_sync(); - GLOBALS.desired_events.blocking_read().len() + Globals::trim_desired_events_sync(); + let desired_count: isize = match GLOBALS.desired_events.try_read() { + Ok(v) => v.len() as isize, + Err(_) => -1, + }; + let incoming_count: isize = match GLOBALS.incoming_events.try_read() { + Ok(v) => v.len() as isize, + Err(_) => -1, }; - let incoming_count = GLOBALS.incoming_events.blocking_read().len(); ui.with_layout(Layout::right_to_left(Align::TOP), |ui| { if ui @@ -48,7 +52,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram }); } - if ui.button("▶ close all" ).clicked() { + if ui.button("▶ close all").clicked() { app.hides = feed.clone(); } if ui.button("▼ open all").clicked() {