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
16	channel:Option<String>,
17) -> Result<UpdateInfoDTO::Struct, String> {
18	dev_log!(
19		"grpc",
20		"[WindAirCommands] CheckForUpdates called with version: {:?}, channel: {:?}",
21		current_version,
22		channel
23	);
24
25	let air_address = GetAirAddress::Fn()?;
26
27	let client = GetOrCreateAirClient::Fn(air_address).await?;
28
29	let request_id = uuid::Uuid::new_v4().to_string();
30
31	let current_version = current_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string());
32
33	let channel = channel.unwrap_or_else(|| "stable".to_string());
34
35	let update_info = client
36		.check_for_updates(request_id, current_version, channel)
37		.await
38		.map_err(|e| format!("Update check failed: {:?}", e))?;
39
40	let result = UpdateInfoDTO::Struct {
41		update_available:update_info.update_available,
42
43		version:update_info.version,
44
45		download_url:update_info.download_url,
46
47		release_notes:update_info.release_notes,
48	};
49
50	dev_log!(
51		"grpc",
52		"[WindAirCommands] Update check completed: available={}",
53		result.update_available
54	);
55
56	Ok(result)
57}