Skip to content

Commit 048da10

Browse files
committed
chore: add some more docs
1 parent cef8df6 commit 048da10

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

crates/bitwarden-ipc/src/ipc_client.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use crate::{
1111
traits::{CommunicationBackend, CryptoProvider, SessionRepository},
1212
};
1313

14-
#[allow(missing_docs)]
14+
/// An IPC client that handles communication between different components and clients.
15+
/// It uses a crypto provider to encrypt and decrypt messages, a communication backend to send and
16+
/// receive messages, and a session repository to persist sessions.
1517
pub struct IpcClient<Crypto, Com, Ses>
1618
where
1719
Crypto: CryptoProvider<Com, Ses>,
@@ -96,7 +98,7 @@ where
9698
Com: CommunicationBackend,
9799
Ses: SessionRepository<Crypto::Session>,
98100
{
99-
#[allow(missing_docs)]
101+
/// Create a new IPC client with the provided crypto provider, communication backend, and session repository.
100102
pub fn new(crypto: Crypto, communication: Com, sessions: Ses) -> Arc<Self> {
101103
Arc::new(Self {
102104
crypto,
@@ -108,7 +110,11 @@ where
108110
})
109111
}
110112

111-
#[allow(missing_docs)]
113+
/// Start the IPC client, which will begin listening for incoming messages and processing them.
114+
/// This will be done in a separate task, allowing the client to receive messages asynchronously.
115+
/// The client will stop automatically if an error occurs during message processing or if the cancellation token is triggered.
116+
///
117+
/// Note: The client can and will send messages in the background while it is running, even if no active subscriptions are present.
112118
pub async fn start(self: &Arc<Self>) {
113119
let cancellation_token = CancellationToken::new();
114120
self.cancellation_token
@@ -156,14 +162,14 @@ where
156162
wasm_bindgen_futures::spawn_local(future);
157163
}
158164

159-
#[allow(missing_docs)]
165+
/// Check if the IPC client task is currently running.
160166
pub async fn is_running(self: &Arc<Self>) -> bool {
161167
let has_incoming = self.incoming.read().await.is_some();
162168
let has_cancellation_token = self.cancellation_token.read().await.is_some();
163169
has_incoming && has_cancellation_token
164170
}
165171

166-
#[allow(missing_docs)]
172+
/// Stop the IPC client task. This will stop listening for incoming messages.
167173
pub async fn stop(self: &Arc<Self>) {
168174
let mut incoming = self.incoming.write().await;
169175
let _ = incoming.take();

crates/bitwarden-ipc/src/wasm/communication_backend.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ export interface IpcCommunicationBackendSender {
3232

3333
#[wasm_bindgen]
3434
extern "C" {
35-
#[allow(missing_docs)]
35+
/// JavaScript interface for handling outgoing messages from the IPC framework.
3636
#[wasm_bindgen(js_name = IpcCommunicationBackendSender, typescript_type = "IpcCommunicationBackendSender")]
3737
pub type JsCommunicationBackendSender;
3838

39-
#[allow(missing_docs)]
39+
/// Used by the IPC framework to send an outgoing message.
4040
#[wasm_bindgen(catch, method, structural)]
4141
pub async fn send(
4242
this: &JsCommunicationBackendSender,
4343
message: OutgoingMessage,
4444
) -> Result<(), JsValue>;
4545

46-
#[allow(missing_docs)]
46+
/// Used by JavaScript to provide an incoming message to the IPC framework.
4747
#[wasm_bindgen(catch, method, structural)]
4848
pub async fn receive(this: &JsCommunicationBackendSender) -> Result<JsValue, JsValue>;
4949
}
5050

51-
#[allow(missing_docs)]
51+
/// JavaScript implementation of the `CommunicationBackend` trait for IPC communication.
5252
#[wasm_bindgen(js_name = IpcCommunicationBackend)]
5353
pub struct JsCommunicationBackend {
5454
sender: Arc<ThreadBoundRunner<JsCommunicationBackendSender>>,
@@ -68,7 +68,7 @@ impl Clone for JsCommunicationBackend {
6868

6969
#[wasm_bindgen(js_class = IpcCommunicationBackend)]
7070
impl JsCommunicationBackend {
71-
#[allow(missing_docs)]
71+
/// Creates a new instance of the JavaScript communication backend.
7272
#[wasm_bindgen(constructor)]
7373
pub fn new(sender: JsCommunicationBackendSender) -> Self {
7474
let (receive_tx, receive_rx) = tokio::sync::broadcast::channel(20);
@@ -79,8 +79,8 @@ impl JsCommunicationBackend {
7979
}
8080
}
8181

82-
/// JavaScript function to provide a received message to the backend/IPC framework.
83-
pub fn deliver_message(&self, message: IncomingMessage) -> Result<(), JsValue> {
82+
/// Used by JavaScript to provide an incoming message to the IPC framework.
83+
pub fn receive(&self, message: IncomingMessage) -> Result<(), JsValue> {
8484
self.receive_tx
8585
.send(message)
8686
.map_err(|e| ChannelError(e.to_string()))?;

crates/bitwarden-ipc/src/wasm/ipc_client.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::{
1111
IpcClient,
1212
};
1313

14-
#[allow(missing_docs)]
14+
/// JavaScript wrapper around the IPC client. For more information, see the
15+
/// [IpcClient] documentation.
1516
#[wasm_bindgen(js_name = IpcClient)]
1617
pub struct JsIpcClient {
1718
// TODO: Change session provider to a JS-implemented one
@@ -24,15 +25,16 @@ pub struct JsIpcClient {
2425
>,
2526
}
2627

27-
#[allow(missing_docs)]
28+
/// JavaScript wrapper around the IPC client subscription. For more information, see the
29+
/// [IpcClientSubscription] documentation.
2830
#[wasm_bindgen(js_name = IpcClientSubscription)]
2931
pub struct JsIpcClientSubscription {
3032
subscription: IpcClientSubscription,
3133
}
3234

33-
#[allow(missing_docs)]
3435
#[wasm_bindgen(js_class = IpcClientSubscription)]
3536
impl JsIpcClientSubscription {
37+
#[allow(missing_docs)]
3638
pub async fn receive(
3739
&mut self,
3840
abort_signal: Option<AbortSignal>,

0 commit comments

Comments
 (0)