wip
This commit is contained in:
@@ -36,6 +36,9 @@ pub struct EncryptionPanel {
|
||||
/// Whether the panel is loading
|
||||
loading: bool,
|
||||
|
||||
/// Whether the encryption is resetting
|
||||
resetting: bool,
|
||||
|
||||
/// Tasks
|
||||
tasks: Vec<Task<Result<(), Error>>>,
|
||||
}
|
||||
@@ -47,6 +50,7 @@ impl EncryptionPanel {
|
||||
focus_handle: cx.focus_handle(),
|
||||
public_key,
|
||||
loading: false,
|
||||
resetting: false,
|
||||
tasks: vec![],
|
||||
}
|
||||
}
|
||||
@@ -91,6 +95,42 @@ impl EncryptionPanel {
|
||||
}));
|
||||
}
|
||||
|
||||
fn set_resetting(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||
self.resetting = status;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let device = DeviceRegistry::global(cx);
|
||||
let task = device.read(cx).create_encryption(cx);
|
||||
|
||||
// Update the reset status
|
||||
self.set_resetting(true, cx);
|
||||
|
||||
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||
match task.await {
|
||||
Ok(keys) => {
|
||||
this.update_in(cx, |this, _window, cx| {
|
||||
this.set_resetting(false, cx);
|
||||
|
||||
device.update(cx, |this, cx| {
|
||||
this.set_signer(keys, cx);
|
||||
this.listen_request(cx);
|
||||
});
|
||||
})?;
|
||||
}
|
||||
Err(e) => {
|
||||
this.update_in(cx, |this, window, cx| {
|
||||
this.set_resetting(false, cx);
|
||||
window.push_notification(Notification::error(e.to_string()), cx);
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
|
||||
fn render_requests(&mut self, cx: &mut Context<Self>) -> Vec<impl IntoElement> {
|
||||
const TITLE: &str = "You've requested for the Encryption Key from:";
|
||||
|
||||
@@ -269,26 +309,27 @@ impl Render for EncryptionPanel {
|
||||
)),
|
||||
)
|
||||
})
|
||||
.when(state.set(), |this| {
|
||||
this.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Button::new("reset")
|
||||
.icon(IconName::Reset)
|
||||
.label("Reset")
|
||||
.warning()
|
||||
.small()
|
||||
.font_semibold(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.italic()
|
||||
.text_size(px(10.))
|
||||
.text_color(cx.theme().text_muted)
|
||||
.child(SharedString::from(NOTICE)),
|
||||
),
|
||||
)
|
||||
})
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
Button::new("reset")
|
||||
.icon(IconName::Reset)
|
||||
.label("Reset")
|
||||
.warning()
|
||||
.small()
|
||||
.font_semibold()
|
||||
.on_click(
|
||||
cx.listener(move |this, _ev, window, cx| this.reset(window, cx)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.italic()
|
||||
.text_size(px(10.))
|
||||
.text_color(cx.theme().text_muted)
|
||||
.child(SharedString::from(NOTICE)),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use ::settings::AppSettings;
|
||||
use chat::{ChatEvent, ChatRegistry, InboxState};
|
||||
use device::DeviceRegistry;
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
div, px, rems, Action, App, AppContext, Axis, Context, Entity, InteractiveElement, IntoElement,
|
||||
@@ -36,6 +37,7 @@ enum Command {
|
||||
|
||||
RefreshRelayList,
|
||||
RefreshMessagingRelays,
|
||||
RefreshEncryption,
|
||||
|
||||
ShowRelayList,
|
||||
ShowMessaging,
|
||||
@@ -260,6 +262,12 @@ impl Workspace {
|
||||
);
|
||||
});
|
||||
}
|
||||
Command::RefreshEncryption => {
|
||||
let device = DeviceRegistry::global(cx);
|
||||
device.update(cx, |this, cx| {
|
||||
this.get_announcement(cx);
|
||||
});
|
||||
}
|
||||
Command::RefreshRelayList => {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
nostr.update(cx, |this, cx| {
|
||||
@@ -440,8 +448,19 @@ impl Workspace {
|
||||
.tooltip("Decoupled encryption key")
|
||||
.small()
|
||||
.ghost()
|
||||
.on_click(|_ev, window, cx| {
|
||||
window.dispatch_action(Box::new(Command::ShowEncryption), cx);
|
||||
.dropdown_menu(|this, _window, _cx| {
|
||||
this.min_w(px(260.))
|
||||
.label("Encryption")
|
||||
.menu_with_icon(
|
||||
"Reload",
|
||||
IconName::Refresh,
|
||||
Box::new(Command::RefreshEncryption),
|
||||
)
|
||||
.menu_with_icon(
|
||||
"View encryption",
|
||||
IconName::Settings,
|
||||
Box::new(Command::ShowEncryption),
|
||||
)
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
|
||||
Reference in New Issue
Block a user