From aee31d8bf7d4d8939c35caec7ad75a400064bc6f Mon Sep 17 00:00:00 2001 From: thonyydev <105062764+thonyydev@users.noreply.github.com> Date: Fri, 6 Nov 2026 21:55:26 -0300 Subject: [PATCH] feat: add a button to check for updates Settings gets a "Check for updates" button below "Update automatically". It uses the same check, download and signature verification as the automatic one, and works even with automatic updates off, since the user asked. The result says the app is up to date, that a version is ready to install (the usual banner appears) or that the check failed. - A version found this way stays ready when other settings are saved; it is only dropped when automatic updates are turned off. - Development builds refuse the check, like the automatic one. - The description and the README say the app goes online when you check for updates. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +- i18n/en.json | 9 +++- i18n/es.json | 9 +++- i18n/fr.json | 9 +++- i18n/it.json | 9 +++- i18n/pt-BR.json | 9 +++- src-tauri/src/lib.rs | 91 +++++++++++++++++++++----------- src/App.css | 1 + src/components/settings.test.tsx | 16 ++++++ src/components/settings.tsx | 16 ++++-- src/lib/api.ts | 1 + 11 files changed, 128 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 8f4e0a0..6fe88a6 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Get the installer from the [Releases page](https://github.com/thonyydev/Download The installer isn't code-signed yet, so Windows SmartScreen may warn you when you run it. Each release lists a SHA-256 hash you can check before installing. -**Updates** arrive on their own from this project's GitHub Releases and are checked against a signature before installing. With the window open, the app asks first. In the system tray, it installs them and opens again. Your history and settings are kept. You can turn this off in Settings, then install new versions by hand. +**Updates** arrive on their own from this project's GitHub Releases and are checked against a signature before installing. With the window open, the app asks first. In the system tray, it installs them and opens again. Your history and settings are kept. To look right away, use **Check for updates** in Settings. You can also turn automatic updates off there. **To uninstall,** use Windows Settings. Your organized files are never touched. Settings and history stay in `%APPDATA%\com.thonyy.download-organizer` unless you remove them. @@ -58,7 +58,7 @@ The installer isn't code-signed yet, so Windows SmartScreen may warn you when yo ## Privacy -Download Organizer has no account, telemetry or cloud service. Its only network use is checking GitHub for updates at startup and every 6 hours, which shares your IP address with GitHub and sends no file data. Turning off automatic updates in Settings stops it. Its local database stores file paths, sizes, dates and content hashes so that it can show your history and undo safely. When reporting a problem, remove personal file names and paths, and don't attach the database. +Download Organizer has no account, telemetry or cloud service. Its only network use is checking GitHub for updates at startup and every 6 hours, or when you check for updates yourself, which shares your IP address with GitHub and sends no file data. Turning off automatic updates in Settings stops the automatic checks. Its local database stores file paths, sizes, dates and content hashes so that it can show your history and undo safely. When reporting a problem, remove personal file names and paths, and don't attach the database. ## Feedback & Suggestions diff --git a/i18n/en.json b/i18n/en.json index 5342449..9f5f171 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -289,7 +289,7 @@ "Saved startup": "Saved startup", "Startup, notifications and updates": "Startup, notifications and updates", "Update automatically": "Update automatically", - "Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet": "Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet", + "Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates": "Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates", "Saved updates": "Saved updates", "Preferences applied on save": "Preferences applied on save", "Start with Windows": "Start with Windows", @@ -541,5 +541,10 @@ "With several folders, each file in the preview shows its source folder. Files that are only in the cloud, such as OneDrive online-only files, are left alone and never downloaded.": "With several folders, each file in the preview shows its source folder. Files that are only in the cloud, such as OneDrive online-only files, are left alone and never downloaded.", "What's new in version": "What's new in version", "Choose my folders": "Choose my folders", - "Got it": "Got it" + "Got it": "Got it", + "Check for updates": "Check for updates", + "Checking for updates…": "Checking for updates…", + "You have the latest version": "You have the latest version", + "Couldn't check for updates": "Couldn't check for updates", + "Check your connection and try again.": "Check your connection and try again." } diff --git a/i18n/es.json b/i18n/es.json index 5c4fb16..333bba5 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -289,7 +289,7 @@ "Saved startup": "Inicio guardado", "Startup, notifications and updates": "Inicio, notificaciones y actualizaciones", "Update automatically": "Actualizar automáticamente", - "Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet": "Busca nuevas versiones en GitHub cada 6 horas. Desactivado, la aplicación no accede a internet", + "Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates": "Busca nuevas versiones en GitHub cada 6 horas. Si está desactivado, la aplicación solo se conecta a internet cuando buscas actualizaciones", "Saved updates": "Actualizaciones guardadas", "Preferences applied on save": "Preferencias aplicadas al guardar", "Start with Windows": "Iniciar con Windows", @@ -541,5 +541,10 @@ "With several folders, each file in the preview shows its source folder. Files that are only in the cloud, such as OneDrive online-only files, are left alone and never downloaded.": "Con varias carpetas, cada archivo de la vista previa muestra su carpeta de origen. Los archivos que solo están en la nube, como los archivos solo en línea de OneDrive, se quedan donde están y nunca se descargan.", "What's new in version": "Novedades de la versión", "Choose my folders": "Elegir mis carpetas", - "Got it": "Entendido" + "Got it": "Entendido", + "Check for updates": "Buscar actualizaciones", + "Checking for updates…": "Buscando actualizaciones…", + "You have the latest version": "Tienes la versión más reciente", + "Couldn't check for updates": "No se pudieron buscar actualizaciones", + "Check your connection and try again.": "Revisa tu conexión e inténtalo de nuevo." } diff --git a/i18n/fr.json b/i18n/fr.json index de805a8..8b6f23c 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -289,7 +289,7 @@ "Saved startup": "Démarrage enregistré", "Startup, notifications and updates": "Démarrage, notifications et mises à jour", "Update automatically": "Mettre à jour automatiquement", - "Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet": "Recherche de nouvelles versions sur GitHub toutes les 6 heures. Désactivé, l'application n'accède pas à Internet", + "Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates": "Recherche de nouvelles versions sur GitHub toutes les 6 heures. Désactivé, l'application ne se connecte à internet que lorsque vous recherchez des mises à jour", "Saved updates": "Mises à jour enregistrées", "Preferences applied on save": "Préférences appliquées à l'enregistrement", "Start with Windows": "Démarrer avec Windows", @@ -541,5 +541,10 @@ "With several folders, each file in the preview shows its source folder. Files that are only in the cloud, such as OneDrive online-only files, are left alone and never downloaded.": "Avec plusieurs dossiers, chaque fichier de l'aperçu indique son dossier source. Les fichiers qui sont uniquement dans le cloud, comme les fichiers en ligne uniquement de OneDrive, restent où ils sont et ne sont jamais téléchargés.", "What's new in version": "Nouveautés de la version", "Choose my folders": "Choisir mes dossiers", - "Got it": "Compris" + "Got it": "Compris", + "Check for updates": "Rechercher des mises à jour", + "Checking for updates…": "Recherche de mises à jour…", + "You have the latest version": "Vous avez la version la plus récente", + "Couldn't check for updates": "Impossible de rechercher des mises à jour", + "Check your connection and try again.": "Vérifiez votre connexion et réessayez." } diff --git a/i18n/it.json b/i18n/it.json index 6571d64..2a61a33 100644 --- a/i18n/it.json +++ b/i18n/it.json @@ -289,7 +289,7 @@ "Saved startup": "Avvio salvato", "Startup, notifications and updates": "Avvio, notifiche e aggiornamenti", "Update automatically": "Aggiorna automaticamente", - "Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet": "Cerca nuove versioni su GitHub ogni 6 ore. Se disattivato, l'app non accede a Internet", + "Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates": "Cerca nuove versioni su GitHub ogni 6 ore. Se disattivato, l'app si collega a internet solo quando cerchi aggiornamenti", "Saved updates": "Aggiornamenti salvati", "Preferences applied on save": "Preferenze applicate al salvataggio", "Start with Windows": "Avvia con Windows", @@ -541,5 +541,10 @@ "With several folders, each file in the preview shows its source folder. Files that are only in the cloud, such as OneDrive online-only files, are left alone and never downloaded.": "Con più cartelle, ogni file nell'anteprima mostra la sua cartella di origine. I file che sono solo nel cloud, come i file solo online di OneDrive, restano dove sono e non vengono mai scaricati.", "What's new in version": "Novità della versione", "Choose my folders": "Scegli le mie cartelle", - "Got it": "Ho capito" + "Got it": "Ho capito", + "Check for updates": "Cerca aggiornamenti", + "Checking for updates…": "Ricerca aggiornamenti…", + "You have the latest version": "Hai la versione più recente", + "Couldn't check for updates": "Impossibile cercare aggiornamenti", + "Check your connection and try again.": "Controlla la connessione e riprova." } diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json index 264f0c7..cfca7cc 100644 --- a/i18n/pt-BR.json +++ b/i18n/pt-BR.json @@ -289,7 +289,7 @@ "Saved startup": "Inicialização salva", "Startup, notifications and updates": "Inicialização, notificações e atualizações", "Update automatically": "Atualizar automaticamente", - "Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet": "Procura novas versões no GitHub a cada 6 horas. Desligado, o aplicativo não acessa a internet", + "Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates": "Procura novas versões no GitHub a cada 6 horas. Desligado, o aplicativo só acessa a internet quando você verifica se há atualizações", "Saved updates": "Atualizações salvas", "Preferences applied on save": "Preferências aplicadas ao salvar", "Start with Windows": "Iniciar com o Windows", @@ -541,5 +541,10 @@ "With several folders, each file in the preview shows its source folder. Files that are only in the cloud, such as OneDrive online-only files, are left alone and never downloaded.": "Com várias pastas, cada arquivo na prévia mostra a pasta de origem. Arquivos que estão só na nuvem, como os arquivos somente online do OneDrive, ficam onde estão e nunca são baixados.", "What's new in version": "Novidades da versão", "Choose my folders": "Escolher minhas pastas", - "Got it": "Entendi" + "Got it": "Entendi", + "Check for updates": "Verificar atualizações", + "Checking for updates…": "Verificando atualizações…", + "You have the latest version": "Você está na versão mais recente", + "Couldn't check for updates": "Não foi possível verificar atualizações", + "Check your connection and try again.": "Confira sua conexão e tente de novo." } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4719760..c099da8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -189,43 +189,55 @@ fn install_pending_update(app: &AppHandle) -> Result<()> { Ok(()) } -// Downloads and verifies a newer signed version. A visible window asks first; the tray has no draft to lose. -fn update_cycle(app: &AppHandle) -> Result<()> { +// Downloads and verifies a newer signed version, and returns the one ready to install. +// `asked` is a check the user started: it runs even with automatic updates off. +fn fetch_update(app: &AppHandle, asked: bool) -> Result> { use tauri_plugin_updater::UpdaterExt; let state = app.state::(); - // Turned off, the app makes no network request at all. - if !lock(&state)?.store.preferences()?.updates { - return Ok(()); + // Turned off, the app makes no network request unless the user asks. + if !asked && !lock(&state)?.store.preferences()?.updates { + return Ok(None); } let pending = state .update .lock() .map_err(|_| internal_state_error())? - .is_some(); - if !pending { - let found = tauri::async_runtime::block_on(async { - let updater = app - .updater_builder() - .timeout(Duration::from_secs(300)) - .build()?; - let Some(update) = updater.check().await? else { - return Ok(None); - }; - let bytes = update.download(|_, _| {}, || {}).await?; - Ok::<_, tauri_plugin_updater::Error>(Some((update, bytes))) - }) - .map_err(|e| e.to_string())?; - if found.is_none() { - return Ok(()); - } - // Saving holds this lock too, so turning updates off can't slip in between. - let runtime = lock(&state)?; - if !runtime.store.preferences()?.updates { - return Ok(()); - } - *state.update.lock().map_err(|_| internal_state_error())? = found; - drop(runtime); - let _ = app.emit("organizer-changed", ()); + .as_ref() + .map(|(update, _)| update.version.clone()); + if pending.is_some() { + return Ok(pending); + } + let found = tauri::async_runtime::block_on(async { + let updater = app + .updater_builder() + .timeout(Duration::from_secs(300)) + .build()?; + let Some(update) = updater.check().await? else { + return Ok(None); + }; + let bytes = update.download(|_, _| {}, || {}).await?; + Ok::<_, tauri_plugin_updater::Error>(Some((update, bytes))) + }) + .map_err(|e| e.to_string())?; + let Some(found) = found else { + return Ok(None); + }; + // Saving holds this lock too, so turning updates off can't slip in between. + let runtime = lock(&state)?; + if !asked && !runtime.store.preferences()?.updates { + return Ok(None); + } + let version = found.0.version.clone(); + *state.update.lock().map_err(|_| internal_state_error())? = Some(found); + drop(runtime); + let _ = app.emit("organizer-changed", ()); + Ok(Some(version)) +} + +// A visible window asks first; the tray has no draft to lose. +fn update_cycle(app: &AppHandle) -> Result<()> { + if fetch_update(app, false)?.is_none() { + return Ok(()); } let hidden = app .get_webview_window("main") @@ -748,7 +760,8 @@ async fn save_preferences( &expected, autostart::apply, )?; - if !preferences.updates { + // Only when turned off now: a version the user checked for by hand stays ready while it's off. + if !preferences.updates && expected.updates { *state.update.lock().map_err(|_| internal_state_error())? = None; } i18n::set_language(&preferences.language); @@ -766,6 +779,21 @@ async fn save_preferences( .await } +#[tauri::command] +async fn check_update(app: AppHandle) -> Result> { + // Like the automatic checks, a dev build must never replace itself with a release. + if cfg!(debug_assertions) { + return Err("Development builds don't check for updates".into()); + } + blocking(move || fetch_update(&app, true)) + .await + .map_err(|error| { + // The details are technical and in English; the person gets the next step. + eprintln!("{error}"); + t("Check your connection and try again.").into() + }) +} + #[tauri::command] async fn install_update(app: AppHandle) -> Result<()> { blocking(move || install_pending_update(&app)).await @@ -880,6 +908,7 @@ fn run_application() -> std::result::Result<(), startup::StartupError> { organize, undo_operation, save_preferences, + check_update, install_update, retry_monitoring ]) diff --git a/src/App.css b/src/App.css index d3b5b5a..3ac48b7 100644 --- a/src/App.css +++ b/src/App.css @@ -367,6 +367,7 @@ tbody tr:has(.file-disclosure[aria-expanded=true]) { background: var(--surface-s /* Radix Presence owns exit/unmount and focus restoration through animationend. */ @keyframes dialog-close { to { opacity: 0; transform: translateY(4px) scale(.99); } } .spin { animation: spin 1s linear infinite; } +.update-check { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); padding-top: var(--space-2); } @keyframes spin { to { transform: rotate(360deg); } } @media (max-width: 1100px) { :root { --content-gutter: 24px; }.overview-lists { gap: var(--space-6); grid-template-columns: minmax(0,1fr) minmax(0,1fr); }.settings-section { grid-template-columns: 150px minmax(0,1fr); gap: var(--space-4); } } @media (max-width: 850px) { :root { --sidebar-width: 168px; --content-gutter: 16px; }.source-section { padding: var(--space-4); }.route { font-size: var(--text-title); }.overview-lists { grid-template-columns: 1fr; }.file-toolbar { flex-wrap: wrap; }.search-field { flex-basis: 100%; max-width: none; }.settings-section { grid-template-columns: 1fr; }.settings-section-heading p { max-width: none; }.rule-grid { column-gap: var(--space-4); }.file-summary { grid-template-columns: repeat(2,minmax(0,1fr)); }.history-header { flex-wrap: wrap; padding-bottom: var(--space-2); }.history-header > [data-slot=button] { margin-left: var(--space-8); } } diff --git a/src/components/settings.test.tsx b/src/components/settings.test.tsx index b2913a2..588d82a 100644 --- a/src/components/settings.test.tsx +++ b/src/components/settings.test.tsx @@ -6,8 +6,11 @@ import { Settings } from "@/components/settings"; import { samePreferences } from "@/lib/experience"; import type { Preferences } from "@/lib/api"; import { open } from "@tauri-apps/plugin-dialog"; +import { invoke } from "@tauri-apps/api/core"; +import { version } from "../../package.json"; vi.mock("@tauri-apps/plugin-dialog", () => ({ open: vi.fn() })); +vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn(), isTauri: () => true })); afterEach(() => { cleanup(); localStorage.clear(); }); const preferences: Preferences = { source: "/isolated/source", destination: "/isolated/destination", theme: "dark", language: "pt-BR", automatic: false, enabled_categories: [], notifications: true, updates: true, autostart: false, extra_sources: ["/isolated/desktop"], rules: [{ pattern: "*.stl", folder: "Modelos", keep: false }, { pattern: "*.obj", folder: "Malhas", keep: false }] }; @@ -106,3 +109,16 @@ it("adiciona e remove outras pastas de origem só no rascunho", async () => { expect(draft().extra_sources).toEqual(["/isolated/temp"]); expect(samePreferences(preferences, { ...preferences, extra_sources: [] })).toBe(false); }); + +it("verifica atualizações quando pedido e diz o resultado", async () => { + vi.mocked(invoke).mockResolvedValueOnce(null).mockResolvedValueOnce("9.9.9").mockRejectedValueOnce("Confira sua conexão e tente de novo."); + renderSettings(); + const check = () => fireEvent.click(screen.getByRole("button", { name: "Verificar atualizações" })); + check(); + expect(await screen.findByText(`Você está na versão mais recente (${version})`)).toBeTruthy(); + expect(invoke).toHaveBeenCalledWith("check_update"); + check(); + expect(await screen.findByText("Nova versão pronta para instalar: 9.9.9")).toBeTruthy(); + check(); + expect(await screen.findByText("Não foi possível verificar atualizações. Confira sua conexão e tente de novo.")).toBeTruthy(); +}); diff --git a/src/components/settings.tsx b/src/components/settings.tsx index f3323cb..e0ab682 100644 --- a/src/components/settings.tsx +++ b/src/components/settings.tsx @@ -1,11 +1,12 @@ import { useState } from "react"; import { open } from "@tauri-apps/plugin-dialog"; -import { CircleHelp, FolderOpen, Moon, Plus, Sun, ShieldCheck, Trash2 } from "lucide-react"; +import { CircleHelp, FolderOpen, Moon, Plus, RefreshCw, Sun, ShieldCheck, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; -import { displayPath, type Category, type Preferences, type Rule } from "@/lib/api"; +import { api, displayPath, type Category, type Preferences, type Rule } from "@/lib/api"; import { t } from "@/lib/i18n"; +import { version } from "../../package.json"; // Each language keeps its own name, so anyone can find theirs. const languages = () => [{ id: "system", name: t("System") }, { id: "pt-BR", name: "Português (Brasil)" }, { id: "en", name: "English" }, { id: "es", name: "Español" }, { id: "fr", name: "Français" }, { id: "it", name: "Italiano" }] as const; @@ -18,6 +19,15 @@ export function Settings({ draft, categories, busy, dirty, external, onChange: s }) { const [pickerError, setPickerError] = useState(""); const [tutorial, setTutorial] = useState(false); + // Kept as data, so the message follows the language at render. + const [updateCheck, setUpdateCheck] = useState<{ state: "checking" } | { state: "found"; version: string } | { state: "latest" } | { state: "error"; error: string } | null>(null); + async function checkUpdates() { + setUpdateCheck({ state: "checking" }); + try { + const found = await api.checkUpdate(); + setUpdateCheck(found ? { state: "found", version: found } : { state: "latest" }); + } catch (error) { setUpdateCheck({ state: "error", error: String(error) }); } + } async function choose(field: "source" | "destination") { try { setPickerError(""); @@ -53,7 +63,7 @@ export function Settings({ draft, categories, busy, dirty, external, onChange: s

{t("Startup, notifications and updates")}

{t("Preferences applied on save")}

-

{t("With automatic organization on, the app starts straight in the tray")}

setDraft(p => ({ ...p, autostart }))} />

