fix(update): non-blocking desktop update with progress bar (1.0.7)
Release / Create release (push) Successful in 13s
CI / Format and clippy (push) Successful in 28s
CI / Tests (Linux) (push) Successful in 29s
CI / Dependency audit (push) Successful in 14s
Release / CLI (linux-aarch64) (push) Successful in 53s
Release / CLI (linux-x86_64) (push) Successful in 1m22s
CI / Check desktop app (Linux) (push) Successful in 1m19s
Release / Desktop app (linux-aarch64) (push) Successful in 4m27s
Release / Desktop app (linux-x86_64) (push) Successful in 4m58s
Release / Desktop app (windows) (push) Successful in 3m27s

Update commands ran on the UI thread and froze the window; they now run
in the background, with a real download percentage bar.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Sonnet 5.5 committed 2026-11-03 19:34:00 -03:00
1 parent fd7435cc68
commit 1bbb5f934c
12 files changed
+104 -22

No files matched your search

+28 -5
View File
@@ -30,6 +30,8 @@ struct Release {
struct Asset {
name: String,
browser_download_url: String,
#[serde(default)]
size: u64,
}
#[derive(Debug, Clone, serde::Serialize)]
@@ -56,16 +58,32 @@ fn curl_text(url: &str) -> Result<String> {
Ok(String::from_utf8_lossy(&out.stdout).into_owned())
}
fn curl_download(url: &str, dest: &Path) -> Result<()> {
let status = Command::new("curl")
/// Downloads `url` to `dest`, polling the file size to report a percentage (0-100)
/// through `on_pct` while curl runs; `total` is the release asset size (0 = unknown).
fn curl_download(url: &str, dest: &Path, total: u64, on_pct: &dyn Fn(u8)) -> Result<()> {
let mut child = Command::new("curl")
.args(["-fsSL", "-H", "User-Agent: sabia-updater", "-o"])
.arg(dest)
.arg(url)
.status()
.spawn()
.map_err(|e| SabiaError::CommandFailed {
cmd: format!("curl {url}"),
detail: e.to_string(),
})?;
let status = loop {
let waited = child.try_wait().map_err(|e| SabiaError::CommandFailed {
cmd: format!("curl {url}"),
detail: e.to_string(),
})?;
if let Some(st) = waited {
break st;
}
let got = fs::metadata(dest).map(|m| m.len()).unwrap_or(0);
if let Some(pct) = got.saturating_mul(100).checked_div(total) {
on_pct(pct.min(100) as u8);
}
std::thread::sleep(std::time::Duration::from_millis(150));
};
if !status.success() {
return Err(SabiaError::CommandFailed {
cmd: format!("curl {url}"),
@@ -162,7 +180,7 @@ pub fn apply(current_exe: &PathBuf) -> Result<String> {
let tmp_dir = std::env::temp_dir().join("sabia-update");
fs::create_dir_all(&tmp_dir)?;
let archive_path = tmp_dir.join(&asset.name);
curl_download(&asset.browser_download_url, &archive_path)?;
curl_download(&asset.browser_download_url, &archive_path, 0, &|_| {})?;
if let Some(checksum_asset) = checksum_asset {
let expected = curl_text(&checksum_asset.browser_download_url)?;
@@ -380,7 +398,12 @@ where
let download_path = tmp_dir.join(&asset.name);
on_progress("downloading");
curl_download(&asset.browser_download_url, &download_path)?;
curl_download(
&asset.browser_download_url,
&download_path,
asset.size,
&|pct| on_progress(&format!("downloading:{pct}")),
)?;
if let Some(checksum_asset) = checksum_asset {
on_progress("verifying");