@@ -16,7 +16,7 @@ use std::collections::HashSet;
1616use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1717use std:: sync:: { Arc , Mutex , OnceLock } ;
1818
19- use crate :: { NOSTR_CLIENT , MY_PUBLIC_KEY } ;
19+ use crate :: { NOSTR_CLIENT , MY_KEYS , MY_PUBLIC_KEY } ;
2020use crate :: commands:: relays:: DEFAULT_RELAYS ;
2121use crate :: services:: event_handler:: handle_event_with_context;
2222
@@ -248,22 +248,25 @@ fn run_standalone_sync_loop(data_dir: &str) {
248248
249249 rt. block_on ( async {
250250 // Bootstrap the standalone client — get connected ASAP
251- let ( client, my_public_key, can_decrypt) = match bootstrap_client ( data_dir) . await {
251+ let ( client, my_public_key, can_decrypt, keys ) = match bootstrap_client ( data_dir) . await {
252252 Ok ( result) => result,
253253 Err ( e) => {
254254 logcat ( & format ! ( "Failed to bootstrap client: {}" , e) ) ;
255255 return ;
256256 }
257257 } ;
258258
259- // Store the client and public key in globals so headless operations
259+ // Store the client, keys, and public key in globals so headless operations
260260 // (notification reply, mark-as-read) can use them in service-only mode.
261261 // ONLY set for unencrypted accounts — encrypted accounts use a signerless
262262 // client that would poison the OnceCell and prevent the full app from
263263 // creating a proper client with signer after PIN unlock.
264264 if can_decrypt {
265265 let _ = NOSTR_CLIENT . set ( client. clone ( ) ) ;
266266 let _ = MY_PUBLIC_KEY . set ( my_public_key) ;
267+ if let Some ( keys) = keys {
268+ let _ = MY_KEYS . set ( keys) ;
269+ }
267270 }
268271
269272 // Subscribe to GiftWraps addressed to us (DMs, files, MLS welcomes)
@@ -402,7 +405,7 @@ fn run_standalone_sync_loop(data_dir: &str) {
402405/// Returns (client, public_key, can_decrypt).
403406/// When local encryption is enabled, returns a read-only client (no signer) that can
404407/// subscribe to events but not decrypt them — used for generic "New message" notifications.
405- async fn bootstrap_client ( data_dir : & str ) -> Result < ( Client , PublicKey , bool ) , String > {
408+ async fn bootstrap_client ( data_dir : & str ) -> Result < ( Client , PublicKey , bool , Option < Keys > ) , String > {
406409 let data_path = std:: path:: Path :: new ( data_dir) ;
407410
408411 // Scan for npub directories
@@ -486,7 +489,7 @@ async fn bootstrap_client(data_dir: &str) -> Result<(Client, PublicKey, bool), S
486489 logcat ( & format ! ( "Connecting to {} relays..." , DEFAULT_RELAYS . len( ) ) ) ;
487490 client. connect ( ) . await ;
488491
489- Ok ( ( client, my_public_key, false ) )
492+ Ok ( ( client, my_public_key, false , None ) )
490493 } else {
491494 // Normal account — full signer client
492495 let pkey: String = conn
@@ -508,7 +511,7 @@ async fn bootstrap_client(data_dir: &str) -> Result<(Client, PublicKey, bool), S
508511 & my_public_key. to_bech32( ) . unwrap_or_default( ) [ ..20 . min( my_public_key. to_bech32( ) . unwrap_or_default( ) . len( ) ) ] ) ) ;
509512
510513 let client = Client :: builder ( )
511- . signer ( keys)
514+ . signer ( keys. clone ( ) )
512515 . build ( ) ;
513516
514517 for relay_url in DEFAULT_RELAYS {
@@ -520,7 +523,7 @@ async fn bootstrap_client(data_dir: &str) -> Result<(Client, PublicKey, bool), S
520523 logcat ( & format ! ( "Connecting to {} relays..." , DEFAULT_RELAYS . len( ) ) ) ;
521524 client. connect ( ) . await ;
522525
523- Ok ( ( client, my_public_key, true ) )
526+ Ok ( ( client, my_public_key, true , Some ( keys ) ) )
524527 }
525528}
526529
0 commit comments