use serde::{Deserialize, Serialize};
use super::RemoteActionTarget;
use crate::api::ActionAddress;
pub const PROVIDER: &str = "tilo.downloaded-apps";
pub const RESOURCE: &str = "downloaded-apps";
pub const ADD: &str = "add";
pub const DECLINE: &str = "decline";
pub const LOCATE: &str = "locate";
pub const REMOVE: &str = "remove";
pub const UNINSTALL: &str = "uninstall";
pub const FILE_PARAM: &str = "file";
pub const MOVE_PARAM: &str = "move_to_applications";
pub const PATH_PARAM: &str = "path";
pub const APP_PREFIX: &str = "downloaded-app:";
#[must_use]
pub fn app(desktop_id: &str) -> String {
format!("{APP_PREFIX}{desktop_id}")
}
#[must_use]
pub fn target(step: &str) -> RemoteActionTarget {
RemoteActionTarget {
provider: PROVIDER.to_owned(),
address: ActionAddress::new(RESOURCE, step),
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum DownloadedKind {
AppImage,
Program,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct DownloadedApp {
pub desktop_id: String,
pub name: String,
pub kind: DownloadedKind,
pub file: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub copies: Vec<String>,
pub present: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub artwork: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub comment: Option<String>,
pub launch: String,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct DownloadedOffer {
pub file: String,
pub name: String,
pub kind: DownloadedKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub artwork: Option<String>,
#[serde(default, skip_serializing_if = "is_false")]
pub declined: bool,
}
#[expect(
clippy::trivially_copy_pass_by_ref,
reason = "serde's skip_serializing_if passes the field by reference"
)]
fn is_false(value: &bool) -> bool {
!*value
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum DownloadedDoing {
Add,
Locate,
Remove,
Uninstall,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct DownloadedFailure {
pub attempt: u64,
pub doing: DownloadedDoing,
pub subject: String,
pub name: String,
pub detail: String,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct DownloadedApps {
#[serde(default)]
pub apps: Vec<DownloadedApp>,
#[serde(default)]
pub offers: Vec<DownloadedOffer>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub failures: Vec<DownloadedFailure>,
}