Skip to content

Commit

Permalink
ffi(nostr-sdk): move .shutdown_on_drop(true) in Options::new and …
Browse files Browse the repository at this point in the history
…`ClientBuilder::build`
  • Loading branch information
yukibtc committed Jan 22, 2024
1 parent 4a4440d commit d8f762e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions bindings/nostr-sdk-ffi/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ impl ClientBuilder {
/// Set opts
pub fn opts(self: Arc<Self>, opts: Arc<Options>) -> Self {
let mut builder = unwrap_or_clone_arc(self);
builder.inner = builder
.inner
.opts(opts.as_ref().deref().clone().shutdown_on_drop(true));
builder.inner = builder.inner.opts(opts.as_ref().deref().clone());
builder
}

/// Build [`Client`]
pub fn build(&self) -> Arc<Client> {
Arc::new(ClientSdk::from_builder(self.inner.clone()).into())
let mut inner = self.inner.clone();
inner.opts = inner.opts.shutdown_on_drop(true);
Arc::new(ClientSdk::from_builder(inner).into())
}
}
19 changes: 11 additions & 8 deletions bindings/nostr-sdk-ffi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use nostr_ffi::{
};
use nostr_sdk::client::blocking::Client as ClientSdk;
use nostr_sdk::relay::RelayPoolNotification as RelayPoolNotificationSdk;
use nostr_sdk::{NegentropyOptions, Options as OptionsSdk};
use nostr_sdk::NegentropyOptions;
use uniffi::Object;

mod builder;
Expand Down Expand Up @@ -47,14 +47,17 @@ impl Client {

#[uniffi::constructor]
pub fn with_opts(signer: Option<Arc<ClientSigner>>, opts: Arc<Options>) -> Self {
let opts: OptionsSdk = opts.as_ref().deref().clone().shutdown_on_drop(true);
let mut builder = nostr_sdk::ClientBuilder::new().opts(opts);
if let Some(signer) = signer {
let signer: nostr_sdk::ClientSigner = signer.as_ref().deref().clone();
builder = builder.signer(signer);
}
Self {
inner: builder.build().into(),
inner: match signer {
Some(signer) => ClientSdk::with_opts(
signer.as_ref().deref().clone(),
opts.as_ref().deref().clone(),
),
None => nostr_sdk::ClientBuilder::new()
.opts(opts.as_ref().deref().clone())
.build()
.into(),
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/nostr-sdk-ffi/src/client/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Options {
#[uniffi::constructor]
pub fn new() -> Self {
Self {
inner: nostr_sdk::Options::new(),
inner: nostr_sdk::Options::new().shutdown_on_drop(true),
}
}

Expand Down

0 comments on commit d8f762e

Please sign in to comment.