Offer to unlock keys directly in posting area

This commit is contained in:
Bu5hm4nn 2023-05-12 08:43:39 -06:00
parent d45885ee2b
commit 45a14138f0
3 changed files with 32 additions and 41 deletions

View File

@ -2,7 +2,7 @@ use super::FeedNoteParams;
use crate::comms::ToOverlordMessage;
use crate::db::DbRelay;
use crate::globals::GLOBALS;
use crate::ui::{GossipUi, HighlightType, Page, Theme};
use crate::ui::{GossipUi, HighlightType, Page, Theme, you};
use eframe::egui;
use eframe::epaint::text::LayoutJob;
use egui::{Align, Context, Key, Layout, Modifiers, RichText, ScrollArea, Ui, Vec2};
@ -70,11 +70,15 @@ pub(in crate::ui) fn posting_area(
ui.vertical(|ui| {
if !GLOBALS.signer.is_ready() {
ui.horizontal_wrapped(|ui| {
ui.label("You need to ");
if ui.link("setup your identity").clicked() {
app.set_page(Page::YourKeys);
if GLOBALS.signer.encrypted_private_key().is_some() {
you::offer_unlock_priv_key(app, ui);
} else {
ui.label("You need to ");
if ui.link("setup your identity").clicked() {
app.set_page(Page::YourKeys);
}
ui.label(" to post.");
}
ui.label(" to post.");
});
} else if !GLOBALS
.all_relays

View File

@ -825,33 +825,22 @@ impl eframe::App for GossipUi {
.show(
ui,
|ui| {
if GLOBALS.signer.is_ready() {
let response = ui.add_sized(
[ crate::AVATAR_SIZE_F32 , crate::AVATAR_SIZE_F32 ],
egui::Button::new( RichText::new("+")
.size(22.5)
.color(self.settings.theme.navigation_text_color()))
.stroke(egui::Stroke::NONE)
.rounding(egui::Rounding::same(90.0))
.fill(self.settings.theme.navigation_bg_fill()) );
if response.clicked() {
self.show_post_area = true;
}
response.on_hover_cursor(egui::CursorIcon::PointingHand);
let text = if GLOBALS.signer.is_ready() {
RichText::new("+").size(22.5)
} else {
let response = ui.add_sized(
[ crate::AVATAR_SIZE_F32, crate::AVATAR_SIZE_F32 ],
egui::Button::new( RichText::new("\u{1f513}")
.size(20.0)
.color(self.settings.theme.navigation_text_color()))
.stroke(egui::Stroke::NONE)
.rounding(egui::Rounding::same(90.0))
.fill(self.settings.theme.navigation_bg_fill()) );
if response.clicked() {
self.set_page(Page::YourKeys);
}
response.on_hover_cursor(egui::CursorIcon::PointingHand);
RichText::new("\u{1f513}").size(20.0)
};
let response = ui.add_sized(
[ crate::AVATAR_SIZE_F32 , crate::AVATAR_SIZE_F32 ],
egui::Button::new( text
.color(self.settings.theme.navigation_text_color()))
.stroke(egui::Stroke::NONE)
.rounding(egui::Rounding::same(90.0))
.fill(self.settings.theme.navigation_bg_fill()) );
if response.clicked() {
self.show_post_area = true;
}
response.on_hover_cursor(egui::CursorIcon::PointingHand);
});

View File

@ -120,6 +120,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
bottom: 10.0,
})
.show(ui, |ui| {
ui.heading("Passphrase Needed");
offer_unlock_priv_key(app, ui);
});
@ -216,9 +217,7 @@ fn show_pub_key_detail(app: &mut GossipUi, ctx: &Context, ui: &mut Ui) {
}
}
fn offer_unlock_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.heading("Passphrase Needed");
pub(super) fn offer_unlock_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label("Passphrase: ");
let response = ui.add(text_edit_line!(app, app.password).password(true));
@ -229,15 +228,14 @@ fn offer_unlock_priv_key(app: &mut GossipUi, ui: &mut Ui) {
app.password.zeroize();
app.password = "".to_owned();
}
if ui.button("Unlock Private Key").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
app.password.zeroize();
app.password = "".to_owned();
}
});
if ui.button("Unlock Private Key").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::UnlockKey(app.password.clone()));
app.password.zeroize();
app.password = "".to_owned();
}
}
fn show_priv_key_detail(_app: &mut GossipUi, ui: &mut Ui) {