From 0b9a16e8a0d10bc54f467f0324620d0795873dd0 Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Tue, 3 Nov 2026 16:36:34 -0300 Subject: [PATCH] feat: responsive pause/stop, non-blocking update with progress bar, delete saved sessions (1.5.0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - carve: check cancellation inside chunks and per hit; reassembly stage is cancellable - status exposes `stopping`; UI shows "Pausing…" immediately - Tauri update commands run off the UI thread; download percentage reported - delete autosaved sessions manually (one/all) and by retention setting - chore(release): 1.5.0 Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 10 +++++ CHANGELOG.pt-BR.md | 10 +++++ 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 | 32 +++++++++---- apps/gui/src-tauri/tauri.conf.json | 2 +- apps/gui/ui/app.css | 5 +++ apps/gui/ui/app.js | 60 ++++++++++++++++++++----- apps/gui/ui/i18n-en.js | 16 +++++++ apps/gui/ui/index.html | 2 +- crates/guara-core/src/carve.rs | 16 +++++++ crates/guara-core/src/scan.rs | 14 +++++- crates/guara-core/src/service.rs | 72 ++++++++++++++++++++++++++++++ crates/guara-core/src/settings.rs | 4 ++ crates/guara-core/src/update.rs | 29 +++++++++--- crates/guara-core/tests/extras.rs | 1 + docs/interface.md | 6 ++- docs/pt-BR/interface.md | 6 ++- 20 files changed, 262 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97ecef4..0e3f21b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow SemVer. +## [1.5.0] - 2026-11-03 + +### Added +- **Update progress bar.** The in-app update shows a real download percentage bar followed by the verify/install/restart phases. +- **Delete saved sessions.** Each autosaved session in the sidebar has a delete button, plus a "delete all" button. Settings gained "Delete autosaved sessions after" (never, 7, 30 or 90 days), applied on startup. Sessions open in the app are never removed automatically. + +### Fixed +- **Updating no longer freezes the app.** The update check and install ran on the UI thread; they now run in the background. +- **Pause and Stop respond right away.** The signature scan only checked for the request once per 8 MiB block; it now checks continuously, and the UI shows "Pausing…" immediately. + ## [1.4.0] - 2026-11-03 ### Added diff --git a/CHANGELOG.pt-BR.md b/CHANGELOG.pt-BR.md index cd00724..3384926 100644 --- a/CHANGELOG.pt-BR.md +++ b/CHANGELOG.pt-BR.md @@ -4,6 +4,16 @@ Formato baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/); versões seguem SemVer. +## [1.5.0] - 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 fases de verificação, instalação e reinício. +- **Apagar sessões salvas.** Cada sessão salva sozinha na lateral tem um botão de apagar, além de um botão "apagar todas". As configurações ganharam "Apagar sessões salvas sozinhas após" (nunca, 7, 30 ou 90 dias), aplicado ao abrir. Sessões abertas no app nunca são removidas automaticamente. + +### 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. +- **Pausar e Parar respondem na hora.** A varredura por assinatura só checava o pedido a cada bloco de 8 MiB; agora checa continuamente, e a interface mostra "Pausando…" imediatamente. + ## [1.4.0] - 2026-11-03 ### Adicionado diff --git a/Cargo.lock b/Cargo.lock index 8a33440..19f9134 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "guara-cli" -version = "1.4.0" +version = "1.5.0" dependencies = [ "clap", "ctrlc", @@ -429,7 +429,7 @@ dependencies = [ [[package]] name = "guara-core" -version = "1.4.0" +version = "1.5.0" dependencies = [ "aes", "argon2", diff --git a/Cargo.toml b/Cargo.toml index e462cd9..2433d7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/guara-core", "crates/guara-cli"] [workspace.package] -version = "1.4.0" +version = "1.5.0" edition = "2021" license = "MIT OR Apache-2.0" repository = "https://git.lucasrguerra.dev.br/ciberfauna/guara" diff --git a/apps/gui/src-tauri/Cargo.lock b/apps/gui/src-tauri/Cargo.lock index e9ec621..e968553 100644 --- a/apps/gui/src-tauri/Cargo.lock +++ b/apps/gui/src-tauri/Cargo.lock @@ -1342,7 +1342,7 @@ dependencies = [ [[package]] name = "guara-core" -version = "1.4.0" +version = "1.5.0" dependencies = [ "aes", "argon2", @@ -1373,7 +1373,7 @@ dependencies = [ [[package]] name = "guara-gui" -version = "1.4.0" +version = "1.5.0" dependencies = [ "guara-core", "libc", diff --git a/apps/gui/src-tauri/Cargo.toml b/apps/gui/src-tauri/Cargo.toml index 96ea3eb..ca9d8de 100644 --- a/apps/gui/src-tauri/Cargo.toml +++ b/apps/gui/src-tauri/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "guara-gui" description = "Guará: graphical file recovery interface" -version = "1.4.0" +version = "1.5.0" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Guará contributors"] diff --git a/apps/gui/src-tauri/src/main.rs b/apps/gui/src-tauri/src/main.rs index e78877b..bc80830 100644 --- a/apps/gui/src-tauri/src/main.rs +++ b/apps/gui/src-tauri/src/main.rs @@ -22,25 +22,41 @@ async fn rpc( } #[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 to read raw disks. diff --git a/apps/gui/src-tauri/tauri.conf.json b/apps/gui/src-tauri/tauri.conf.json index b5cb1cf..2352482 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": "Guará", - "version": "1.4.0", + "version": "1.5.0", "identifier": "dev.guara.app", "build": { "frontendDist": "../ui" diff --git a/apps/gui/ui/app.css b/apps/gui/ui/app.css index 544be89..9125636 100644 --- a/apps/gui/ui/app.css +++ b/apps/gui/ui/app.css @@ -542,3 +542,8 @@ dialog.lightbox[open] { display: grid; } .update-card .upd-actions { display: flex; gap: 8px; flex-wrap: wrap; } .update-card .sub { margin: 0; } pre.upd-notes { max-height: 50vh; overflow: auto; white-space: pre-wrap; font-size: 13px; } +.update-card .upd-bar { margin-top: 10px; } + +.list li.has-del { position: relative; } +.list li.has-del .del { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); opacity: 0; } +.list li.has-del:hover .del, .list li.has-del .del:focus-visible { opacity: 1; } diff --git a/apps/gui/ui/app.js b/apps/gui/ui/app.js index 201dd96..95a0a48 100644 --- a/apps/gui/ui/app.js +++ b/apps/gui/ui/app.js @@ -53,7 +53,7 @@ document.querySelectorAll('[data-theme-pick]').forEach((b) => (b.onclick = async // ------------------------------------------------------------------ settings // (declared before use: `S` is defined further below, so the object lives here) -const SETTINGS = { theme: 'auto', lang: 'auto', ui_lang: null, notify: true, maps: false, updates: true }; +const SETTINGS = { theme: 'auto', lang: 'auto', ui_lang: null, notify: true, maps: false, updates: true, session_retention_days: 0 }; async function saveSettings(patch) { Object.assign(SETTINGS, patch); try { await rpc('settings_set', SETTINGS); } catch { /* continue with local storage only */ } @@ -201,11 +201,36 @@ function renderSide() { const rl = $('#recentList'); rl.dataset.empty = 'Nada salvo ainda'; rl.innerHTML = (S.recent || []).map((r, i) => ` -
  • `).join(''); +
  • `).join(''); rl.querySelectorAll('.dev').forEach((b) => (b.onclick = () => openRecent(S.recent[+b.dataset.r]))); + rl.querySelectorAll('.del').forEach((b) => (b.onclick = (e) => { e.stopPropagation(); deleteRecent(S.recent[+b.dataset.del]); })); } +function confirmDlg({ title, text, ok }) { + return new Promise((resolve) => { + const d = $('#dlg'); + d.innerHTML = `

    ${esc(title)}

    ${text}

    `; + d.onclose = () => resolve(d.returnValue === 'ok'); + d.showModal(); + }); +} + +async function deleteRecent(r) { + if (!r) return; + const name = (r.target || '').split(/[\\/]/).pop() || 'Sessão'; + if (!await confirmDlg({ title: 'Apagar sessão salva', text: `A sessão de ${esc(name)} será apagada de vez. Os arquivos do disco não são afetados.`, ok: 'Apagar' })) return; + try { await rpc('session_delete', { path: r.path }); toast('Sessão apagada'); } catch (e) { toast(e.message); } + loadRecent(); +} + +$('#clearRecentBtn')?.addEventListener('click', async () => { + if (!(S.recent || []).length) { toast('Nada para apagar'); return; } + if (!await confirmDlg({ title: 'Apagar todas as sessões salvas', text: 'Todas as sessões salvas sozinhas serão apagadas de vez. Sessões abertas agora são mantidas.', ok: 'Apagar tudo' })) return; + try { const r = await rpc('sessions_prune', { all: true }); toast(`Sessões apagadas: ${r.removed}`); } catch (e) { toast(e.message); } + loadRecent(); +}); + async function loadRecent() { try { S.recent = await rpc('sessions_list'); } catch { S.recent = []; } renderSide(); @@ -590,7 +615,9 @@ function paintStatus() { const rate = p.total && st.elapsed > 1 && p.done ? p.done / st.elapsed : 0; const eta = rate && running ? dur((p.total - p.done) / rate) : null; const enr = st.enriching ? `Lendo datas e metadados das fotos… ${st.enriching.done.toLocaleString(LOC())}/${st.enriching.total.toLocaleString(LOC())}` : ''; - const buttons = running ? '' + const stopping = running && st.stopping; + const buttons = stopping ? '' + : running ? '' : st.status === 'paused' ? `` : ''; const relink = st.source === false ? '' : ''; const tools = relink + (!running && st.found ? '' : ''); @@ -651,8 +678,8 @@ async function chooseSource() { async function onProgressClick(e) { const act = e.target.closest('[data-act]')?.dataset.act; if (!act) return; - if (act === 'pause') { await rpc('scan_pause', { job: S.job }); toast('Pausando…'); } - else if (act === 'stop') await rpc('scan_stop', { job: S.job }); + if (act === 'pause') { await rpc('scan_pause', { job: S.job }); toast('Pausando…'); tick(); } + else if (act === 'stop') { await rpc('scan_stop', { job: S.job }); tick(); } else if (act === 'resume') { try { await rpc('scan_resume', { job: S.job }); stopPoll(); S.poll = setInterval(tick, 500); tick(); } catch (err) { toast(err.message); chooseSource(); } @@ -753,9 +780,11 @@ $('#settingsBtn')?.addEventListener('click', () => { + ${tauri?.core?.invoke ? `` : ''} `; d.querySelector('[name=lang]').value = SETTINGS.lang; + d.querySelector('[name=retention]').value = String([0, 7, 30, 90].includes(SETTINGS.session_retention_days) ? SETTINGS.session_retention_days : 0); d.querySelector('#updNow')?.addEventListener('click', (e) => { e.preventDefault(); if (UPD) applyUpdate(); @@ -763,11 +792,11 @@ $('#settingsBtn')?.addEventListener('click', () => { }); d.onclose = () => { if (d.returnValue !== 'ok') return; - const patch = { lang: d.querySelector('[name=lang]').value, notify: d.querySelector('[name=notify]').checked, maps: d.querySelector('[name=maps]').checked }; + const patch = { lang: d.querySelector('[name=lang]').value, notify: d.querySelector('[name=notify]').checked, maps: d.querySelector('[name=maps]').checked, session_retention_days: +d.querySelector('[name=retention]').value }; if (d.querySelector('[name=updates]')) patch.updates = d.querySelector('[name=updates]').checked; setLang(patch.lang); patch.ui_lang = currentLang(); - saveSettings(patch); + saveSettings(patch).then(() => rpc('sessions_prune', {}).then(loadRecent).catch(() => {})); EX?.relang?.(); toast('Salvo'); }; @@ -785,7 +814,15 @@ async function applyUpdate() { updating = true; const updApply = $('#updApply'); const updNow = $('#updNow'); - const setPhase = (txt) => { + const setPhase = (txt, pct) => { + const card = $('#updateCard'); + if (card) { + let bar = card.querySelector('.upd-bar'); + if (!bar) { bar = document.createElement('div'); bar.className = 'bar upd-bar'; bar.innerHTML = ''; card.appendChild(bar); } + bar.classList.toggle('indet', pct == null); + bar.firstChild.style.width = pct == null ? '35%' : `${pct}%`; + } + if (pct != null) txt = `${txt} ${pct}%`; if (updApply) { updApply.disabled = true; updApply.textContent = txt; } if (updNow) { updNow.disabled = true; updNow.textContent = txt; } }; @@ -796,7 +833,8 @@ async function applyUpdate() { try { unlisten = await tauri.event.listen('update-progress', (event) => { const phase = event.payload?.phase; - if (phase === 'downloading') setPhase('Baixando a atualização…'); + const pct = event.payload?.percent; + if (phase === 'downloading') setPhase('Baixando a atualização…', pct); else if (phase === 'verifying') setPhase('Verificando integridade…'); else if (phase === 'installing') setPhase('Instalando a atualização…'); else if (phase === 'restarting') setPhase('Reiniciando…'); @@ -809,6 +847,7 @@ async function applyUpdate() { setPhase('Atualização concluída'); } catch (e) { updating = false; + $('#updateCard .upd-bar')?.remove(); if (updApply) { updApply.disabled = false; updApply.textContent = 'Atualizar agora'; } if (updNow) { updNow.disabled = false; updNow.textContent = UPD?.version ? `atualizar para ${UPD.version}` : 'Verificar agora'; } toast(`Falha na atualização: ${e}`); @@ -914,6 +953,7 @@ function watchClose() { return; } await loadDevices(); + try { await rpc('sessions_prune', {}); } catch { /* retention is best-effort */ } await loadRecent(); renderHome(); })(); diff --git a/apps/gui/ui/i18n-en.js b/apps/gui/ui/i18n-en.js index f73db56..cf5baf8 100644 --- a/apps/gui/ui/i18n-en.js +++ b/apps/gui/ui/i18n-en.js @@ -619,4 +619,20 @@ export const EN = { '{n} arquivo': '{n} file', '{n} arquivos': '{n} files', '{n} {n} · {n}': '{n} {n} · {n}', + 'Apagar esta sessão': 'Delete this session', + 'Apagar todas as sessões salvas sozinhas': 'Delete all autosaved sessions', + 'Apagar sessão salva': 'Delete saved session', + 'Apagar': 'Delete', + 'Apagar tudo': 'Delete all', + 'Apagar todas as sessões salvas': 'Delete all saved sessions', + 'Todas as sessões salvas sozinhas serão apagadas de vez. Sessões abertas agora são mantidas.': 'All autosaved sessions will be permanently deleted. Sessions currently open are kept.', + 'Sessão apagada': 'Session deleted', + 'Nada para apagar': 'Nothing to delete', + 'Apagar sessões salvas sozinhas após': 'Delete autosaved sessions after', + 'Nunca': 'Never', + '7 dias': '7 days', + '30 dias': '30 days', + '90 dias': '90 days', + 'será apagada de vez. Os arquivos do disco não são afetados.': 'will be permanently deleted. Files on the disk are not affected.', + 'Sessões apagadas: {n}': 'Sessions deleted: {n}', }; diff --git a/apps/gui/ui/index.html b/apps/gui/ui/index.html index 9b2980d..789b53d 100644 --- a/apps/gui/ui/index.html +++ b/apps/gui/ui/index.html @@ -24,7 +24,7 @@
    Sessões
      -
      Recentes (salvas sozinhas)
      +
      Recentes (salvas sozinhas)
        diff --git a/crates/guara-core/src/carve.rs b/crates/guara-core/src/carve.rs index 709136c..56efb59 100644 --- a/crates/guara-core/src/carve.rs +++ b/crates/guara-core/src/carve.rs @@ -64,7 +64,19 @@ pub fn carve_range( let scan_len = got.min(CHUNK).min((end - pos) as usize); ev.chunk(pos, &buf[..scan_len]); let mut i = 0usize; + let mut since_check = 0u32; while i < scan_len { + // Pause/stop must take effect within a fraction of a second even on slow media, + // not only at 8 MiB chunk boundaries. The chunk is reprocessed on resume (hits at + // offsets already found are skipped by the caller). + since_check += 1; + if since_check >= 2048 { + since_check = 0; + if cancelled() { + *next = pos; + return CarveEnd::Cancelled; + } + } let abs = pos + i as u64; if abs < skip_until { i += SECTOR as usize; @@ -78,6 +90,10 @@ pub fn carve_range( let allowed = cfg.categories.is_empty() || cfg.categories.contains(&category_for_ext(hit.ext)); if hit.len >= MIN_LEN && allowed { + if cancelled() { + *next = pos; + return CarveEnd::Cancelled; + } let action = ev.hit(abs, &hit); match action { HitAction::Skip if hit.confidence != crate::types::Confidence::Low => { diff --git a/crates/guara-core/src/scan.rs b/crates/guara-core/src/scan.rs index b8bed74..347ec07 100644 --- a/crates/guara-core/src/scan.rs +++ b/crates/guara-core/src/scan.rs @@ -235,7 +235,12 @@ pub fn run( return Outcome::Interrupted(cp); } } - handler.rebuild_pending(); + if !handler.rebuild_pending(cancelled) { + // Paused/stopped during reassembly: the truncated candidates were already reported, + // and on resume (all ranges done) the scan finishes without redoing them. + cp.next_id = next_id.load(std::sync::atomic::Ordering::Relaxed); + return Outcome::Interrupted(cp); + } Outcome::Completed } @@ -306,9 +311,13 @@ impl Handler<'_> { self.sink.replace(f); } - fn rebuild_pending(&mut self) { + /// Reassembles queued fragmented files. Returns `false` if cancelled part-way. + fn rebuild_pending(&mut self, cancelled: &(dyn Fn() -> bool + Sync)) -> bool { let pend = std::mem::take(&mut self.pending); for p in pend { + if cancelled() { + return false; + } let off = p.found.first_offset().unwrap_or(0); if p.mp4 { self.rebuild_mp4(p, off); @@ -339,6 +348,7 @@ impl Handler<'_> { self.sink.replace(f); } } + true } } diff --git a/crates/guara-core/src/service.rs b/crates/guara-core/src/service.rs index 51a89f0..95a0ee9 100644 --- a/crates/guara-core/src/service.rs +++ b/crates/guara-core/src/service.rs @@ -336,6 +336,7 @@ impl Engine { "error": s.error, "report": s.report, "elapsed": elapsed, + "stopping": s.status == Status::Running && j.cancelled(), "source": j.source().is_some(), "source_path": j.src_path.lock().unwrap().clone(), "session_file": j.session_file.lock().unwrap().as_ref().map(|p| p.to_string_lossy().to_string()), @@ -1098,11 +1099,78 @@ impl Engine { "só sessões automáticas podem ser apagadas por aqui", )); } + let running = self.jobs.lock().unwrap().values().any(|j| { + j.session_file.lock().unwrap().as_deref() == Some(p) + && j.st.lock().unwrap().status == Status::Running + }); + if running { + return Err(Error::msg( + "esta varredura ainda está em andamento; pause ou pare antes de apagar a sessão", + )); + } let _ = std::fs::remove_file(p.with_extension("meta.json")); std::fs::remove_file(p)?; Ok(()) } + /// `true` if an open job (scanning, paused, or loaded) still autosaves to this file. + fn session_in_use(&self, p: &Path) -> bool { + self.jobs + .lock() + .unwrap() + .values() + .any(|j| j.session_file.lock().unwrap().as_deref() == Some(p)) + } + + /// Deletes autosaved sessions older than `days` (`None` = the configured retention; + /// `Some(0)` = all of them). Sessions held by open jobs are always kept. + /// Returns how many were removed. + pub fn sessions_prune(&self, days: Option) -> usize { + let days = match days { + Some(d) => d, + None => match crate::settings::load().session_retention_days { + 0 => return 0, // retention disabled: keep everything + d => d, + }, + }; + let dir = sessions_dir(); + let now = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_secs() as i64) + .unwrap_or(0); + let cutoff = now - days as i64 * 86_400; + let mut removed = 0; + let Ok(rd) = std::fs::read_dir(&dir) else { + return 0; + }; + for e in rd.flatten() { + let path = e.path(); + let name = e.file_name().to_string_lossy().to_string(); + if !name.ends_with(".json") || name.ends_with(".meta.json") { + continue; + } + let saved_at = std::fs::read(path.with_extension("meta.json")) + .ok() + .and_then(|b| serde_json::from_slice::(&b).ok()) + .and_then(|v| v["saved_at"].as_i64()) + .or_else(|| { + e.metadata() + .and_then(|m| m.modified()) + .ok() + .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) + .map(|d| d.as_secs() as i64) + }) + .unwrap_or(now); + if saved_at <= cutoff && !self.session_in_use(&path) { + let _ = std::fs::remove_file(path.with_extension("meta.json")); + if std::fs::remove_file(&path).is_ok() { + removed += 1; + } + } + } + removed + } + // ---------------------------------------------------------------- RPC pub fn rpc(&self, method: &str, p: Value) -> Result { @@ -1342,6 +1410,10 @@ impl Engine { self.session_delete(&s("path")?)?; json!({}) } + "sessions_prune" => { + let all = p.get("all").and_then(|v| v.as_bool()) == Some(true); + json!({ "removed": self.sessions_prune(if all { Some(0) } else { None }) }) + } "session_load" => json!({ "job": self.load_session(&s("path")?)? }), "defaults" => { let home = crate::owner::user_home().to_string_lossy().to_string(); diff --git a/crates/guara-core/src/settings.rs b/crates/guara-core/src/settings.rs index a8a2b54..acbbbf6 100644 --- a/crates/guara-core/src/settings.rs +++ b/crates/guara-core/src/settings.rs @@ -27,6 +27,9 @@ pub struct Settings { /// without sending any telemetry). #[serde(default = "yes")] pub updates: bool, + /// Autosaved sessions older than this many days are deleted on startup (`0` = keep forever). + #[serde(default)] + pub session_retention_days: u32, } fn auto() -> String { @@ -46,6 +49,7 @@ impl Default for Settings { notify: true, maps: false, updates: true, + session_retention_days: 0, } } } diff --git a/crates/guara-core/src/update.rs b/crates/guara-core/src/update.rs index 3e3e046..3eb3bbd 100644 --- a/crates/guara-core/src/update.rs +++ b/crates/guara-core/src/update.rs @@ -29,6 +29,8 @@ struct Release { struct Asset { name: String, browser_download_url: String, + #[serde(default)] + size: u64, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] @@ -52,13 +54,25 @@ 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 `percent` (0-100) through +/// `on_pct` while curl runs (no stderr parsing; `total` comes from the release asset size). +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: guara-updater", "-o"]) .arg(dest) .arg(url) - .status() + .spawn() .map_err(|e| Error::msg(format!("curl {url}: {e}")))?; + let status = loop { + if let Some(st) = child.try_wait().map_err(|e| Error::msg(e.to_string()))? { + 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(Error::msg(format!("curl {url}: download falhou"))); } @@ -145,7 +159,7 @@ pub fn apply(current_exe: &PathBuf) -> Result { let tmp_dir = std::env::temp_dir().join("guara-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)?; @@ -350,7 +364,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"); diff --git a/crates/guara-core/tests/extras.rs b/crates/guara-core/tests/extras.rs index 3fc57d0..6ec157b 100644 --- a/crates/guara-core/tests/extras.rs +++ b/crates/guara-core/tests/extras.rs @@ -143,6 +143,7 @@ fn configuracoes_antigas_ganham_os_valores_padrao_novos() { notify: false, maps: true, updates: false, + ..Default::default() }) .unwrap(); let s = settings::load(); diff --git a/docs/interface.md b/docs/interface.md index 118dc34..dec1a24 100644 --- a/docs/interface.md +++ b/docs/interface.md @@ -37,9 +37,13 @@ The switch at the bottom of the sidebar offers **Auto** (follows the system), ** **Settings** (the gear at the bottom of the sidebar) has a **Language** selector: **Auto** follows the system language, or you can pick **Português** or **English**. The change applies right away. The same dialog controls automatic updates (below), notifications for long tasks and online maps for photos with GPS (off by default, because it downloads OpenStreetMap tiles). +## Saved sessions + +Sessions are autosaved and listed under **Recent** in the sidebar. Hover one and click the ✕ to delete it, or use the trash button in the section title to delete them all; sessions open in the app are kept. **Settings > Delete autosaved sessions after** removes old ones on startup (never by default; 7, 30 or 90 days). + ## Updates -When the desktop app opens it asks Gitea for the latest release. If a newer version exists, a card appears at the bottom right with the versions and the release address. For the CLI, `guara update` checks for and installs updates with SHA-256 verification. **Settings > Automatic updates** turns the startup check off and has a **Check now** button. The check sends nothing besides what any browser sends to Gitea. `guara ui` in the browser does not update itself. +When the desktop app opens it asks Gitea for the latest release. If a newer version exists, a card appears at the bottom right with the versions and the release address. For the CLI, `guara update` checks for and installs updates with SHA-256 verification. **Settings > Automatic updates** turns the startup check off and has a **Check now** button. Clicking **Update now** shows a progress bar with the download percentage, then the verify, install and restart steps; the app stays responsive meanwhile. The check sends nothing besides what any browser sends to Gitea. `guara ui` in the browser does not update itself.

        The Settings dialog with the Language selector set to English

        diff --git a/docs/pt-BR/interface.md b/docs/pt-BR/interface.md index bb7a4a7..b8a90c2 100644 --- a/docs/pt-BR/interface.md +++ b/docs/pt-BR/interface.md @@ -37,9 +37,13 @@ O seletor no fim da barra lateral oferece **Auto** (acompanha o sistema), **Clar Em **Configurações** (a engrenagem no fim da barra lateral) há o seletor **Idioma**: **Auto** acompanha o idioma do sistema, ou você escolhe **Português** ou **English**. A troca vale na hora. A mesma janela controla as atualizações automáticas (abaixo), as notificações de tarefas longas e os mapas online das fotos com GPS (desligados por padrão, porque baixam blocos do OpenStreetMap). +## Sessões salvas + +As sessões são salvas sozinhas e listadas em **Recentes** na barra lateral. Passe o mouse sobre uma e clique no ✕ para apagá-la, ou use o botão de lixeira no título da seção para apagar todas; sessões abertas no app são mantidas. **Configurações > Apagar sessões salvas sozinhas após** remove as antigas ao abrir (nunca, por padrão; 7, 30 ou 90 dias). + ## Atualizações -Ao abrir, o app desktop consulta o Gitea para verificar se há uma versão mais nova. Havendo versão nova, aparece um cartão no canto inferior direito com as versões e o endereço da release. Para o CLI, `guara update` verifica e instala atualizações com conferência de SHA-256. **Configurações > Atualizações automáticas** desliga a verificação ao abrir e tem o botão **Verificar agora**. A consulta não envia nada além do que qualquer navegador envia ao Gitea. O `guara ui` no navegador não se atualiza sozinho. +Ao abrir, o app desktop consulta o Gitea para verificar se há uma versão mais nova. Havendo versão nova, aparece um cartão no canto inferior direito com as versões e o endereço da release. Para o CLI, `guara update` verifica e instala atualizações com conferência de SHA-256. **Configurações > Atualizações automáticas** desliga a verificação ao abrir e tem o botão **Verificar agora**. Ao clicar em **Atualizar agora**, aparece uma barra de progresso com a porcentagem do download e depois as etapas de verificação, instalação e reinício; o app continua responsivo. A consulta não envia nada além do que qualquer navegador envia ao Gitea. O `guara ui` no navegador não se atualiza sozinho.

        A janela de Configurações com o seletor de Idioma