diff --git a/crates/chat_ui/src/lib.rs b/crates/chat_ui/src/lib.rs index 7325fcf8..36583c11 100644 --- a/crates/chat_ui/src/lib.rs +++ b/crates/chat_ui/src/lib.rs @@ -1752,7 +1752,7 @@ impl ChatPanel { auto, ) .menu_with_check_and_disabled( - "Decoupled Encryption Key", + "Encryption Key", encryption, Box::new(Command::ChangeSigner(SignerKind::Encryption)), encryption, diff --git a/crates/nip29_ui/src/lib.rs b/crates/nip29_ui/src/lib.rs index 71c550e4..ed5470a9 100644 --- a/crates/nip29_ui/src/lib.rs +++ b/crates/nip29_ui/src/lib.rs @@ -1192,6 +1192,10 @@ impl Panel for GroupPanel { window.dispatch_action(Box::new(HideGroupMeta { relay, group: id }), cx); } } + + fn on_removed(&mut self, window: &mut Window, cx: &mut Context) { + self.set_active(false, window, cx); + } } impl EventEmitter for GroupPanel {} diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 3b611fb5..673e65b1 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -83,8 +83,6 @@ pub struct NostrRegistry { current_user: Option, /// Whether the stored credential needs a passphrase to unlock passphrase_required: bool, - /// Whether the initial credential check has concluded - ready: bool, /// Tasks for asynchronous operations tasks: Vec>>, } @@ -139,7 +137,6 @@ impl NostrRegistry { this.connect_bootstrap_relays(cx); if cfg!(target_arch = "wasm32") { - this.mark_ready(cx); cx.emit(StateEvent::NoSigner); } else if let Some(secret) = cli_key { // Use CLI-provided key -- same path as restore_session @@ -156,7 +153,6 @@ impl NostrRegistry { signer, current_user: None, passphrase_required: false, - ready: false, tasks: vec![], } } @@ -176,15 +172,6 @@ impl NostrRegistry { self.current_user } - fn mark_ready(&mut self, cx: &mut Context) { - if self.ready { - return; - } - - self.ready = true; - cx.notify(); - } - /// Update the signer fn set_signer(&mut self, new_signer: T, cx: &mut Context) where @@ -200,7 +187,7 @@ impl NostrRegistry { this.signer.swap_inner(new_signer); this.current_user = Some(public_key); this.passphrase_required = false; - this.mark_ready(cx); + cx.emit(StateEvent::SignerChanged); cx.notify(); })?; @@ -289,25 +276,21 @@ impl NostrRegistry { } else if content.starts_with("ncryptsec1") { this.update(cx, |this, cx| { this.passphrase_required = true; - this.mark_ready(cx); cx.emit(StateEvent::PassphraseRequired); })?; } else if content == "proxy" { #[cfg(not(target_arch = "wasm32"))] this.update(cx, |this, cx| { - this.mark_ready(cx); this.connect_proxy(cx); })?; } else { - this.update(cx, |this, cx| { - this.mark_ready(cx); + this.update(cx, |_, cx| { cx.emit(StateEvent::NoSigner); })?; } } _ => { - this.update(cx, |this, cx| { - this.mark_ready(cx); + this.update(cx, |_, cx| { cx.emit(StateEvent::NoSigner); })?; } @@ -318,8 +301,7 @@ impl NostrRegistry { .await; if let Err(e) = result { - this.update(cx, |this, cx| { - this.mark_ready(cx); + this.update(cx, |_, cx| { cx.emit(StateEvent::error(e.to_string())); cx.emit(StateEvent::NoSigner); })?; diff --git a/crates/ui/src/dock/panel.rs b/crates/ui/src/dock/panel.rs index 15cec04e..2a343abf 100644 --- a/crates/ui/src/dock/panel.rs +++ b/crates/ui/src/dock/panel.rs @@ -2,8 +2,8 @@ use std::any::Any; use std::sync::Arc; use gpui::{ - AnyElement, AnyView, App, Element, Entity, EventEmitter, FocusHandle, Focusable, Render, - SharedString, Window, + AnyElement, AnyView, App, Context, Element, Entity, EventEmitter, FocusHandle, Focusable, + Render, SharedString, Window, }; use gpui_base::dock::{PanelId, PanelState}; @@ -39,6 +39,9 @@ pub trait Panel: EventEmitter + Render + Focusable { /// Set active state of the panel. fn set_active(&self, _active: bool, _window: &mut Window, _cx: &mut App) {} + /// Called when the panel leaves the dock. + fn on_removed(&mut self, _window: &mut Window, _cx: &mut Context) {} + /// Set zoomed state of the panel. fn set_zoomed(&self, _zoomed: bool, _cx: &mut App) {} @@ -56,6 +59,7 @@ pub(crate) trait PanelView: 'static + Send + Sync { fn visible(&self, cx: &App) -> bool; fn set_active(&self, active: bool, window: &mut Window, cx: &mut App); fn set_zoomed(&self, zoomed: bool, cx: &mut App); + fn on_removed(&self, window: &mut Window, cx: &mut App); fn view(&self) -> AnyView; fn focus_handle(&self, cx: &App) -> FocusHandle; } @@ -93,6 +97,12 @@ impl PanelView for Entity { }) } + fn on_removed(&self, window: &mut Window, cx: &mut App) { + self.update(cx, |this, cx| { + this.on_removed(window, cx); + }) + } + fn view(&self) -> AnyView { self.clone().into() } @@ -163,7 +173,9 @@ impl gpui_base::dock::PanelView for PanelHandle { ) { } - fn on_removed(&self, _: &mut Window, _: &mut App) {} + fn on_removed(&self, window: &mut Window, cx: &mut App) { + self.panel.on_removed(window, cx); + } fn view(&self) -> AnyView { self.panel.view()