Skip to main content

Mountain/IPC/WindAirCommands/
CheckForUpdates.rs

1#![allow(non_snake_case)]
2
3//! `CheckForUpdates` Tauri command - delegate the update probe
4//! to Air's gRPC service and shape the response into
5//! `UpdateInfoDTO::Struct`.
6
7use crate::{
8	IPC::WindAirCommands::{GetAirAddress, GetOrCreateAirClient, UpdateInfoDTO},
9	dev_log,
10};
11
12#[tauri::command]
13pub async fn CheckForUpdates(
14	current_version:Option<String>,
15	channel:Option<String>,
16) -> Result<UpdateInfoDTO::Struct, String> {
17	dev_log!(
18		"grpc",
19		"[WindAirCommands] CheckForUpdates called with version: {:?}, channel: {:?}",
20		current_version,
21		channel
22	);
23
24	let air_address = GetAirAddress::Fn()?;
25	let client = GetOrCreateAirClient::Fn(air_address).await?;
26
27	let request_id = uuid::Uuid::new_v4().to_string();
28	let current_version = current_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
29	let channel = channel.unwrap_or_else(|| "stable".to_string());
30
31	let update_info = client
32		.check_for_updates(request_id, current_version, channel)
33		.await
34		.map_err(|e| format!("Update check failed: {:?}", e))?;
35
36	let result = UpdateInfoDTO::Struct {
37		update_available:update_info.update_available,
38		version:update_info.version,
39		download_url:update_info.download_url,
40		release_notes:update_info.release_notes,
41	};
42
43	dev_log!(
44		"grpc",
45		"[WindAirCommands] Update check completed: available={}",
46		result.update_available
47	);
48	Ok(result)
49}