Skip to main content

AirLibrary/Updates/
Types.rs

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