use crate::{Error, Result};
use semver::Version;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UpdateChannel {
Stable,
Beta,
Nightly,
}
impl std::str::FromStr for UpdateChannel {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s.to_lowercase().as_str() {
"stable" => Ok(Self::Stable),
"beta" => Ok(Self::Beta),
"nightly" => Ok(Self::Nightly),
_ => Err(Error::config(format!("Invalid update channel: {}", s))),
}
}
}
impl std::fmt::Display for UpdateChannel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Stable => write!(f, "stable"),
Self::Beta => write!(f, "beta"),
Self::Nightly => write!(f, "nightly"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateInfo {
pub version: Version,
pub download_url: String,
pub size: u64,
pub sha256: Option<String>,
pub notes: String,
pub critical: bool,
}
#[derive(Debug)]
pub struct UpdateManager {
pub current_version: Version,
pub channel: UpdateChannel,
pub binary_path: PathBuf,
}