Skip to main content

Mountain/IPC/WindAirCommands/
AirClientWrapper.rs

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