Skip to main content

AirLibrary/Client/AirClient/
CheckForUpdates.rs

1//! `AirClient::CheckForUpdates` - queries the Air daemon's
2//! `UpdateService` for available updates on the given channel.
3//!
4//! Maps the wire response into [`UpdateInfo::Struct`]. tonic transport /
5//! status failures surface as [`AirError::Network`].
6
7use tonic::Request;
8
9use crate::{
10	AirError,
11	Client::AirClient::{AirClient, UpdateInfo},
12	Vine::Generated::air::UpdateCheckRequest,
13	dev_log,
14};
15
16impl AirClient {
17	/// Checks for available updates.
18	///
19	/// # Arguments
20	///
21	/// - `request_id` - opaque correlation id.
22	/// - `current_version` - the currently-running application version.
23	/// - `channel` - update channel (`"stable"`, `"beta"`, `"nightly"`).
24	pub async fn CheckForUpdates(
25		&self,
26
27		request_id:String,
28
29		current_version:String,
30
31		channel:String,
32	) -> Result<UpdateInfo::Struct, AirError> {
33		dev_log!("grpc", "[AirClient] Checking for updates for version '{}'", current_version);
34
35		let RequestPayload = UpdateCheckRequest { request_id, current_version, channel };
36
37		let Client = self
38			.Client()
39			.ok_or_else(|| AirError::Network("Air client not initialized".to_string()))?;
40
41		let mut ClientGuard = Client.lock().await;
42
43		match ClientGuard.check_for_updates(Request::new(RequestPayload)).await {
44			Ok(Response) => {
45				let Response = Response.into_inner();
46
47				dev_log!(
48					"grpc",
49					"[AirClient] Update check completed. Update available: {}",
50					Response.update_available
51				);
52
53				Ok(UpdateInfo::Struct {
54					update_available:Response.update_available,
55					version:Response.version,
56					download_url:Response.download_url,
57					release_notes:Response.release_notes,
58				})
59			},
60
61			Err(Status) => {
62				dev_log!("grpc", "error: [AirClient] Check for updates RPC error: {}", Status);
63
64				Err(AirError::Network(format!("Check for updates RPC error: {}", Status)))
65			},
66		}
67	}
68}