mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 00:11:01 +00:00
Wizard work
This commit is contained in:
parent
1773fea6fa
commit
33327d0f2f
@ -21,12 +21,16 @@ impl StatusQueue {
|
||||
|
||||
pub fn read_all(&self) -> [String; 3] {
|
||||
[
|
||||
self.messages[self.head].to_owned(),
|
||||
self.messages[(self.head + 1) % 3].to_owned(),
|
||||
self.messages[(self.head + 2) % 3].to_owned(),
|
||||
self.messages[self.head].clone(),
|
||||
self.messages[(self.head + 1) % 3].clone(),
|
||||
self.messages[(self.head + 2) % 3].clone(),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn read_last(&self) -> String {
|
||||
self.messages[self.head].clone()
|
||||
}
|
||||
|
||||
pub fn write(&mut self, message: String) {
|
||||
self.head = (self.head + 2) % 3; // like -1, but modular safe
|
||||
self.messages[self.head] = message;
|
||||
|
@ -15,53 +15,16 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
return;
|
||||
}
|
||||
|
||||
// Here we should merge in the contact list event, if existing
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Follow Someone:");
|
||||
ui.add(text_edit_line!(app, app.follow_someone).hint_text(
|
||||
"Enter a key (bech32 npub1 or hex), or an nprofile, or a DNS id (user@domain)",
|
||||
));
|
||||
if ui.button("follow").clicked() {
|
||||
if let Ok(pubkey) = PublicKey::try_from_bech32_string(app.follow_someone.trim(), true) {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::FollowPubkey(pubkey));
|
||||
} else if let Ok(pubkey) =
|
||||
PublicKey::try_from_hex_string(app.follow_someone.trim(), true)
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::FollowPubkey(pubkey));
|
||||
} else if let Ok(profile) =
|
||||
Profile::try_from_bech32_string(app.follow_someone.trim(), true)
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::FollowNprofile(profile));
|
||||
} else if crate::nip05::parse_nip05(app.follow_someone.trim()).is_ok() {
|
||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::FollowNip05(
|
||||
app.follow_someone.trim().to_owned(),
|
||||
));
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid pubkey.".to_string());
|
||||
}
|
||||
app.follow_someone = "".to_owned();
|
||||
}
|
||||
});
|
||||
// Merge in their contacts data
|
||||
if app.wizard_state.contacts_sought {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::UpdateFollowing(false));
|
||||
app.wizard_state.contacts_sought = false;
|
||||
}
|
||||
|
||||
ui.add_space(10.0);
|
||||
ui.label("We accept:");
|
||||
ui.label(" • Public key (npub1..)");
|
||||
ui.label(" • Public key (hex)");
|
||||
ui.label(" • Profile (nprofile1..)");
|
||||
ui.label(" • DNS ID (user@domain)");
|
||||
|
||||
ui.add_space(10.0);
|
||||
ui.heading("Followed");
|
||||
ui.heading("Followed:");
|
||||
let mut limit = 10;
|
||||
for pk in &app.wizard_state.followed {
|
||||
let person = match GLOBALS.storage.read_person(pk) {
|
||||
@ -107,16 +70,76 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
|
||||
limit -= 1;
|
||||
if limit == 0 && app.wizard_state.followed.len() > 10 {
|
||||
ui.label(format!("and {} more", app.wizard_state.followed.len() - 10));
|
||||
ui.add_space(10.0);
|
||||
ui.label(format!(
|
||||
"...and {} more",
|
||||
app.wizard_state.followed.len() - 10
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(10.0);
|
||||
ui.separator();
|
||||
ui.add_space(20.0);
|
||||
if ui
|
||||
.button(RichText::new(" > Publish and Finish").color(app.settings.theme.accent_color()))
|
||||
.clicked()
|
||||
{
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Follow Someone:");
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.follow_someone).hint_text(
|
||||
"Enter a key (bech32 npub1 or hex), or an nprofile, or a DNS id (user@domain)",
|
||||
))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
if ui.button("follow").clicked() {
|
||||
if let Ok(pubkey) = PublicKey::try_from_bech32_string(app.follow_someone.trim(), true) {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::FollowPubkey(pubkey));
|
||||
} else if let Ok(pubkey) =
|
||||
PublicKey::try_from_hex_string(app.follow_someone.trim(), true)
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::FollowPubkey(pubkey));
|
||||
} else if let Ok(profile) =
|
||||
Profile::try_from_bech32_string(app.follow_someone.trim(), true)
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::FollowNprofile(profile));
|
||||
} else if crate::nip05::parse_nip05(app.follow_someone.trim()).is_ok() {
|
||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::FollowNip05(
|
||||
app.follow_someone.trim().to_owned(),
|
||||
));
|
||||
} else {
|
||||
app.wizard_state.error = Some("ERROR: Invalid pubkey".to_owned());
|
||||
}
|
||||
app.follow_someone = "".to_owned();
|
||||
}
|
||||
});
|
||||
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
ui.add_space(10.0);
|
||||
ui.label("We accept:");
|
||||
ui.label(" • Public key (npub1..)");
|
||||
ui.label(" • Public key (hex)");
|
||||
ui.label(" • Profile (nprofile1..)");
|
||||
ui.label(" • DNS ID (user@domain)");
|
||||
|
||||
ui.add_space(20.0);
|
||||
let mut label = RichText::new(" > Publish and Finish");
|
||||
if app.wizard_state.new_user {
|
||||
label = label.color(app.settings.theme.accent_color());
|
||||
}
|
||||
if ui.button(label).clicked() {
|
||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::PushFollow);
|
||||
|
||||
let _ = GLOBALS.storage.write_wizard_complete(true, None);
|
||||
@ -124,7 +147,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
}
|
||||
|
||||
ui.add_space(20.0);
|
||||
if ui.button(" > Finish without publishing").clicked() {
|
||||
let mut label = RichText::new(" > Finish without publishing");
|
||||
if !app.wizard_state.new_user {
|
||||
label = label.color(app.settings.theme.accent_color());
|
||||
}
|
||||
if ui.button(label).clicked() {
|
||||
let _ = GLOBALS.storage.write_wizard_complete(true, None);
|
||||
app.page = Page::Feed(FeedKind::Followed(false));
|
||||
}
|
||||
|
@ -16,12 +16,17 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Enter your private key");
|
||||
ui.add(
|
||||
text_edit_line!(app, app.import_priv)
|
||||
.hint_text("nsec1 or hex")
|
||||
.desired_width(f32::INFINITY)
|
||||
.password(true),
|
||||
);
|
||||
if ui
|
||||
.add(
|
||||
text_edit_line!(app, app.import_priv)
|
||||
.hint_text("nsec1 or hex")
|
||||
.desired_width(f32::INFINITY)
|
||||
.password(true),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
};
|
||||
});
|
||||
|
||||
let ncryptsec = app.import_priv.starts_with("ncryptsec1");
|
||||
@ -29,23 +34,40 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
ui.add_space(10.0);
|
||||
ui.horizontal(|ui| {
|
||||
if ncryptsec {
|
||||
ui.label("Enter passphrase to decrypt the encryptd private key");
|
||||
ui.label("Enter passphrase to decrypt the encrypted private key");
|
||||
} else {
|
||||
ui.label("Enter a passphrase to keep it encrypted under");
|
||||
}
|
||||
ui.add(text_edit_line!(app, app.password).password(true));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.password).password(true))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
if !ncryptsec {
|
||||
ui.add_space(10.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Repeat passphrase to be sure");
|
||||
ui.add(text_edit_line!(app, app.password2).password(true));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.password2).password(true))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let ready = !app.import_priv.is_empty() && !app.password.is_empty() &&
|
||||
(ncryptsec || !app.password2.is_empty());
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
let ready = !app.import_priv.is_empty()
|
||||
&& !app.password.is_empty()
|
||||
&& (ncryptsec || !app.password2.is_empty());
|
||||
|
||||
if ready {
|
||||
ui.add_space(10.0);
|
||||
@ -54,10 +76,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
.clicked()
|
||||
{
|
||||
if !ncryptsec && app.password != app.password2 {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Passwords do not match".to_owned());
|
||||
app.wizard_state.error = Some("ERROR: Passwords do not match".to_owned());
|
||||
} else {
|
||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::ImportPriv(
|
||||
app.import_priv.clone(),
|
||||
|
@ -21,18 +21,33 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Enter your public key");
|
||||
ui.add(text_edit_line!(app, app.import_pub).desired_width(f32::INFINITY));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.import_pub).desired_width(f32::INFINITY))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
if ui
|
||||
.button(RichText::new(" > Import").color(app.settings.theme.accent_color()))
|
||||
.clicked()
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::ImportPub(app.import_pub.clone()));
|
||||
app.import_pub = "".to_owned();
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
let ready = !app.import_pub.is_empty();
|
||||
|
||||
if ready {
|
||||
ui.add_space(10.0);
|
||||
if ui
|
||||
.button(RichText::new(" > Import").color(app.settings.theme.accent_color()))
|
||||
.clicked()
|
||||
{
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::ImportPub(app.import_pub.clone()));
|
||||
app.import_pub = "".to_owned();
|
||||
}
|
||||
}
|
||||
|
||||
ui.add_space(20.0);
|
||||
|
@ -3,8 +3,8 @@ use crate::globals::GLOBALS;
|
||||
use crate::relay::Relay;
|
||||
use crate::ui::{GossipUi, Page};
|
||||
use eframe::egui;
|
||||
use egui::widgets::{Button, Label, Slider};
|
||||
use egui::{Align, Context, Layout, RichText, Sense};
|
||||
use egui::widgets::{Button, Slider};
|
||||
use egui::{Align, Context, Layout};
|
||||
|
||||
mod follow_people;
|
||||
mod import_keys;
|
||||
@ -20,26 +20,26 @@ mod wizard_state;
|
||||
pub use wizard_state::WizardState;
|
||||
|
||||
static DEFAULT_RELAYS: [&str; 20] = [
|
||||
"wss://nostr.zbd.gg/",
|
||||
"wss://nostr.einundzwanzig.space/",
|
||||
"wss://christpill.nostr1.com/",
|
||||
"wss://nostr.mutinywallet.com/",
|
||||
"wss://relay.nostrplebs.com/",
|
||||
"wss://bevo.nostr1.com/",
|
||||
"wss://relay.shitforce.one/",
|
||||
"wss://nostr.naut.social/",
|
||||
"wss://nostrsatva.net/",
|
||||
"wss://lightningrelay.com/",
|
||||
"wss://nostr.688.org/",
|
||||
"wss://xmr.usenostr.org/",
|
||||
"wss://knostr.neutrine.com/",
|
||||
"wss://relay.current.fyi/",
|
||||
"wss://e.nos.lol/",
|
||||
"wss://nostr.thesamecat.io/",
|
||||
"wss://christpill.nostr1.com/",
|
||||
"wss://nostr-pub.wellorder.net/",
|
||||
"wss://nostr.sovbit.host/",
|
||||
"wss://relay.nostr.jabber.ch/",
|
||||
"wss://relay.damus.io/",
|
||||
"wss://bevo.nostr1.com/",
|
||||
"wss://relay.snort.social/",
|
||||
"wss://public.relaying.io/",
|
||||
"wss://nostrue.com/",
|
||||
"wss://relay.noswhere.com/",
|
||||
"wss://relay.primal.net/",
|
||||
"wss://relay.nostr.jabber.ch/",
|
||||
"wss://relay.nostr.band/",
|
||||
"wss://relay.wellorder.net/",
|
||||
"wss://nostr.coinfundit.com/",
|
||||
"wss://relay.nostrich.de/",
|
||||
"wss://verbiricha.nostr1.com/",
|
||||
"wss://nostr21.com/",
|
||||
"wss://nostr.bitcoiner.social/",
|
||||
];
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@ -163,46 +163,6 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
||||
// Update the wizard state
|
||||
app.wizard_state.update();
|
||||
|
||||
egui::TopBottomPanel::bottom("wizard-messages")
|
||||
.show_separator_line(false)
|
||||
.frame(
|
||||
egui::Frame::none()
|
||||
.inner_margin({
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let margin = egui::Margin::symmetric(20.0, 20.0);
|
||||
#[cfg(target_os = "macos")]
|
||||
let margin = egui::Margin {
|
||||
left: 20.0,
|
||||
right: 20.0,
|
||||
top: 35.0,
|
||||
bottom: 20.0,
|
||||
};
|
||||
margin
|
||||
})
|
||||
.fill(app.settings.theme.navigation_bg_fill()),
|
||||
)
|
||||
.show(ctx, |ui| {
|
||||
let messages = GLOBALS.status_queue.read().read_all();
|
||||
if ui
|
||||
.add(Label::new(RichText::new(&messages[0]).strong()).sense(Sense::click()))
|
||||
.clicked()
|
||||
{
|
||||
GLOBALS.status_queue.write().dismiss(0);
|
||||
}
|
||||
if ui
|
||||
.add(Label::new(RichText::new(&messages[1]).small()).sense(Sense::click()))
|
||||
.clicked()
|
||||
{
|
||||
GLOBALS.status_queue.write().dismiss(1);
|
||||
}
|
||||
if ui
|
||||
.add(Label::new(RichText::new(&messages[2]).weak().small()).sense(Sense::click()))
|
||||
.clicked()
|
||||
{
|
||||
GLOBALS.status_queue.write().dismiss(2);
|
||||
}
|
||||
});
|
||||
|
||||
egui::CentralPanel::default()
|
||||
.frame({
|
||||
let frame = egui::Frame::central_panel(&app.settings.theme.get_style());
|
||||
@ -217,6 +177,12 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
|
||||
ui.add_space(24.0);
|
||||
ui.heading(wp.as_str());
|
||||
ui.add_space(12.0);
|
||||
/*
|
||||
if let Some(err) = app.wizard_state.error {
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
ui.add_space(12.0);
|
||||
}
|
||||
*/
|
||||
ui.separator();
|
||||
|
||||
match wp {
|
||||
|
@ -98,43 +98,32 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
ui.add_space(20.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Enter Relay URL");
|
||||
ui.add(text_edit_line!(app, app.wizard_state.relay_url));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.wizard_state.relay_url))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(20.0);
|
||||
if ui.button(" > Fetch From This Relay").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::SubscribeConfig(rurl.to_owned()));
|
||||
app.wizard_state.relay_url = String::new();
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid Relay URL".to_string());
|
||||
}
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
if app.wizard_state.need_relay_list() {
|
||||
let ready = !app.wizard_state.relay_url.is_empty();
|
||||
|
||||
if ready {
|
||||
ui.add_space(20.0);
|
||||
if ui
|
||||
.button(" > Look up my relay list from this Relay")
|
||||
.clicked()
|
||||
{
|
||||
if ui.button(" > Fetch From This Relay").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::SubscribeDiscover(
|
||||
vec![pubkey],
|
||||
Some(vec![rurl.to_owned()]),
|
||||
));
|
||||
.send(ToOverlordMessage::SubscribeConfig(rurl.to_owned()));
|
||||
app.wizard_state.relay_url = String::new();
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid Relay URL".to_string());
|
||||
app.wizard_state.error = Some("ERROR: Invalid Relay URL".to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,30 +53,50 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Name:");
|
||||
ui.add(text_edit_line!(app, app.wizard_state.metadata_name));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.wizard_state.metadata_name))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(15.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("About:");
|
||||
ui.add(text_edit_multiline!(app, app.wizard_state.metadata_about));
|
||||
if ui
|
||||
.add(text_edit_multiline!(app, app.wizard_state.metadata_about))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(15.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Picture:");
|
||||
ui.add(text_edit_multiline!(app, app.wizard_state.metadata_picture));
|
||||
if ui
|
||||
.add(text_edit_multiline!(app, app.wizard_state.metadata_picture))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
ui.add_space(15.0);
|
||||
|
||||
ui.add_space(20.0);
|
||||
if ui
|
||||
.button(
|
||||
RichText::new(" > Save, Publish and Continue")
|
||||
.color(app.settings.theme.accent_color()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
let mut label = RichText::new(" > Save, Publish and Continue");
|
||||
if app.wizard_state.new_user {
|
||||
label = label.color(app.settings.theme.accent_color());
|
||||
}
|
||||
if ui.button(label).clicked() {
|
||||
// Copy from form and save
|
||||
save_metadata(app, you.clone(), metadata.clone());
|
||||
|
||||
@ -100,10 +120,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
}
|
||||
|
||||
ui.add_space(20.0);
|
||||
if ui
|
||||
.button(" > Continue without saving or publishing")
|
||||
.clicked()
|
||||
{
|
||||
let mut label = RichText::new(" > Continue without saving or publishing");
|
||||
if !app.wizard_state.new_user {
|
||||
label = label.color(app.settings.theme.accent_color());
|
||||
}
|
||||
if ui.button(label).clicked() {
|
||||
app.page = Page::Wizard(WizardPage::FollowPeople);
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,12 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
ui.add_space(15.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Enter Relay URL");
|
||||
ui.add(text_edit_line!(app, app.wizard_state.relay_url));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.wizard_state.relay_url))
|
||||
.changed
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
ui.label("or");
|
||||
ui.menu_button("▼ Pick from Top Relays", |ui| {
|
||||
for (url, _relay) in relay_options.iter() {
|
||||
@ -167,66 +172,66 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
});
|
||||
});
|
||||
|
||||
ui.add_space(15.0);
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button(" ^ Add to Outbox").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
if !relay_options.contains_key(&rurl) {
|
||||
relay_options.insert(rurl.clone(), read_relay(&rurl));
|
||||
}
|
||||
let r = relay_options.get_mut(&rurl).unwrap();
|
||||
r.set_usage_bits(Relay::OUTBOX | Relay::WRITE);
|
||||
let _ = GLOBALS.storage.write_relay(r, None);
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid Relay URL".to_string());
|
||||
}
|
||||
}
|
||||
let ready = !app.wizard_state.relay_url.is_empty();
|
||||
|
||||
if ui.button(" ^ Add to Inbox").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
if !relay_options.contains_key(&rurl) {
|
||||
relay_options.insert(rurl.clone(), read_relay(&rurl));
|
||||
}
|
||||
let r = relay_options.get_mut(&rurl).unwrap();
|
||||
r.set_usage_bits(Relay::INBOX | Relay::READ);
|
||||
let _ = GLOBALS.storage.write_relay(r, None);
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid Relay URL".to_string());
|
||||
}
|
||||
}
|
||||
if ready {
|
||||
ui.add_space(15.0);
|
||||
|
||||
if ui.button(" ^ Add to Discovery").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
if !relay_options.contains_key(&rurl) {
|
||||
relay_options.insert(rurl.clone(), read_relay(&rurl));
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button(" ^ Add to Outbox").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
if !relay_options.contains_key(&rurl) {
|
||||
relay_options.insert(rurl.clone(), read_relay(&rurl));
|
||||
}
|
||||
let r = relay_options.get_mut(&rurl).unwrap();
|
||||
r.set_usage_bits(Relay::OUTBOX | Relay::WRITE);
|
||||
let _ = GLOBALS.storage.write_relay(r, None);
|
||||
} else {
|
||||
app.wizard_state.error = Some("ERROR: Invalid Relay URL".to_owned());
|
||||
}
|
||||
let r = relay_options.get_mut(&rurl).unwrap();
|
||||
r.set_usage_bits(Relay::DISCOVER | Relay::ADVERTISE);
|
||||
let _ = GLOBALS.storage.write_relay(r, None);
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid Relay URL".to_string());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if ui.button(" ^ Add to Inbox").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
if !relay_options.contains_key(&rurl) {
|
||||
relay_options.insert(rurl.clone(), read_relay(&rurl));
|
||||
}
|
||||
let r = relay_options.get_mut(&rurl).unwrap();
|
||||
r.set_usage_bits(Relay::INBOX | Relay::READ);
|
||||
let _ = GLOBALS.storage.write_relay(r, None);
|
||||
} else {
|
||||
app.wizard_state.error = Some("ERROR: Invalid Relay URL".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
if ui.button(" ^ Add to Discovery").clicked() {
|
||||
if let Ok(rurl) = RelayUrl::try_from_str(&app.wizard_state.relay_url) {
|
||||
if !relay_options.contains_key(&rurl) {
|
||||
relay_options.insert(rurl.clone(), read_relay(&rurl));
|
||||
}
|
||||
let r = relay_options.get_mut(&rurl).unwrap();
|
||||
r.set_usage_bits(Relay::DISCOVER | Relay::ADVERTISE);
|
||||
let _ = GLOBALS.storage.write_relay(r, None);
|
||||
} else {
|
||||
app.wizard_state.error = Some("ERROR: Invalid Relay URL".to_owned());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if !need_more {
|
||||
ui.add_space(20.0);
|
||||
if ui
|
||||
.button(
|
||||
RichText::new(" > Publish and Continue").color(app.settings.theme.accent_color()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
let mut label = RichText::new(" > Publish and Continue");
|
||||
if app.wizard_state.new_user {
|
||||
label = label.color(app.settings.theme.accent_color());
|
||||
}
|
||||
if ui.button(label).clicked() {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::AdvertiseRelayList);
|
||||
@ -234,7 +239,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
}
|
||||
|
||||
ui.add_space(20.0);
|
||||
if ui.button(" > Continue without publishing").clicked() {
|
||||
let mut label = RichText::new(" > Continue without publishing");
|
||||
if !app.wizard_state.new_user {
|
||||
label = label.color(app.settings.theme.accent_color());
|
||||
}
|
||||
if ui.button(label).clicked() {
|
||||
app.page = Page::Wizard(WizardPage::SetupMetadata);
|
||||
};
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use zeroize::Zeroize;
|
||||
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
// If already generated, advance
|
||||
if app.wizard_state.has_private_key {
|
||||
app.page = Page::Wizard(WizardPage::ReadNostrConfig);
|
||||
app.page = Page::Wizard(WizardPage::SetupRelays);
|
||||
}
|
||||
|
||||
ui.add_space(10.0);
|
||||
@ -27,34 +27,51 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
ui.add_space(10.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Enter a passphrase to keep it encrypted under");
|
||||
ui.add(text_edit_line!(app, app.password).password(true));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.password).password(true))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Repeat that passphrase");
|
||||
ui.add(text_edit_line!(app, app.password2).password(true));
|
||||
if ui
|
||||
.add(text_edit_line!(app, app.password2).password(true))
|
||||
.changed()
|
||||
{
|
||||
app.wizard_state.error = None;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
if ui
|
||||
.button(RichText::new(" > Generate Now").color(app.settings.theme.accent_color()))
|
||||
.clicked()
|
||||
{
|
||||
if app.password != app.password2 {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Passwords do not match".to_owned());
|
||||
} else {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::GeneratePrivateKey(app.password.clone()));
|
||||
// error block
|
||||
if let Some(err) = &app.wizard_state.error {
|
||||
ui.add_space(10.0);
|
||||
ui.label(RichText::new(err).color(app.settings.theme.warning_marker_text_color()));
|
||||
}
|
||||
|
||||
let ready = !app.password.is_empty() && !app.password2.is_empty();
|
||||
|
||||
if ready {
|
||||
ui.add_space(10.0);
|
||||
if ui
|
||||
.button(RichText::new(" > Generate Now").color(app.settings.theme.accent_color()))
|
||||
.clicked()
|
||||
{
|
||||
if app.password != app.password2 {
|
||||
app.wizard_state.error = Some("ERROR: Passwords do not match".to_owned());
|
||||
} else {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::GeneratePrivateKey(app.password.clone()));
|
||||
}
|
||||
app.password.zeroize();
|
||||
app.password = "".to_owned();
|
||||
app.password2.zeroize();
|
||||
app.password2 = "".to_owned();
|
||||
}
|
||||
app.password.zeroize();
|
||||
app.password = "".to_owned();
|
||||
app.password2.zeroize();
|
||||
app.password2 = "".to_owned();
|
||||
}
|
||||
|
||||
ui.add_space(20.0);
|
||||
|
@ -3,8 +3,10 @@ use crate::relay::Relay;
|
||||
use nostr_types::{Event, EventKind, PublicKey, RelayUrl};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
pub struct WizardState {
|
||||
pub error: Option<String>,
|
||||
pub last_status_queue_message: String,
|
||||
pub new_user: bool,
|
||||
pub follow_only: bool,
|
||||
pub relay_url: String,
|
||||
@ -21,8 +23,34 @@ pub struct WizardState {
|
||||
pub relays: Vec<Relay>,
|
||||
pub followed: Vec<PublicKey>,
|
||||
pub followed_getting_metadata: HashSet<PublicKey>,
|
||||
pub contacts_sought: bool,
|
||||
}
|
||||
|
||||
impl Default for WizardState {
|
||||
fn default() -> WizardState {
|
||||
WizardState {
|
||||
error: None,
|
||||
last_status_queue_message: "".to_owned(),
|
||||
new_user: false,
|
||||
follow_only: false,
|
||||
relay_url: "wss://purplepag.es/".to_owned(),
|
||||
relay_list_sought: true,
|
||||
metadata_copied: false,
|
||||
metadata_name: "".to_owned(),
|
||||
metadata_about: "".to_owned(),
|
||||
metadata_picture: "".to_owned(),
|
||||
pubkey: None,
|
||||
has_private_key: false,
|
||||
metadata_events: Vec::new(),
|
||||
contact_list_events: Vec::new(),
|
||||
relay_list_events: Vec::new(),
|
||||
relays: Vec::new(),
|
||||
followed: Vec::new(),
|
||||
followed_getting_metadata: HashSet::new(),
|
||||
contacts_sought: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl WizardState {
|
||||
pub fn update(&mut self) {
|
||||
self.follow_only = GLOBALS.storage.read_following_only();
|
||||
@ -62,6 +90,15 @@ impl WizardState {
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
// Copy any new status queue messages into our local error variable
|
||||
let last_status_queue_message = GLOBALS.status_queue.read().read_last();
|
||||
if last_status_queue_message != self.last_status_queue_message {
|
||||
if !last_status_queue_message.starts_with("Welcome to Gossip") {
|
||||
self.error = Some(last_status_queue_message.clone());
|
||||
self.last_status_queue_message = last_status_queue_message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user