1#![allow(
2 dead_code,
3 unused_imports,
4 non_local_definitions,
5 reason = "Conditional compilation"
6)]
7
8use serde::{Deserialize, Serialize};
19use serde_json::{from_str, to_string, to_string_pretty};
20use std::{borrow::Cow, fs::read, sync::Arc};
21use tokio::task::JoinHandle;
22
23pub type AppId = String;
24pub type Str = String;
25pub type AppData = (String, String);
26pub type RefId = u64;
27
28pub type Success = bool;
29
30pub mod app;
31pub use app::*;
32
33pub mod api;
34pub use api::*;
35
36pub mod data;
37pub use data::*;
38
39pub mod winget;
40
41#[cfg_attr(feature = "export", derive(specta::Type))]
42#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
43#[derive(Debug, Serialize)]
44pub struct StatusUpdateData {
45 #[cfg(not(feature = "export"))]
46 pub queue: Box<[QueuedAppData]>,
47 #[cfg(feature = "export")]
48 pub queue: Vec<QueuedAppData>,
49 #[serde(rename = "supportsUpdate")]
50 pub disable_update: bool,
51 #[serde(rename = "queueOverflow")]
52 pub overflow: bool,
53}
54
55#[cfg_attr(feature = "export", derive(specta::Type))]
56#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
57#[derive(Debug, Serialize, Clone)]
58pub enum AppActionIntent {
59 Install,
60 Uninstall,
61 Update,
62}
63
64#[cfg_attr(feature = "export", derive(specta::Type))]
65#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
66#[derive(Debug, Serialize, Clone)]
67pub struct QueuedAppData {
68 #[cfg(not(feature = "export"))]
69 pub id: Arc<str>,
70 #[cfg(feature = "export")]
71 pub id: String,
72 #[cfg_attr(feature = "export", specta(type = u32))]
73 pub transaction: u64,
74 pub status: AppUpdateInstallStatus,
75 pub intent: AppActionIntent,
76}
77
78impl QueuedAppData {
79 pub fn from(data: &QueuedApp) -> Self {
80 Self {
81 id: data.id.clone(),
82 transaction: data.transaction,
83 intent: data.intent.clone(),
84 status: data.status.clone(),
85 }
86 }
87}
88
89#[derive(Debug, Serialize)]
90pub struct QueuedAppUpdate {
91 pub transaction: u64,
92 pub status: AppUpdateInstallStatus,
93}
94
95#[derive(Debug, Serialize)]
96pub struct QueuedApp {
97 #[cfg(not(feature = "export"))]
98 pub id: Arc<str>,
99 #[cfg(feature = "export")]
100 pub id: String,
101 pub transaction: u64,
102 pub status: AppUpdateInstallStatus,
103 pub intent: AppActionIntent,
104 #[serde(skip)]
105 pub task: Option<JoinHandle<()>>,
106}
107
108#[cfg_attr(feature = "export", derive(specta::Type))]
109#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
110#[derive(Debug, Serialize, Clone)]
111#[serde(tag = "status")]
112pub enum AppUpdateInstallStatus {
113 Pending,
115 PendingUserAction,
117 Cancelled {
119 #[serde(skip)]
121 time: u64,
122 },
123 Downloading { progress: f64 },
125 AVScanning,
127 PendingInstall,
129 Installing { progress: Option<f64> },
135 MoreDwnlNeeded {
137 progress: f64,
139 current: usize,
140 items: usize,
141 },
142 CopyingFiles { percentage: f64, total: usize },
144 Finalizing,
146 Updating,
148 Uninstalling,
150 Successful {
152 #[serde(skip)]
154 time: u64,
155 },
156 Error {
158 err: Cow<'static, str>,
159 #[serde(skip)]
161 time: u64,
162 },
163}
164
165#[cfg(test)]
166mod tests {
167 #[test]
168 #[cfg(feature = "export")]
169 fn export() {
170 let export =
172 specta::ts::ExportConfiguration::new().bigint(specta::ts::BigIntExportBehavior::Number);
173
174 _ = specta::export::ts_with_cfg("./pkg/ahqstore.types.d.ts", &export).unwrap();
175 _ = specta::export::ts_with_cfg("./types/ahqstore.types.d.ts", &export).unwrap();
176 }
177}