chore: clean up sidebar on group panel closed

This commit is contained in:
2026-10-12 21:07:43 +07:00
parent 830917d897
commit 62719f42d9
4 changed files with 24 additions and 26 deletions
+1 -1
View File
@@ -1752,7 +1752,7 @@ impl ChatPanel {
auto, auto,
) )
.menu_with_check_and_disabled( .menu_with_check_and_disabled(
"Decoupled Encryption Key", "Encryption Key",
encryption, encryption,
Box::new(Command::ChangeSigner(SignerKind::Encryption)), Box::new(Command::ChangeSigner(SignerKind::Encryption)),
encryption, encryption,
+4
View File
@@ -1192,6 +1192,10 @@ impl Panel for GroupPanel {
window.dispatch_action(Box::new(HideGroupMeta { relay, group: id }), cx); window.dispatch_action(Box::new(HideGroupMeta { relay, group: id }), cx);
} }
} }
fn on_removed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.set_active(false, window, cx);
}
} }
impl EventEmitter<PanelEvent> for GroupPanel {} impl EventEmitter<PanelEvent> for GroupPanel {}
+4 -22
View File
@@ -83,8 +83,6 @@ pub struct NostrRegistry {
current_user: Option<PublicKey>, current_user: Option<PublicKey>,
/// Whether the stored credential needs a passphrase to unlock /// Whether the stored credential needs a passphrase to unlock
passphrase_required: bool, passphrase_required: bool,
/// Whether the initial credential check has concluded
ready: bool,
/// Tasks for asynchronous operations /// Tasks for asynchronous operations
tasks: Vec<Task<Result<(), Error>>>, tasks: Vec<Task<Result<(), Error>>>,
} }
@@ -139,7 +137,6 @@ impl NostrRegistry {
this.connect_bootstrap_relays(cx); this.connect_bootstrap_relays(cx);
if cfg!(target_arch = "wasm32") { if cfg!(target_arch = "wasm32") {
this.mark_ready(cx);
cx.emit(StateEvent::NoSigner); cx.emit(StateEvent::NoSigner);
} else if let Some(secret) = cli_key { } else if let Some(secret) = cli_key {
// Use CLI-provided key -- same path as restore_session // Use CLI-provided key -- same path as restore_session
@@ -156,7 +153,6 @@ impl NostrRegistry {
signer, signer,
current_user: None, current_user: None,
passphrase_required: false, passphrase_required: false,
ready: false,
tasks: vec![], tasks: vec![],
} }
} }
@@ -176,15 +172,6 @@ impl NostrRegistry {
self.current_user self.current_user
} }
fn mark_ready(&mut self, cx: &mut Context<Self>) {
if self.ready {
return;
}
self.ready = true;
cx.notify();
}
/// Update the signer /// Update the signer
fn set_signer<T>(&mut self, new_signer: T, cx: &mut Context<Self>) fn set_signer<T>(&mut self, new_signer: T, cx: &mut Context<Self>)
where where
@@ -200,7 +187,7 @@ impl NostrRegistry {
this.signer.swap_inner(new_signer); this.signer.swap_inner(new_signer);
this.current_user = Some(public_key); this.current_user = Some(public_key);
this.passphrase_required = false; this.passphrase_required = false;
this.mark_ready(cx);
cx.emit(StateEvent::SignerChanged); cx.emit(StateEvent::SignerChanged);
cx.notify(); cx.notify();
})?; })?;
@@ -289,25 +276,21 @@ impl NostrRegistry {
} else if content.starts_with("ncryptsec1") { } else if content.starts_with("ncryptsec1") {
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.passphrase_required = true; this.passphrase_required = true;
this.mark_ready(cx);
cx.emit(StateEvent::PassphraseRequired); cx.emit(StateEvent::PassphraseRequired);
})?; })?;
} else if content == "proxy" { } else if content == "proxy" {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.mark_ready(cx);
this.connect_proxy(cx); this.connect_proxy(cx);
})?; })?;
} else { } else {
this.update(cx, |this, cx| { this.update(cx, |_, cx| {
this.mark_ready(cx);
cx.emit(StateEvent::NoSigner); cx.emit(StateEvent::NoSigner);
})?; })?;
} }
} }
_ => { _ => {
this.update(cx, |this, cx| { this.update(cx, |_, cx| {
this.mark_ready(cx);
cx.emit(StateEvent::NoSigner); cx.emit(StateEvent::NoSigner);
})?; })?;
} }
@@ -318,8 +301,7 @@ impl NostrRegistry {
.await; .await;
if let Err(e) = result { if let Err(e) = result {
this.update(cx, |this, cx| { this.update(cx, |_, cx| {
this.mark_ready(cx);
cx.emit(StateEvent::error(e.to_string())); cx.emit(StateEvent::error(e.to_string()));
cx.emit(StateEvent::NoSigner); cx.emit(StateEvent::NoSigner);
})?; })?;
+15 -3
View File
@@ -2,8 +2,8 @@ use std::any::Any;
use std::sync::Arc; use std::sync::Arc;
use gpui::{ use gpui::{
AnyElement, AnyView, App, Element, Entity, EventEmitter, FocusHandle, Focusable, Render, AnyElement, AnyView, App, Context, Element, Entity, EventEmitter, FocusHandle, Focusable,
SharedString, Window, Render, SharedString, Window,
}; };
use gpui_base::dock::{PanelId, PanelState}; use gpui_base::dock::{PanelId, PanelState};
@@ -39,6 +39,9 @@ pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
/// Set active state of the panel. /// Set active state of the panel.
fn set_active(&self, _active: bool, _window: &mut Window, _cx: &mut App) {} 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<Self>) {}
/// Set zoomed state of the panel. /// Set zoomed state of the panel.
fn set_zoomed(&self, _zoomed: bool, _cx: &mut App) {} 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 visible(&self, cx: &App) -> bool;
fn set_active(&self, active: bool, window: &mut Window, cx: &mut App); fn set_active(&self, active: bool, window: &mut Window, cx: &mut App);
fn set_zoomed(&self, zoomed: bool, 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 view(&self) -> AnyView;
fn focus_handle(&self, cx: &App) -> FocusHandle; fn focus_handle(&self, cx: &App) -> FocusHandle;
} }
@@ -93,6 +97,12 @@ impl<T: Panel> PanelView for Entity<T> {
}) })
} }
fn on_removed(&self, window: &mut Window, cx: &mut App) {
self.update(cx, |this, cx| {
this.on_removed(window, cx);
})
}
fn view(&self) -> AnyView { fn view(&self) -> AnyView {
self.clone().into() 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 { fn view(&self) -> AnyView {
self.panel.view() self.panel.view()