From 41faf033e04e06d3095127673126ca69f4428aae Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sun, 2 Aug 2026 18:25:47 +0700 Subject: [PATCH] . --- crates/state/src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 62ff7aa..e33c3e0 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -264,6 +264,10 @@ impl NostrRegistry { this.set_signer(signer, cx); cx.notify(); })?; + } else if content == "proxy" { + this.update(cx, |this, cx| { + this.connect_proxy(cx); + })?; } } _ => { @@ -344,6 +348,8 @@ impl NostrRegistry { async move |this, cx| { while let Ok(url) = rx.recv_async().await { this.update(cx, |this, cx| { + let save = cx.write_credentials(USER_KEYRING, "proxy", b"proxy"); + cx.background_spawn(async move { save.await.ok() }).detach(); cx.open_url(&url); this.set_signer(proxy.clone(), cx); })?; @@ -351,6 +357,34 @@ impl NostrRegistry { Ok(()) } })); + + // Monitor the session, if the browser disconnects, notify user to reconnect + self.tasks.push(cx.spawn({ + let proxy = proxy.clone(); + let executor = cx.background_executor().clone(); + async move |this, cx| { + // Wait for the signer to be confirmed (timeout is 30s) + executor.timer(Duration::from_secs(30)).await; + + loop { + executor.timer(Duration::from_secs(5)).await; + if !proxy.is_session_active() { + _ = this.update(cx, |this, cx| { + // Only notify if this proxy is still the active signer + if this.current_user.is_some() { + this.signer.swap_inner(Keys::generate()); + this.current_user = None; + cx.emit(StateEvent::NoSigner); + cx.notify(); + } + }); + break; + } + } + + Ok(()) + } + })); } /// Get the public key of a NIP-05 address