diff --git a/src/globals.rs b/src/globals.rs index d6573e3a..ff566029 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -74,6 +74,9 @@ pub struct Globals { /// Failed Avatar Fetches pub failed_avatars: RwLock>, + + /// UI status message + pub status_message: RwLock, } lazy_static! { @@ -104,6 +107,7 @@ lazy_static! { feed: Feed::new(), fetcher: Fetcher::new(), failed_avatars: RwLock::new(HashSet::new()), + status_message: RwLock::new("Welcome to Gossip. Status messages will appear here. Click them to dismiss them.".to_owned()), } }; } diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 9ad695ea..4acadc20 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -586,12 +586,12 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: ®ex::Regex, event: } Tag::Hashtag(s) => { if ui.link(format!("#{}", s)).clicked() { - app.status = "Gossip doesn't have a hashtag feed yet.".to_owned(); + *GLOBALS.status_message.blocking_write() = "Gossip doesn't have a hashtag feed yet.".to_owned(); } } _ => { if ui.link(format!("#[{}]", num)).clicked() { - app.status = + *GLOBALS.status_message.blocking_write() = "Gossip can't handle this kind of tag link yet.".to_owned(); } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b8490bfd..041c8f1d 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -72,7 +72,6 @@ enum Page { struct GossipUi { next_frame: Instant, page: Page, - status: String, about: About, icon: TextureHandle, placeholder_avatar: TextureHandle, @@ -143,9 +142,6 @@ impl GossipUi { GossipUi { next_frame: Instant::now(), page: Page::FeedGeneral, - status: - "Welcome to Gossip. Status messages will appear here. Click them to dismiss them." - .to_owned(), about: crate::about::about(), icon: icon_texture_handle, placeholder_avatar: placeholder_avatar_texture_handle, @@ -257,10 +253,10 @@ impl eframe::App for GossipUi { egui::TopBottomPanel::bottom("status").show(ctx, |ui| { ui.horizontal(|ui| { if ui - .add(Label::new(&self.status).sense(Sense::click())) + .add(Label::new(GLOBALS.status_message.blocking_read().clone()).sense(Sense::click())) .clicked() { - self.status = "".to_string(); + *GLOBALS.status_message.blocking_write() = "".to_string(); } }); }); diff --git a/src/ui/relays.rs b/src/ui/relays.rs index 3b11c785..5e544361 100644 --- a/src/ui/relays.rs +++ b/src/ui/relays.rs @@ -31,12 +31,12 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr json_payload: serde_json::to_string(&app.new_relay_url).unwrap(), }); app.new_relay_url = "".to_owned(); - app.status = format!( + *GLOBALS.status_message.blocking_write() = format!( "I asked the overlord to add relay {}. Check for it below.", &app.new_relay_url ); } else { - app.status = "That's not a valid relay URL.".to_owned(); + *GLOBALS.status_message.blocking_write() = "That's not a valid relay URL.".to_owned(); } } }); diff --git a/src/ui/you.rs b/src/ui/you.rs index ff9d07a4..731b51cc 100644 --- a/src/ui/you.rs +++ b/src/ui/you.rs @@ -83,10 +83,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr Ok(mut bech32) => { println!("Exported private key (bech32): {}", bech32); bech32.zeroize(); - app.status = + *GLOBALS.status_message.blocking_write() = "Exported key has been printed to the console standard output.".to_owned(); } - Err(e) => app.status = format!("{}", e), + Err(e) => + *GLOBALS.status_message.blocking_write() = format!("{}", e), } app.password.zeroize(); app.password = "".to_owned(); @@ -100,10 +101,10 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr Ok(mut hex) => { println!("Exported private key (hex): {}", hex); hex.zeroize(); - app.status = + *GLOBALS.status_message.blocking_write() = "Exported key has been printed to the console standard output.".to_owned(); } - Err(e) => app.status = format!("{}", e), + Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e), } app.password.zeroize(); app.password = "".to_owned(); @@ -126,8 +127,8 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr .blocking_write() .delete_identity(&app.password) { - Ok(_) => app.status = "Identity deleted.".to_string(), - Err(e) => app.status = format!("{}", e), + Ok(_) => *GLOBALS.status_message.blocking_write() = "Identity deleted.".to_string(), + Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e), } app.password.zeroize(); app.password = "".to_owned();