use std::sync::mpsc::Receiver; use anyhow::{Context, Result}; use self_update::{cargo_crate_version, update::Release}; use crate::{ jobs::{start_job, update_status, Job, JobContext, JobResult, JobState}, update::{build_updater, BIN_NAME_NEW, BIN_NAME_OLD}, }; pub struct CheckUpdateResult { pub update_available: bool, pub latest_release: Release, pub found_binary: Option, } fn run_check_update(context: &JobContext, cancel: Receiver<()>) -> Result> { update_status(context, "Fetching latest release".to_string(), 0, 1, &cancel)?; let updater = build_updater().context("Failed to create release updater")?; let latest_release = updater.get_latest_release()?; let update_available = self_update::version::bump_is_greater(cargo_crate_version!(), &latest_release.version)?; // Find the binary name in the release assets let found_binary = latest_release .assets .iter() .find(|a| a.name == BIN_NAME_NEW) .or_else(|| latest_release.assets.iter().find(|a| a.name == BIN_NAME_OLD)) .map(|a| a.name.clone()); update_status(context, "Complete".to_string(), 1, 1, &cancel)?; Ok(Box::new(CheckUpdateResult { update_available, latest_release, found_binary })) } pub fn start_check_update(ctx: &egui::Context) -> JobState { start_job(ctx, "Check for updates", Job::CheckUpdate, move |context, cancel| { run_check_update(&context, cancel).map(|result| JobResult::CheckUpdate(Some(result))) }) }