Skip to main content

kimun_notes/update/
provider.rs

1//! Provider-agnostic release model and the [`ReleaseProvider`] trait.
2//!
3//! The self-updater talks to a release backend only through this trait. To use
4//! a different source (GitLab, a self-hosted index, a mirror), implement
5//! `ReleaseProvider` and swap the constructor in [`super::provider`]. Everything
6//! downstream (status computation, download, checksum, swap) is backend-neutral
7//! — it only consumes [`LatestRelease`]/[`Asset`] and their plain URLs.
8
9use super::UpdateError;
10
11/// A single downloadable release artifact (binary, archive, or checksums file).
12#[derive(Debug, Clone)]
13pub struct Asset {
14    /// Asset filename, e.g. `kimun-0.18.0-linux-x64`.
15    pub name: String,
16    /// Direct download URL.
17    pub url: String,
18}
19
20/// The newest stable app release and everything needed to download it.
21#[derive(Debug, Clone)]
22pub struct LatestRelease {
23    /// Version without any tag prefix, e.g. `0.18.0`.
24    pub version: String,
25    /// Downloadable assets (raw binaries, archives, checksums).
26    pub assets: Vec<Asset>,
27}
28
29impl LatestRelease {
30    /// Find an asset by exact name.
31    pub fn asset(&self, name: &str) -> Option<&Asset> {
32        self.assets.iter().find(|a| a.name == name)
33    }
34}
35
36/// Source of release information for the self-updater. Implement this and swap
37/// the constructor in [`super::provider`] to change backends without touching
38/// any caller.
39pub trait ReleaseProvider {
40    /// The newest stable release for this app, with its downloadable assets.
41    /// Blocking — callers run it on the blocking pool.
42    fn latest_stable(&self) -> Result<LatestRelease, UpdateError>;
43
44    /// Human-facing page listing releases, shown when self-update isn't
45    /// available on the current install channel.
46    fn releases_url(&self) -> &'static str;
47}