Skip to main content

AirLibrary/Updates/
Types.rs

1//! Value types for the update lifecycle: channels, status, installation
2//! states, update manifests, platform metadata, and telemetry records.
3//!
4//! These structs are shared between `UpdateManager` methods, IPC handlers
5//! (Mountain ↔ Air), and the test suite. Keeping them in one file makes the
6//! shape of the update domain legible without reading the 2600-line
7//! implementation.
8
9use std::{collections::HashMap, path::PathBuf};
10
11use serde::{Deserialize, Serialize};
12
13/// Update distribution channel.
14#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
15pub enum UpdateChannel {
16	Stable,
17
18	Insiders,
19
20	Preview,
21}
22
23impl UpdateChannel {
24	pub fn as_str(&self) -> &'static str {
25		match self {
26			UpdateChannel::Stable => "stable",
27
28			UpdateChannel::Insiders => "insiders",
29
30			UpdateChannel::Preview => "preview",
31		}
32	}
33}
34
35/// Supported OS package formats.
36#[derive(Debug, Clone, Copy)]
37pub enum PackageFormat {
38	WindowsExe,
39
40	MacOsDmg,
41
42	LinuxAppImage,
43
44	LinuxDeb,
45
46	LinuxRpm,
47}
48
49/// Snapshot of a rollback point created before applying an update.
50#[derive(Debug, Clone)]
51pub struct RollbackState {
52	pub version:String,
53
54	pub backup_path:PathBuf,
55
56	pub timestamp:chrono::DateTime<chrono::Utc>,
57
58	pub checksum:String,
59}
60
61/// Fine-grained installation lifecycle state.
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
63pub enum InstallationStatus {
64	NotStarted,
65
66	CheckingPrerequisites,
67
68	Downloading,
69
70	Paused,
71
72	VerifyingSignature,
73
74	VerifyingChecksums,
75
76	Staging,
77
78	CreatingBackup,
79
80	Installing,
81
82	Completed,
83
84	RollingBack,
85
86	Failed(String),
87}
88
89impl InstallationStatus {
90	pub fn is_cancellable(&self) -> bool {
91		matches!(
92			self,
93			InstallationStatus::Downloading
94				| InstallationStatus::Paused
95				| InstallationStatus::Staging
96				| InstallationStatus::NotStarted
97		)
98	}
99
100	pub fn is_error(&self) -> bool { matches!(self, InstallationStatus::Failed(_)) }
101
102	pub fn is_in_progress(&self) -> bool {
103		matches!(
104			self,
105			InstallationStatus::CheckingPrerequisites
106				| InstallationStatus::Downloading
107				| InstallationStatus::VerifyingSignature
108				| InstallationStatus::VerifyingChecksums
109				| InstallationStatus::Staging
110				| InstallationStatus::CreatingBackup
111				| InstallationStatus::Installing
112		)
113	}
114}
115
116/// Live status snapshot surfaced to Mountain and IPC callers.
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct UpdateStatus {
119	pub last_check:Option<chrono::DateTime<chrono::Utc>>,
120
121	pub update_available:bool,
122
123	pub current_version:String,
124
125	pub available_version:Option<String>,
126
127	pub download_progress:Option<f32>,
128
129	pub installation_status:InstallationStatus,
130
131	pub update_channel:UpdateChannel,
132
133	pub update_size:Option<u64>,
134
135	pub release_notes:Option<String>,
136
137	pub requires_restart:bool,
138
139	pub download_speed:Option<f64>,
140
141	pub eta_seconds:Option<u64>,
142
143	pub last_error:Option<String>,
144}
145
146/// Manifest returned by the update server for an available release.
147#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct UpdateInfo {
149	pub version:String,
150
151	pub download_url:String,
152
153	pub release_notes:String,
154
155	pub checksum:String,
156
157	pub checksums:HashMap<String, String>,
158
159	pub size:u64,
160
161	pub published_at:chrono::DateTime<chrono::Utc>,
162
163	pub is_mandatory:bool,
164
165	pub requires_restart:bool,
166
167	pub min_compatible_version:Option<String>,
168
169	pub delta_url:Option<String>,
170
171	pub delta_checksum:Option<String>,
172
173	pub delta_size:Option<u64>,
174
175	pub signature:Option<String>,
176
177	pub platform_metadata:Option<PlatformMetadata>,
178}
179
180/// Platform-specific fields inside an `UpdateInfo`.
181#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct PlatformMetadata {
183	pub package_format:String,
184
185	pub install_instructions:Vec<String>,
186
187	pub required_disk_space:u64,
188
189	pub requires_admin:bool,
190
191	pub additional_params:HashMap<String, serde_json::Value>,
192}
193
194/// Analytics record emitted after every update operation.
195#[derive(Debug, Clone, Serialize, Deserialize)]
196pub struct UpdateTelemetry {
197	pub event_id:String,
198
199	pub current_version:String,
200
201	pub target_version:String,
202
203	pub channel:String,
204
205	pub platform:String,
206
207	pub operation:String,
208
209	pub success:bool,
210
211	pub duration_ms:u64,
212
213	pub download_size:Option<u64>,
214
215	pub error_message:Option<String>,
216
217	pub timestamp:chrono::DateTime<chrono::Utc>,
218}