pub struct Updater {
pub client: Client,
pub owner: String,
pub name: String,
pub version: String,
pub latest_version: Option<String>,
pub download_url: Option<String>,
/* private fields */
}Expand description
The update workflow: check the latest tag, download the platform asset,
swap the binary keeping the old one as .bak.
Fields§
§client: Client§owner: StringRepository owner, from build-time metadata.
name: StringRepository/app name, from build-time metadata.
version: StringVersion of the running binary.
latest_version: Option<String>Newer version found by the check, if any.
download_url: Option<String>Asset URL for this platform, set when a newer version is found.
Implementations§
Source§impl Updater
impl Updater
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Builds an updater from build-time metadata.
use kasl::libs::update::Updater;
let updater = Updater::new()?;
println!("Updater configured for {} v{}", updater.name, updater.version);Sourcepub async fn show_update_notification()
pub async fn show_update_notification()
Prints an update notice when one is available - throttled to one check per day, and silent on any failure, so startup never blocks or complains because of the network.
use kasl::libs::update::Updater;
// Call during application startup
Updater::show_update_notification().await;Sourcepub async fn perform_update(&self) -> Result<()>
pub async fn perform_update(&self) -> Result<()>
Downloads the release archive and swaps the binary in.
Requires a prior successful Updater::check_for_latest_release
(it sets download_url). The old executable stays next to the new
one as .bak - restoring it is a manual copy, nothing automatic.
use kasl::libs::update::Updater;
let mut updater = Updater::new()?;
if updater.check_for_latest_release().await? {
updater.perform_update().await?;
println!("Update completed successfully");
}Sourcepub async fn check_for_latest_release(&mut self) -> Result<bool>
pub async fn check_for_latest_release(&mut self) -> Result<bool>
Compares the latest published tag against the running version; on a newer one, stores it and the platform asset URL.
use kasl::libs::update::Updater;
let mut updater = Updater::new()?;
if updater.check_for_latest_release().await? {
println!("Update available: {} -> {}",
updater.version,
updater.latest_version.unwrap());
}