mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 11:43:43 +00:00
Move storage of UI status message to globals, so non-UI components can set status too
This commit is contained in:
parent
733ae13eb0
commit
aa757bd9bd
@ -74,6 +74,9 @@ pub struct Globals {
|
|||||||
|
|
||||||
/// Failed Avatar Fetches
|
/// Failed Avatar Fetches
|
||||||
pub failed_avatars: RwLock<HashSet<PublicKeyHex>>,
|
pub failed_avatars: RwLock<HashSet<PublicKeyHex>>,
|
||||||
|
|
||||||
|
/// UI status message
|
||||||
|
pub status_message: RwLock<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@ -104,6 +107,7 @@ lazy_static! {
|
|||||||
feed: Feed::new(),
|
feed: Feed::new(),
|
||||||
fetcher: Fetcher::new(),
|
fetcher: Fetcher::new(),
|
||||||
failed_avatars: RwLock::new(HashSet::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()),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -586,12 +586,12 @@ fn render_content(app: &mut GossipUi, ui: &mut Ui, tag_re: ®ex::Regex, event:
|
|||||||
}
|
}
|
||||||
Tag::Hashtag(s) => {
|
Tag::Hashtag(s) => {
|
||||||
if ui.link(format!("#{}", s)).clicked() {
|
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() {
|
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();
|
"Gossip can't handle this kind of tag link yet.".to_owned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,6 @@ enum Page {
|
|||||||
struct GossipUi {
|
struct GossipUi {
|
||||||
next_frame: Instant,
|
next_frame: Instant,
|
||||||
page: Page,
|
page: Page,
|
||||||
status: String,
|
|
||||||
about: About,
|
about: About,
|
||||||
icon: TextureHandle,
|
icon: TextureHandle,
|
||||||
placeholder_avatar: TextureHandle,
|
placeholder_avatar: TextureHandle,
|
||||||
@ -143,9 +142,6 @@ impl GossipUi {
|
|||||||
GossipUi {
|
GossipUi {
|
||||||
next_frame: Instant::now(),
|
next_frame: Instant::now(),
|
||||||
page: Page::FeedGeneral,
|
page: Page::FeedGeneral,
|
||||||
status:
|
|
||||||
"Welcome to Gossip. Status messages will appear here. Click them to dismiss them."
|
|
||||||
.to_owned(),
|
|
||||||
about: crate::about::about(),
|
about: crate::about::about(),
|
||||||
icon: icon_texture_handle,
|
icon: icon_texture_handle,
|
||||||
placeholder_avatar: placeholder_avatar_texture_handle,
|
placeholder_avatar: placeholder_avatar_texture_handle,
|
||||||
@ -257,10 +253,10 @@ impl eframe::App for GossipUi {
|
|||||||
egui::TopBottomPanel::bottom("status").show(ctx, |ui| {
|
egui::TopBottomPanel::bottom("status").show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui
|
if ui
|
||||||
.add(Label::new(&self.status).sense(Sense::click()))
|
.add(Label::new(GLOBALS.status_message.blocking_read().clone()).sense(Sense::click()))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.status = "".to_string();
|
*GLOBALS.status_message.blocking_write() = "".to_string();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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(),
|
json_payload: serde_json::to_string(&app.new_relay_url).unwrap(),
|
||||||
});
|
});
|
||||||
app.new_relay_url = "".to_owned();
|
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.",
|
"I asked the overlord to add relay {}. Check for it below.",
|
||||||
&app.new_relay_url
|
&app.new_relay_url
|
||||||
);
|
);
|
||||||
} else {
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -83,10 +83,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
|||||||
Ok(mut bech32) => {
|
Ok(mut bech32) => {
|
||||||
println!("Exported private key (bech32): {}", bech32);
|
println!("Exported private key (bech32): {}", bech32);
|
||||||
bech32.zeroize();
|
bech32.zeroize();
|
||||||
app.status =
|
*GLOBALS.status_message.blocking_write() =
|
||||||
"Exported key has been printed to the console standard output.".to_owned();
|
"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.zeroize();
|
||||||
app.password = "".to_owned();
|
app.password = "".to_owned();
|
||||||
@ -100,10 +101,10 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
|||||||
Ok(mut hex) => {
|
Ok(mut hex) => {
|
||||||
println!("Exported private key (hex): {}", hex);
|
println!("Exported private key (hex): {}", hex);
|
||||||
hex.zeroize();
|
hex.zeroize();
|
||||||
app.status =
|
*GLOBALS.status_message.blocking_write() =
|
||||||
"Exported key has been printed to the console standard output.".to_owned();
|
"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.zeroize();
|
||||||
app.password = "".to_owned();
|
app.password = "".to_owned();
|
||||||
@ -126,8 +127,8 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
|||||||
.blocking_write()
|
.blocking_write()
|
||||||
.delete_identity(&app.password)
|
.delete_identity(&app.password)
|
||||||
{
|
{
|
||||||
Ok(_) => app.status = "Identity deleted.".to_string(),
|
Ok(_) => *GLOBALS.status_message.blocking_write() = "Identity deleted.".to_string(),
|
||||||
Err(e) => app.status = format!("{}", e),
|
Err(e) => *GLOBALS.status_message.blocking_write() = format!("{}", e),
|
||||||
}
|
}
|
||||||
app.password.zeroize();
|
app.password.zeroize();
|
||||||
app.password = "".to_owned();
|
app.password = "".to_owned();
|
||||||
|
Loading…
Reference in New Issue
Block a user