rename BusMessage to ToOverlordMessage

This commit is contained in:
Mike Dilger 2023-01-06 15:12:36 +13:00
parent 4b70a761f4
commit b997ca8668
12 changed files with 62 additions and 63 deletions

View File

@ -5,7 +5,7 @@ use zeroize::Zeroize;
/// This is a message sent to the Overlord /// This is a message sent to the Overlord
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub struct BusMessage { pub struct ToOverlordMessage {
/// What kind of message is this /// What kind of message is this
pub kind: String, pub kind: String,
@ -13,9 +13,9 @@ pub struct BusMessage {
pub json_payload: String, pub json_payload: String,
} }
/// We may send passwords through BusMessage objects, so we zeroize /// We may send passwords through ToOverlordMessage objects, so we zeroize
/// bus message payloads upon drop. /// bus message payloads upon drop.
impl Drop for BusMessage { impl Drop for ToOverlordMessage {
fn drop(&mut self) { fn drop(&mut self) {
self.json_payload.zeroize(); self.json_payload.zeroize();
} }

View File

@ -1,4 +1,4 @@
use crate::comms::{BusMessage, ToMinionMessage}; use crate::comms::{ToMinionMessage, ToOverlordMessage};
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
@ -19,7 +19,7 @@ pub enum Error {
JoinError(#[from] tokio::task::JoinError), JoinError(#[from] tokio::task::JoinError),
#[error("Error sending mpsc: {0}")] #[error("Error sending mpsc: {0}")]
MpscSend(#[from] tokio::sync::mpsc::error::SendError<BusMessage>), MpscSend(#[from] tokio::sync::mpsc::error::SendError<ToOverlordMessage>),
#[error("NIP-05 public key not found")] #[error("NIP-05 public key not found")]
Nip05NotFound, Nip05NotFound,

View File

@ -1,4 +1,4 @@
use crate::comms::{BusMessage, ToMinionMessage}; use crate::comms::{ToMinionMessage, ToOverlordMessage};
use crate::db::{DbEvent, DbRelay}; use crate::db::{DbEvent, DbRelay};
use crate::error::Error; use crate::error::Error;
use crate::feed::Feed; use crate::feed::Feed;
@ -25,11 +25,11 @@ pub struct Globals {
/// This is a mpsc channel. The Overlord listens on it. /// This is a mpsc channel. The Overlord listens on it.
/// To create a sender, just clone() it. /// To create a sender, just clone() it.
pub to_overlord: mpsc::UnboundedSender<BusMessage>, pub to_overlord: mpsc::UnboundedSender<ToOverlordMessage>,
/// This is ephemeral. It is filled during lazy_static initialization, /// This is ephemeral. It is filled during lazy_static initialization,
/// and stolen away when the Overlord is created. /// and stolen away when the Overlord is created.
pub tmp_overlord_receiver: Mutex<Option<mpsc::UnboundedReceiver<BusMessage>>>, pub tmp_overlord_receiver: Mutex<Option<mpsc::UnboundedReceiver<ToOverlordMessage>>>,
/// All nostr events, keyed by the event Id /// All nostr events, keyed by the event Id
pub events: RwLock<HashMap<Id, Event>>, pub events: RwLock<HashMap<Id, Event>>,

View File

@ -19,7 +19,7 @@ mod settings;
mod signer; mod signer;
mod ui; mod ui;
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::error::Error; use crate::error::Error;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use std::ops::DerefMut; use std::ops::DerefMut;
@ -92,7 +92,7 @@ async fn tokio_main() {
// Any task can call this to shutdown // Any task can call this to shutdown
pub fn initiate_shutdown() -> Result<(), Error> { pub fn initiate_shutdown() -> Result<(), Error> {
let to_overlord = GLOBALS.to_overlord.clone(); let to_overlord = GLOBALS.to_overlord.clone();
let _ = to_overlord.send(BusMessage { let _ = to_overlord.send(ToOverlordMessage {
kind: "shutdown".to_string(), kind: "shutdown".to_string(),
json_payload: serde_json::to_string("").unwrap(), json_payload: serde_json::to_string("").unwrap(),
}); // ignore errors }); // ignore errors

View File

@ -1,7 +1,7 @@
mod handle_websocket; mod handle_websocket;
mod subscription; mod subscription;
use crate::comms::{BusMessage, ToMinionMessage, ToMinionPayload}; use crate::comms::{ToMinionMessage, ToMinionPayload, ToOverlordMessage};
use crate::db::DbRelay; use crate::db::DbRelay;
use crate::error::Error; use crate::error::Error;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
@ -23,7 +23,7 @@ use tungstenite::protocol::{Message as WsMessage, WebSocketConfig};
pub struct Minion { pub struct Minion {
url: Url, url: Url,
to_overlord: UnboundedSender<BusMessage>, to_overlord: UnboundedSender<ToOverlordMessage>,
from_overlord: Receiver<ToMinionMessage>, from_overlord: Receiver<ToMinionMessage>,
dbrelay: DbRelay, dbrelay: DbRelay,
nip11: Option<RelayInformationDocument>, nip11: Option<RelayInformationDocument>,
@ -221,7 +221,7 @@ impl Minion {
}; };
#[allow(clippy::collapsible_if)] #[allow(clippy::collapsible_if)]
if to_minion_message.target == self.url.inner() || to_minion_message.target == "all" { if to_minion_message.target == self.url.inner() || to_minion_message.target == "all" {
keepgoing = self.handle_bus_message(to_minion_message).await?; keepgoing = self.handle_message(to_minion_message).await?;
} }
}, },
} }
@ -229,7 +229,7 @@ impl Minion {
Ok(keepgoing) Ok(keepgoing)
} }
pub async fn handle_bus_message(&mut self, message: ToMinionMessage) -> Result<bool, Error> { pub async fn handle_message(&mut self, message: ToMinionMessage) -> Result<bool, Error> {
match message.payload { match message.payload {
ToMinionPayload::Shutdown => { ToMinionPayload::Shutdown => {
tracing::info!("{}: Websocket listener shutting down", &self.url); tracing::info!("{}: Websocket listener shutting down", &self.url);
@ -262,7 +262,7 @@ impl Minion {
} }
async fn tell_overlord_we_are_ready(&self) -> Result<(), Error> { async fn tell_overlord_we_are_ready(&self) -> Result<(), Error> {
self.to_overlord.send(BusMessage { self.to_overlord.send(ToOverlordMessage {
kind: "minion_is_ready".to_string(), kind: "minion_is_ready".to_string(),
json_payload: "".to_owned(), json_payload: "".to_owned(),
})?; })?;

View File

@ -1,7 +1,7 @@
mod minion; mod minion;
mod relay_picker; mod relay_picker;
use crate::comms::{BusMessage, ToMinionMessage, ToMinionPayload}; use crate::comms::{ToMinionMessage, ToMinionPayload, ToOverlordMessage};
use crate::db::{DbEvent, DbPersonRelay, DbRelay}; use crate::db::{DbEvent, DbPersonRelay, DbRelay};
use crate::error::Error; use crate::error::Error;
use crate::globals::{Globals, GLOBALS}; use crate::globals::{Globals, GLOBALS};
@ -20,7 +20,7 @@ use zeroize::Zeroize;
pub struct Overlord { pub struct Overlord {
to_minions: Sender<ToMinionMessage>, to_minions: Sender<ToMinionMessage>,
inbox: UnboundedReceiver<BusMessage>, inbox: UnboundedReceiver<ToOverlordMessage>,
// All the minion tasks running. // All the minion tasks running.
minions: task::JoinSet<()>, minions: task::JoinSet<()>,
@ -33,7 +33,7 @@ pub struct Overlord {
} }
impl Overlord { impl Overlord {
pub fn new(inbox: UnboundedReceiver<BusMessage>) -> Overlord { pub fn new(inbox: UnboundedReceiver<ToOverlordMessage>) -> Overlord {
let to_minions = GLOBALS.to_minions.clone(); let to_minions = GLOBALS.to_minions.clone();
Overlord { Overlord {
to_minions, to_minions,
@ -276,27 +276,27 @@ impl Overlord {
if self.minions.is_empty() { if self.minions.is_empty() {
// Just listen on inbox // Just listen on inbox
let bus_message = self.inbox.recv().await; let message = self.inbox.recv().await;
let bus_message = match bus_message { let message = match message {
Some(bm) => bm, Some(bm) => bm,
None => { None => {
// All senders dropped, or one of them closed. // All senders dropped, or one of them closed.
return Ok(false); return Ok(false);
} }
}; };
keepgoing = self.handle_bus_message(bus_message).await?; keepgoing = self.handle_message(message).await?;
} else { } else {
// Listen on inbox, and dying minions // Listen on inbox, and dying minions
select! { select! {
bus_message = self.inbox.recv() => { message = self.inbox.recv() => {
let bus_message = match bus_message { let message = match message {
Some(bm) => bm, Some(bm) => bm,
None => { None => {
// All senders dropped, or one of them closed. // All senders dropped, or one of them closed.
return Ok(false); return Ok(false);
} }
}; };
keepgoing = self.handle_bus_message(bus_message).await?; keepgoing = self.handle_message(message).await?;
}, },
task_nextjoined = self.minions.join_next_with_id() => { task_nextjoined = self.minions.join_next_with_id() => {
self.handle_task_nextjoined(task_nextjoined).await; self.handle_task_nextjoined(task_nextjoined).await;
@ -355,9 +355,9 @@ impl Overlord {
} }
} }
async fn handle_bus_message(&mut self, bus_message: BusMessage) -> Result<bool, Error> { async fn handle_message(&mut self, message: ToOverlordMessage) -> Result<bool, Error> {
#[allow(clippy::single_match)] // because temporarily so #[allow(clippy::single_match)] // because temporarily so
match &*bus_message.kind { match &*message.kind {
"shutdown" => { "shutdown" => {
tracing::info!("Overlord shutting down"); tracing::info!("Overlord shutting down");
return Ok(false); return Ok(false);
@ -371,7 +371,7 @@ impl Overlord {
self.get_missing_events().await?; self.get_missing_events().await?;
} }
"follow_nip35" => { "follow_nip35" => {
let dns_id: String = serde_json::from_str(&bus_message.json_payload)?; let dns_id: String = serde_json::from_str(&message.json_payload)?;
let _ = tokio::spawn(async move { let _ = tokio::spawn(async move {
if let Err(e) = Overlord::get_and_follow_nip35(dns_id).await { if let Err(e) = Overlord::get_and_follow_nip35(dns_id).await {
tracing::error!("{}", e); tracing::error!("{}", e);
@ -379,15 +379,15 @@ impl Overlord {
}); });
} }
"follow_bech32" => { "follow_bech32" => {
let data: (String, String) = serde_json::from_str(&bus_message.json_payload)?; let data: (String, String) = serde_json::from_str(&message.json_payload)?;
Overlord::follow_bech32(data.0, data.1).await?; Overlord::follow_bech32(data.0, data.1).await?;
} }
"follow_hexkey" => { "follow_hexkey" => {
let data: (String, String) = serde_json::from_str(&bus_message.json_payload)?; let data: (String, String) = serde_json::from_str(&message.json_payload)?;
Overlord::follow_hexkey(data.0, data.1).await?; Overlord::follow_hexkey(data.0, data.1).await?;
} }
"unlock_key" => { "unlock_key" => {
let mut password: String = serde_json::from_str(&bus_message.json_payload)?; let mut password: String = serde_json::from_str(&message.json_payload)?;
GLOBALS GLOBALS
.signer .signer
.write() .write()
@ -404,7 +404,7 @@ impl Overlord {
} }
} }
"generate_private_key" => { "generate_private_key" => {
let mut password: String = serde_json::from_str(&bus_message.json_payload)?; let mut password: String = serde_json::from_str(&message.json_payload)?;
GLOBALS GLOBALS
.signer .signer
.write() .write()
@ -415,7 +415,7 @@ impl Overlord {
} }
"import_priv" => { "import_priv" => {
let (mut import_priv, mut password): (String, String) = let (mut import_priv, mut password): (String, String) =
serde_json::from_str(&bus_message.json_payload)?; serde_json::from_str(&message.json_payload)?;
let maybe_pk1 = PrivateKey::try_from_bech32_string(&import_priv); let maybe_pk1 = PrivateKey::try_from_bech32_string(&import_priv);
let maybe_pk2 = PrivateKey::try_from_hex_string(&import_priv); let maybe_pk2 = PrivateKey::try_from_hex_string(&import_priv);
import_priv.zeroize(); import_priv.zeroize();
@ -435,7 +435,7 @@ impl Overlord {
} }
} }
"import_pub" => { "import_pub" => {
let pubstr: String = serde_json::from_str(&bus_message.json_payload)?; let pubstr: String = serde_json::from_str(&message.json_payload)?;
let maybe_pk1 = PublicKey::try_from_bech32_string(&pubstr); let maybe_pk1 = PublicKey::try_from_bech32_string(&pubstr);
let maybe_pk2 = PublicKey::try_from_hex_string(&pubstr); let maybe_pk2 = PublicKey::try_from_hex_string(&pubstr);
if maybe_pk1.is_err() && maybe_pk2.is_err() { if maybe_pk1.is_err() && maybe_pk2.is_err() {
@ -469,17 +469,16 @@ impl Overlord {
} }
} }
"post_textnote" => { "post_textnote" => {
let content: String = serde_json::from_str(&bus_message.json_payload)?; let content: String = serde_json::from_str(&message.json_payload)?;
self.post_textnote(content).await?; self.post_textnote(content).await?;
} }
"post_reply" => { "post_reply" => {
let (content, reply_to): (String, Id) = let (content, reply_to): (String, Id) =
serde_json::from_str(&bus_message.json_payload)?; serde_json::from_str(&message.json_payload)?;
self.post_reply(content, reply_to).await?; self.post_reply(content, reply_to).await?;
} }
"like" => { "like" => {
let (id, pubkey): (Id, PublicKey) = let (id, pubkey): (Id, PublicKey) = serde_json::from_str(&message.json_payload)?;
serde_json::from_str(&bus_message.json_payload)?;
self.post_like(id, pubkey).await?; self.post_like(id, pubkey).await?;
} }
"process_incoming_events" => { "process_incoming_events" => {
@ -494,12 +493,12 @@ impl Overlord {
}); });
} }
"add_relay" => { "add_relay" => {
let relay_str: String = serde_json::from_str(&bus_message.json_payload)?; let relay_str: String = serde_json::from_str(&message.json_payload)?;
let dbrelay = DbRelay::new(relay_str)?; let dbrelay = DbRelay::new(relay_str)?;
DbRelay::insert(dbrelay).await?; DbRelay::insert(dbrelay).await?;
} }
"update_metadata" => { "update_metadata" => {
let pubkey: PublicKeyHex = serde_json::from_str(&bus_message.json_payload)?; let pubkey: PublicKeyHex = serde_json::from_str(&message.json_payload)?;
let person_relays = DbPersonRelay::fetch_for_pubkeys(&[pubkey.clone()]).await?; let person_relays = DbPersonRelay::fetch_for_pubkeys(&[pubkey.clone()]).await?;
for person_relay in person_relays.iter() { for person_relay in person_relays.iter() {

View File

@ -1,5 +1,5 @@
use super::{GossipUi, Page}; use super::{GossipUi, Page};
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::feed::FeedKind; use crate::feed::FeedKind;
use crate::globals::{Globals, GLOBALS}; use crate::globals::{Globals, GLOBALS};
use crate::ui::widgets::{CopyButton, LikeButton, ReplyButton}; use crate::ui::widgets::{CopyButton, LikeButton, ReplyButton};
@ -85,7 +85,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
.clicked() .clicked()
{ {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "get_missing_events".to_string(), kind: "get_missing_events".to_string(),
json_payload: serde_json::to_string("").unwrap(), json_payload: serde_json::to_string("").unwrap(),
}); });
@ -98,7 +98,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
.clicked() .clicked()
{ {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "process_incoming_events".to_string(), kind: "process_incoming_events".to_string(),
json_payload: serde_json::to_string("").unwrap(), json_payload: serde_json::to_string("").unwrap(),
}); });
@ -153,7 +153,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
match app.replying_to { match app.replying_to {
Some(_id) => { Some(_id) => {
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "post_reply".to_string(), kind: "post_reply".to_string(),
json_payload: serde_json::to_string(&( json_payload: serde_json::to_string(&(
&app.draft, &app.draft,
@ -163,7 +163,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
}); });
} }
None => { None => {
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "post_textnote".to_string(), kind: "post_textnote".to_string(),
json_payload: serde_json::to_string(&app.draft).unwrap(), json_payload: serde_json::to_string(&app.draft).unwrap(),
}); });
@ -452,7 +452,7 @@ fn render_post_actual(
GLOBALS.dismissed.blocking_write().push(event.id); GLOBALS.dismissed.blocking_write().push(event.id);
} }
if ui.button("Update Metadata").clicked() { if ui.button("Update Metadata").clicked() {
let _ = GLOBALS.to_overlord.send(BusMessage { let _ = GLOBALS.to_overlord.send(ToOverlordMessage {
kind: "update_metadata".to_string(), kind: "update_metadata".to_string(),
json_payload: serde_json::to_string( json_payload: serde_json::to_string(
&event.pubkey.as_hex_string(), &event.pubkey.as_hex_string(),
@ -498,7 +498,7 @@ fn render_post_actual(
if ui.add(LikeButton {}).clicked() { if ui.add(LikeButton {}).clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "like".to_string(), kind: "like".to_string(),
json_payload: serde_json::to_string(&(&event.id, &event.pubkey)) json_payload: serde_json::to_string(&(&event.id, &event.pubkey))
.unwrap(), .unwrap(),

View File

@ -1,5 +1,5 @@
use super::GossipUi; use super::GossipUi;
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use eframe::egui; use eframe::egui;
use egui::{Context, TextEdit, Ui}; use egui::{Context, TextEdit, Ui};
@ -25,7 +25,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}); });
if ui.button("follow").clicked() { if ui.button("follow").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "follow_nip35".to_string(), kind: "follow_nip35".to_string(),
json_payload: serde_json::to_string(&app.nip35follow).unwrap(), json_payload: serde_json::to_string(&app.nip35follow).unwrap(),
}); });
@ -48,7 +48,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}); });
if ui.button("follow").clicked() { if ui.button("follow").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "follow_bech32".to_string(), kind: "follow_bech32".to_string(),
json_payload: serde_json::to_string(&( json_payload: serde_json::to_string(&(
&app.follow_bech32_pubkey, &app.follow_bech32_pubkey,
@ -76,7 +76,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}); });
if ui.button("follow").clicked() { if ui.button("follow").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "follow_hexkey".to_string(), kind: "follow_hexkey".to_string(),
json_payload: serde_json::to_string(&( json_payload: serde_json::to_string(&(
&app.follow_hex_pubkey, &app.follow_hex_pubkey,

View File

@ -1,5 +1,5 @@
use super::{GossipUi, Page}; use super::{GossipUi, Page};
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::db::DbPerson; use crate::db::DbPerson;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use eframe::egui; use eframe::egui;
@ -57,7 +57,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
} }
if ui.button("UPDATE METADATA").clicked() { if ui.button("UPDATE METADATA").clicked() {
let _ = GLOBALS.to_overlord.send(BusMessage { let _ = GLOBALS.to_overlord.send(ToOverlordMessage {
kind: "update_metadata".to_string(), kind: "update_metadata".to_string(),
json_payload: serde_json::to_string(&pubkeyhex).unwrap(), json_payload: serde_json::to_string(&pubkeyhex).unwrap(),
}); });

View File

@ -1,5 +1,5 @@
use super::GossipUi; use super::GossipUi;
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::db::DbRelay; use crate::db::DbRelay;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use eframe::egui; use eframe::egui;
@ -25,7 +25,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
let test_url = Url::new(&app.new_relay_url); let test_url = Url::new(&app.new_relay_url);
if test_url.is_valid_relay_url() { if test_url.is_valid_relay_url() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "add_relay".to_string(), kind: "add_relay".to_string(),
json_payload: serde_json::to_string(&app.new_relay_url).unwrap(), json_payload: serde_json::to_string(&app.new_relay_url).unwrap(),
}); });
@ -61,7 +61,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.with_layout(Layout::bottom_up(Align::Center), |ui| { ui.with_layout(Layout::bottom_up(Align::Center), |ui| {
if ui.button("SAVE CHANGES").clicked() { if ui.button("SAVE CHANGES").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "save_relays".to_string(), kind: "save_relays".to_string(),
json_payload: serde_json::to_string("").unwrap(), json_payload: serde_json::to_string("").unwrap(),
}); });

View File

@ -1,5 +1,5 @@
use super::GossipUi; use super::GossipUi;
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::GLOBALS; use crate::GLOBALS;
use eframe::egui; use eframe::egui;
use egui::widgets::{Button, Slider}; use egui::widgets::{Button, Slider};
@ -152,7 +152,7 @@ pub(super) fn update(
// Tell the overlord to save them // Tell the overlord to save them
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "save_settings".to_string(), kind: "save_settings".to_string(),
json_payload: serde_json::to_string("").unwrap(), json_payload: serde_json::to_string("").unwrap(),
}); });

View File

@ -1,5 +1,5 @@
use super::GossipUi; use super::GossipUi;
use crate::comms::BusMessage; use crate::comms::ToOverlordMessage;
use crate::globals::GLOBALS; use crate::globals::GLOBALS;
use crate::ui::widgets::CopyButton; use crate::ui::widgets::CopyButton;
use eframe::egui; use eframe::egui;
@ -142,7 +142,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
if ui.button("Unlock Private Key").clicked() { if ui.button("Unlock Private Key").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "unlock_key".to_string(), kind: "unlock_key".to_string(),
json_payload: serde_json::to_string(&app.password).unwrap(), json_payload: serde_json::to_string(&app.password).unwrap(),
}); });
@ -158,7 +158,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}); });
if ui.button("Generate Now").clicked() { if ui.button("Generate Now").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "generate_private_key".to_string(), kind: "generate_private_key".to_string(),
json_payload: serde_json::to_string(&app.password).unwrap(), json_payload: serde_json::to_string(&app.password).unwrap(),
}); });
@ -186,7 +186,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
}); });
if ui.button("import").clicked() { if ui.button("import").clicked() {
let tx = GLOBALS.to_overlord.clone(); let tx = GLOBALS.to_overlord.clone();
let _ = tx.send(BusMessage { let _ = tx.send(ToOverlordMessage {
kind: "import_priv".to_string(), kind: "import_priv".to_string(),
json_payload: serde_json::to_string(&(&app.import_priv, &app.password)).unwrap(), json_payload: serde_json::to_string(&(&app.import_priv, &app.password)).unwrap(),
}); });
@ -224,7 +224,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
} }
if ui.button("Delete this public key").clicked() { if ui.button("Delete this public key").clicked() {
let _ = GLOBALS.to_overlord.send(BusMessage { let _ = GLOBALS.to_overlord.send(ToOverlordMessage {
kind: "delete_pub".to_string(), kind: "delete_pub".to_string(),
json_payload: serde_json::to_string(&app.import_pub).unwrap(), json_payload: serde_json::to_string(&app.import_pub).unwrap(),
}); });
@ -234,7 +234,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.label("Enter your public key"); ui.label("Enter your public key");
ui.add(TextEdit::singleline(&mut app.import_pub).hint_text("npub1 or hex")); ui.add(TextEdit::singleline(&mut app.import_pub).hint_text("npub1 or hex"));
if ui.button("Import a Public Key").clicked() { if ui.button("Import a Public Key").clicked() {
let _ = GLOBALS.to_overlord.send(BusMessage { let _ = GLOBALS.to_overlord.send(ToOverlordMessage {
kind: "import_pub".to_string(), kind: "import_pub".to_string(),
json_payload: serde_json::to_string(&app.import_pub).unwrap(), json_payload: serde_json::to_string(&app.import_pub).unwrap(),
}); });