From 1bbb5f934c4f89f49777375d077fa40d4b19866e Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Tue, 3 Nov 2026 19:34:00 -0300 Subject: [PATCH] fix(update): non-blocking desktop update with progress bar (1.0.7) 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 --- CHANGELOG.md | 8 +++++++ CHANGELOG.pt-BR.md | 8 +++++++ Cargo.lock | 4 ++-- Cargo.toml | 2 +- apps/gui/src-tauri/Cargo.lock | 4 ++-- apps/gui/src-tauri/Cargo.toml | 2 +- apps/gui/src-tauri/src/main.rs | 35 +++++++++++++++++++++++------- apps/gui/src-tauri/tauri.conf.json | 2 +- apps/gui/ui/app.css | 7 +++++- apps/gui/ui/app.js | 20 ++++++++++++++++- apps/gui/ui/i18n-en.js | 1 + crates/sabia-core/src/update.rs | 33 +++++++++++++++++++++++----- 12 files changed, 104 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdeb774..61a3fdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow SemVer. +## [1.0.7] - 2026-11-03 + +### Added +- **Update progress bar.** The in-app update shows a bar with the real download percentage, then the verify, install and restart steps. + +### Fixed +- **Updating no longer freezes the app.** The update check and install ran on the UI thread; they now run in the background. + ## [1.0.6] - 2026-11-03 ### Security diff --git a/CHANGELOG.pt-BR.md b/CHANGELOG.pt-BR.md index 21b704e..d5aef1b 100644 --- a/CHANGELOG.pt-BR.md +++ b/CHANGELOG.pt-BR.md @@ -4,6 +4,14 @@ Formato baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/); versões seguem SemVer. +## [1.0.7] - 2026-11-03 + +### Adicionado +- **Barra de progresso da atualização.** A atualização dentro do app mostra uma barra com a porcentagem real do download, seguida das etapas de verificação, instalação e reinício. + +### Corrigido +- **Atualizar não trava mais o app.** A verificação e a instalação rodavam na thread da interface; agora rodam em segundo plano. + ## [1.0.6] - 2026-11-03 ### Segurança diff --git a/Cargo.lock b/Cargo.lock index 4e515a6..2d3d304 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -440,7 +440,7 @@ dependencies = [ [[package]] name = "sabia-cli" -version = "1.0.6" +version = "1.0.7" dependencies = [ "clap", "ctrlc", @@ -452,7 +452,7 @@ dependencies = [ [[package]] name = "sabia-core" -version = "1.0.6" +version = "1.0.7" dependencies = [ "aes", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 94ac721..12ab677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/sabia-core", "crates/sabia-cli"] [workspace.package] -version = "1.0.6" +version = "1.0.7" edition = "2021" license = "MIT OR Apache-2.0" repository = "https://git.lucasrguerra.dev.br/ciberfauna/sabia" diff --git a/apps/gui/src-tauri/Cargo.lock b/apps/gui/src-tauri/Cargo.lock index e57eccf..cb0e78a 100644 --- a/apps/gui/src-tauri/Cargo.lock +++ b/apps/gui/src-tauri/Cargo.lock @@ -2538,7 +2538,7 @@ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" [[package]] name = "sabia-core" -version = "1.0.6" +version = "1.0.7" dependencies = [ "aes", "flate2", @@ -2555,7 +2555,7 @@ dependencies = [ [[package]] name = "sabia-gui" -version = "1.0.6" +version = "1.0.7" dependencies = [ "libc", "sabia-core", diff --git a/apps/gui/src-tauri/Cargo.toml b/apps/gui/src-tauri/Cargo.toml index 175b42b..4bd0057 100644 --- a/apps/gui/src-tauri/Cargo.toml +++ b/apps/gui/src-tauri/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "sabia-gui" description = "Sabiá: graphical Wi-Fi security auditing interface" -version = "1.0.6" +version = "1.0.7" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Sabiá contributors"] diff --git a/apps/gui/src-tauri/src/main.rs b/apps/gui/src-tauri/src/main.rs index 3134c49..09a6b36 100644 --- a/apps/gui/src-tauri/src/main.rs +++ b/apps/gui/src-tauri/src/main.rs @@ -496,25 +496,44 @@ fn start_scan_opts( } #[tauri::command] -fn update_check(state: tauri::State<'_, State>) -> Result { - let status = state.0.update_check().map_err(|e| e.to_string())?; - serde_json::to_value(status).map_err(|e| e.to_string()) +async fn update_check(state: tauri::State<'_, State>) -> Result { + let eng = state.0.clone(); + tauri::async_runtime::spawn_blocking(move || { + let status = eng.update_check().map_err(|e| e.to_string())?; + serde_json::to_value(status).map_err(|e| e.to_string()) + }) + .await + .map_err(|e| e.to_string())? } #[tauri::command] -fn update_apply(app: tauri::AppHandle, state: tauri::State<'_, State>) -> Result { +async fn update_apply( + app: tauri::AppHandle, + state: tauri::State<'_, State>, +) -> Result { use tauri::Emitter; #[cfg(any(target_os = "linux", target_os = "macos"))] let exe = elevated_exe().unwrap_or_else(|_| std::env::current_exe().unwrap_or_default()); #[cfg(not(any(target_os = "linux", target_os = "macos")))] let exe = std::env::current_exe().unwrap_or_default(); - state - .0 - .update_apply_desktop(&exe, move |phase| { - let _ = app.emit("update-progress", serde_json::json!({ "phase": phase })); + // Blocking download/install must not run on the UI thread, or the window freezes. + let eng = state.0.clone(); + tauri::async_runtime::spawn_blocking(move || { + eng.update_apply_desktop(&exe, move |phase| { + let (name, pct) = match phase.split_once(':') { + Some((n, p)) => (n, p.parse::().ok()), + None => (phase, None), + }; + let _ = app.emit( + "update-progress", + serde_json::json!({ "phase": name, "percent": pct }), + ); }) .map_err(|e| e.to_string()) + }) + .await + .map_err(|e| e.to_string())? } /// `true` when the process already has sufficient privileges for all diff --git a/apps/gui/src-tauri/tauri.conf.json b/apps/gui/src-tauri/tauri.conf.json index 7a6f63b..92fdd59 100644 --- a/apps/gui/src-tauri/tauri.conf.json +++ b/apps/gui/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Sabiá", - "version": "1.0.6", + "version": "1.0.7", "identifier": "dev.sabia.app", "build": { "frontendDist": "../ui" diff --git a/apps/gui/ui/app.css b/apps/gui/ui/app.css index ab9ea22..9ada3c1 100644 --- a/apps/gui/ui/app.css +++ b/apps/gui/ui/app.css @@ -116,7 +116,7 @@ code, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; } .iface-pick .pill { align-self: flex-start; } .side-foot { margin-top: auto; padding: 14px 4px 4px; font-size: 11.5px; color: var(--text-3); display: grid; gap: 8px; } -.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; } +.foot-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; } .side-foot button { background: transparent; border: 0; color: var(--text-3); cursor: pointer; } .side-foot .foot-row > button:not(.icon-btn) { text-decoration: underline; text-underline-offset: 2px; } .side-foot button:hover { color: var(--text-2); } @@ -457,3 +457,8 @@ dialog menu { display: flex; gap: 10px; justify-content: flex-end; padding: 0; m .report-dlg { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; } .report-view { padding: 8px; } } + +.upd-bar { flex-basis: 100%; height: 6px; border-radius: 99px; margin-top: 8px; overflow: hidden; background: color-mix(in srgb, currentColor 12%, transparent); } +.upd-bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent, currentColor); transition: width .3s ease; } +.upd-bar.indet > i { animation: upd-slide 1.2s infinite ease-in-out; } +@keyframes upd-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } } diff --git a/apps/gui/ui/app.js b/apps/gui/ui/app.js index 9c44375..bcbda97 100644 --- a/apps/gui/ui/app.js +++ b/apps/gui/ui/app.js @@ -376,19 +376,36 @@ els.btnScan.addEventListener('click', async () => { let updateStatus = null; let updateInProgress = false; +// Progress bar under the update button (indeterminate until a percentage arrives). +function setUpdBar(pct) { + const row = els.btnUpdate.parentElement; + let bar = row.querySelector('.upd-bar'); + if (!bar) { + bar = document.createElement('div'); + bar.className = 'upd-bar'; + bar.innerHTML = ''; + row.appendChild(bar); + } + bar.classList.toggle('indet', pct == null); + bar.firstChild.style.width = pct == null ? '35%' : `${pct}%`; +} + els.btnUpdate.addEventListener('click', async () => { if (updateInProgress) return; if (updateStatus?.update_available) { updateInProgress = true; els.btnUpdate.disabled = true; els.btnUpdate.textContent = 'baixando…'; + setUpdBar(null); let unlisten = null; if (tauri?.event?.listen) { try { unlisten = await tauri.event.listen('update-progress', (event) => { const phase = event.payload?.phase; - if (phase === 'downloading') els.btnUpdate.textContent = 'baixando…'; + const pct = event.payload?.percent; + setUpdBar(pct); + if (phase === 'downloading') els.btnUpdate.textContent = pct != null ? `baixando… ${pct}%` : 'baixando…'; else if (phase === 'verifying') els.btnUpdate.textContent = 'verificando…'; else if (phase === 'installing') els.btnUpdate.textContent = 'instalando…'; else if (phase === 'restarting') els.btnUpdate.textContent = 'reiniciando…'; @@ -401,6 +418,7 @@ els.btnUpdate.addEventListener('click', async () => { els.btnUpdate.textContent = 'já atualizado'; } catch (err) { updateInProgress = false; + els.btnUpdate.parentElement.querySelector('.upd-bar')?.remove(); els.btnUpdate.disabled = false; els.btnUpdate.textContent = `atualizar para ${updateStatus.latest_version}`; alert('Falha na atualização: ' + (err?.message || err)); diff --git a/apps/gui/ui/i18n-en.js b/apps/gui/ui/i18n-en.js index 57d4dbd..36d0b5e 100644 --- a/apps/gui/ui/i18n-en.js +++ b/apps/gui/ui/i18n-en.js @@ -570,4 +570,5 @@ export const EN = { 'a captura em {n} não está ativa': 'capture on {n} is not active', '{n} não está disponível; o reaver integrado não pôde ser extraído': '{n} is not available; the bundled reaver could not be extracted', + 'baixando… {n}%': 'downloading… {n}%', }; diff --git a/crates/sabia-core/src/update.rs b/crates/sabia-core/src/update.rs index 7e96b0e..866406e 100644 --- a/crates/sabia-core/src/update.rs +++ b/crates/sabia-core/src/update.rs @@ -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 { 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 { 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");