{t("Tells you when automation organizes files or hits a problem, if the window isn't in focus")}

setDraft(p => ({ ...p, notifications }))} />

{t("Looks for new versions on GitHub every 6 hours. When off, the app doesn't use the internet")}

setDraft(p => ({ ...p, updates }))} />
+

{t("With automatic organization on, the app starts straight in the tray")}

setDraft(p => ({ ...p, autostart }))} />

{t("Tells you when automation organizes files or hits a problem, if the window isn't in focus")}

setDraft(p => ({ ...p, notifications }))} />

{t("Looks for new versions on GitHub every 6 hours. When off, the app only goes online when you check for updates")}

setDraft(p => ({ ...p, updates }))} />

{updateCheck?.state === "found" ? `${t("New version ready to install")}: ${updateCheck.version}` : updateCheck?.state === "latest" ? `${t("You have the latest version")} (${version})` : updateCheck?.state === "error" ? `${t("Couldn't check for updates")}. ${updateCheck.error}` : ""}

{t("Enabled categories")}

{t("Sorted by extension. Turned-off categories keep their files in the source, unless a custom rule fits them.")}

diff --git a/src/lib/api.ts b/src/lib/api.ts index 7ae3b51..b8624e9 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -31,6 +31,7 @@ export const api = { undo: (operationId: number) => invoke("undo_operation", { operationId }), save: (preferences: Preferences, expected: Preferences) => invoke("save_preferences", { preferences, expected }), retryMonitoring: () => invoke("retry_monitoring"), + checkUpdate: () => invoke("check_update"), installUpdate: () => invoke("install_update"), };