Skip to main content

Mountain/IPC/WindAirCommands/
AirClientWrapper.rs

1
2//! gRPC client wrapper around `Air::AirClient::AirClient` -
3//! adds reconnect support and PascalCase logging consistent
4//! with the WindAirCommands surface.
5
6use crate::{Air::AirClient as AirClientModule, dev_log};
7
8#[derive(Debug, Clone)]
9pub struct Struct {
10	pub(super) client:AirClientModule::AirClient,
11}
12
13impl Struct {
14	pub async fn new(address:String) -> Result<Self, String> {
15		dev_log!("grpc", "[WindAirCommands] Connecting to Air daemon at: {}", address);
16
17		let client = AirClientModule::AirClient::new(&address)
18			.await
19			.map_err(|e| format!("Failed to connect to Air daemon: {:?}", e))?;
20
21		dev_log!("grpc", "[WindAirCommands] Successfully connected to Air daemon");
22
23		Ok(Self { client })
24	}
25
26	pub async fn reconnect(&mut self, address:String) -> Result<(), String> {
27		dev_log!("grpc", "[WindAirCommands] Reconnecting to Air daemon at: {}", address);
28
29		let client = AirClientModule::AirClient::new(&address)
30			.await
31			.map_err(|e| format!("Failed to reconnect to Air daemon: {:?}", e))?;
32
33		self.client = client;
34
35		dev_log!("grpc", "[WindAirCommands] Successfully reconnected to Air daemon");
36
37		Ok(())
38	}
39}