Move storage of UI status message to globals, so non-UI components can set status too

This commit is contained in:
Mike Dilger 2023-01-05 19:57:07 +13:00
parent 733ae13eb0
commit aa757bd9bd
5 changed files with 17 additions and 16 deletions

View File

@ -74,6 +74,9 @@ pub struct Globals {
/// Failed Avatar Fetches
pub failed_avatars: RwLock<HashSet<PublicKeyHex>>,
/// UI status message
pub status_message: RwLock<String>,
}
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()),
}
};
}

View File

@ -586,12 +586,12 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: &regex::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();
}
}

View File

@ -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();
}
});
});

View File

@ -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();
}
}
});

View File

@ -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();