diff --git a/.github/scripts/test_update_manifest.py b/.github/scripts/test_update_manifest.py index a926408..0b70c02 100644 --- a/.github/scripts/test_update_manifest.py +++ b/.github/scripts/test_update_manifest.py @@ -6,7 +6,7 @@ class ManifestTest(unittest.TestCase): - def test_signed_assets_become_platforms_and_linux_stays_appimage_only(self): + def test_signed_assets_become_platforms_with_one_key_per_linux_format(self): with tempfile.TemporaryDirectory() as tmp: assets = Path(tmp) for name in [ @@ -15,17 +15,21 @@ def test_signed_assets_become_platforms_and_linux_stays_appimage_only(self): "LowMail-1.2.3-macos-universal.app.tar.gz", "LowMail-1.2.3-linux-x64.AppImage", "LowMail-1.2.3-linux-x64.deb", + "LowMail-1.2.3-linux-x64.rpm", + "LowMail-1.2.3-linux-x86_64.pkg.tar.zst", ]: (assets / name).write_bytes(b"x") - if not name.endswith(".deb"): + if not name.endswith(".zst"): (assets / f"{name}.sig").write_text(f"sig-{name}\n") doc = build_manifest("1.2.3", "LowBloat/LowMail", assets, "notes") self.assertEqual( sorted(doc["platforms"]), - ["darwin-aarch64", "darwin-x86_64", "linux-x86_64-appimage", - "windows-x86_64", "windows-x86_64-msi", "windows-x86_64-nsis"], + ["darwin-aarch64", "darwin-x86_64", "linux-x86_64-appimage", "linux-x86_64-deb", + "linux-x86_64-rpm", "windows-x86_64", "windows-x86_64-msi", "windows-x86_64-nsis"], ) self.assertNotIn("linux-x86_64", doc["platforms"]) + self.assertTrue(doc["platforms"]["linux-x86_64-deb"]["url"].endswith("/LowMail-1.2.3-linux-x64.deb")) + self.assertTrue(doc["platforms"]["linux-x86_64-rpm"]["url"].endswith("/LowMail-1.2.3-linux-x64.rpm")) self.assertEqual(doc["platforms"]["windows-x86_64-msi"]["signature"], "sig-LowMail-1.2.3-windows-x64.msi") self.assertTrue(doc["platforms"]["windows-x86_64"]["url"].endswith("/v1.2.3/LowMail-1.2.3-windows-x64-setup.exe")) diff --git a/.github/scripts/update_manifest.py b/.github/scripts/update_manifest.py index cabf8b8..2522e2f 100644 --- a/.github/scripts/update_manifest.py +++ b/.github/scripts/update_manifest.py @@ -21,8 +21,11 @@ def signed(keys, asset): signed(["windows-x86_64", "windows-x86_64-nsis"], f"LowMail-{version}-windows-x64-setup.exe") signed(["windows-x86_64-msi"], f"LowMail-{version}-windows-x64.msi") signed(["darwin-aarch64", "darwin-x86_64"], f"LowMail-{version}-macos-universal.app.tar.gz") - # No generic Linux key: .deb, .rpm and Arch installs must never receive an AppImage. + # One key per Linux format, never a generic one: a .deb install must get a + # .deb, an .rpm install an .rpm, and the Arch package nothing (pacman owns it). signed(["linux-x86_64-appimage"], f"LowMail-{version}-linux-x64.AppImage") + signed(["linux-x86_64-deb"], f"LowMail-{version}-linux-x64.deb") + signed(["linux-x86_64-rpm"], f"LowMail-{version}-linux-x64.rpm") return { "version": version, @@ -47,7 +50,7 @@ def signed(keys, asset): notes = result.stdout.strip() assets = Path("release-assets") doc = build_manifest(version, repo, assets, notes) - required = {"windows-x86_64", "darwin-aarch64", "linux-x86_64-appimage"} + required = {"windows-x86_64", "darwin-aarch64", "linux-x86_64-appimage", "linux-x86_64-deb", "linux-x86_64-rpm"} missing = required - doc["platforms"].keys() if missing: raise SystemExit(f"Signed updater artifacts missing for: {sorted(missing)}") diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c10d53f..57235af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -128,8 +128,14 @@ jobs: set -euo pipefail mkdir -p out bundle=target/release/bundle - cp "$(find $bundle/deb -name '*.deb' | head -n 1)" "out/LowMail-${VERSION}-linux-x64.deb" - cp "$(find $bundle/rpm -name '*.rpm' | head -n 1)" "out/LowMail-${VERSION}-linux-x64.rpm" + # Each package keeps its updater signature: .deb and .rpm installs + # update themselves through dpkg/rpm. + deb="$(find $bundle/deb -name '*.deb' | head -n 1)" + cp "$deb" "out/LowMail-${VERSION}-linux-x64.deb" + cp "$deb.sig" "out/LowMail-${VERSION}-linux-x64.deb.sig" + rpm="$(find $bundle/rpm -name '*.rpm' | head -n 1)" + cp "$rpm" "out/LowMail-${VERSION}-linux-x64.rpm" + cp "$rpm.sig" "out/LowMail-${VERSION}-linux-x64.rpm.sig" appimage="$(find $bundle/appimage -name '*.AppImage' | head -n 1)" cp "$appimage" "out/LowMail-${VERSION}-linux-x64.AppImage" cp "$appimage.sig" "out/LowMail-${VERSION}-linux-x64.AppImage.sig" diff --git a/Cargo.lock b/Cargo.lock index 4fd5e06..c55816b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2937,7 +2937,7 @@ checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" [[package]] name = "lowmail-core" -version = "0.2.1" +version = "0.2.2" dependencies = [ "ammonia", "anyhow", @@ -2970,7 +2970,7 @@ dependencies = [ [[package]] name = "lowmail-desktop" -version = "0.2.1" +version = "0.2.2" dependencies = [ "keyring", "lowmail-core", @@ -2997,7 +2997,7 @@ dependencies = [ [[package]] name = "lowmail-server" -version = "0.2.1" +version = "0.2.2" dependencies = [ "anyhow", "axum", @@ -3026,7 +3026,7 @@ dependencies = [ [[package]] name = "lowmail-testserver" -version = "0.2.1" +version = "0.2.2" dependencies = [ "anyhow", "async-imap", diff --git a/Cargo.toml b/Cargo.toml index a1c1bcb..06c6766 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/*", "src-tauri"] default-members = ["crates/*"] [workspace.package] -version = "0.2.1" +version = "0.2.2" edition = "2024" rust-version = "1.95" license = "AGPL-3.0-only" diff --git a/README.md b/README.md index 14fa32a..8b28738 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ bun run tauri android build --apk # Android (needs the Android SDK and NDK) The first start asks for the e-mail address and password; LowMail tries the usual host names (`imap.`, `mail.`, `smtp.`, the domain and its MX hosts) and ports, keeps the first server whose certificate is valid, checks the sign-in on IMAP and SMTP, and lets you adjust everything under **Server settings**. Passwords go to the Windows Credential Manager, the macOS Keychain or the Secret Service on Linux; on Android, to the app's private storage. -Installed desktop copies (Windows installers, the macOS app, AppImage) update themselves from signed GitHub releases; packages and portable copies show when a new version exists. +Installed desktop copies (Windows installers, the macOS app, AppImage, .deb and .rpm) update themselves from signed GitHub releases: the update downloads in the background and a restart installs it (.deb and .rpm ask for the administrator password). The Arch package and portable copies show when a new version exists. ## How it works diff --git a/package.json b/package.json index 9603c05..dca947a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lowmail", - "version": "0.2.1", + "version": "0.2.2", "description": "LowMail: a light e-mail client for your own mail server, on the desktop and in the browser.", "homepage": "https://github.com/LowBloat/LowMail", "repository": { diff --git a/src-tauri/src/updates.rs b/src-tauri/src/updates.rs index 0c1551c..ee5a540 100644 --- a/src-tauri/src/updates.rs +++ b/src-tauri/src/updates.rs @@ -1,9 +1,11 @@ //! Update policy: which installations can update themselves. //! -//! Windows installers (NSIS/MSI), macOS app bundles and writable AppImages -//! download the signed update, install it and restart. Linux packages -//! (.deb/.rpm/Arch) belong to the system package manager and portable copies -//! have no installer, so they are only told a new version exists. +//! Windows installers (NSIS/MSI), macOS app bundles, writable AppImages and +//! .deb/.rpm installs download the signed update, install it and restart. For +//! .deb and .rpm the updater hands the new package to dpkg/rpm through pkexec, +//! which asks for the administrator password. The Arch package (pacman owns +//! it) and portable copies have no installer, so they are only told a new +//! version exists. use serde::Serialize; @@ -35,12 +37,19 @@ impl UpdatePolicy { target: Some(format!("linux-{}-appimage", std::env::consts::ARCH)), }; } - let channel = match bundle { - Some(BundleType::Deb) => "deb", - Some(BundleType::Rpm) => "rpm", - _ if std::env::current_exe().is_ok_and(|p| p.starts_with("/usr") || p.starts_with("/opt")) => "package", - _ => "portable", + let exe = std::env::current_exe().ok(); + // The updater picks dpkg or rpm from the bundle type built into the + // binary; only trust it when that package manager really owns this + // file (a binary copied into the Arch package keeps a marker too). + let package = match bundle { + Some(BundleType::Deb) if exe.as_deref().is_some_and(|p| owned_by(p, "dpkg-query", "-S")) => Some("deb"), + Some(BundleType::Rpm) if exe.as_deref().is_some_and(|p| owned_by(p, "rpm", "-qf")) => Some("rpm"), + _ => None, }; + if let Some(channel) = package { + return Self { channel, can_install: true, target: Some(format!("linux-{}-{channel}", std::env::consts::ARCH)) }; + } + let channel = if exe.is_some_and(|p| p.starts_with("/usr") || p.starts_with("/opt")) { "package" } else { "portable" }; return Self { channel, can_install: false, target: None }; } @@ -51,6 +60,17 @@ impl UpdatePolicy { } } +/// Whether `program` (dpkg-query -S, rpm -qf) names a package that installed `path`. +fn owned_by(path: &std::path::Path, program: &str, flag: &str) -> bool { + std::process::Command::new(program) + .arg(flag) + .arg(path) + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .is_ok_and(|status| status.success()) +} + fn dir_is_writable(dir: &std::path::Path) -> bool { let probe = dir.join(format!(".lowmail-update-check-{}", std::process::id())); let ok = std::fs::write(&probe, b"").is_ok(); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index e3704a5..0cea649 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "LowMail", - "version": "0.2.1", + "version": "0.2.2", "identifier": "dev.lowbloat.lowmail", "build": { "beforeDevCommand": "bun run dev", diff --git a/src/lib/components/Shell.svelte b/src/lib/components/Shell.svelte index 8d95587..00e8e89 100644 --- a/src/lib/components/Shell.svelte +++ b/src/lib/components/Shell.svelte @@ -115,9 +115,9 @@ {/each}
- {#if updates.available} - - diff --git a/src/lib/components/desktop/UpdateDialog.svelte b/src/lib/components/desktop/UpdateDialog.svelte index 29e8982..0997768 100644 --- a/src/lib/components/desktop/UpdateDialog.svelte +++ b/src/lib/components/desktop/UpdateDialog.svelte @@ -66,6 +66,8 @@ {updates.manualHint} {:else if compose.active && !updates.installing} {t("updates.draftOpen")} + {:else if updates.ready && !updates.installing} + {t("updates.readyHint")} {/if} {#if updates.installing} updates.install()}> {#snippet leading()}{/snippet} - {t("updates.install")} + {updates.ready ? t("updates.restart") : t("updates.install")} {:else} + {#if updates.offered} + {:else} {/if} diff --git a/src/lib/i18n/en.ts b/src/lib/i18n/en.ts index a2a3aa4..29de0a7 100644 --- a/src/lib/i18n/en.ts +++ b/src/lib/i18n/en.ts @@ -587,8 +587,9 @@ export const en: Dict = { "updates.later": "Later", "updates.install": "Install and restart", "updates.download": "Download", - "updates.manual.deb": "Installed from a .deb package: download the new package or update it with your package manager.", - "updates.manual.rpm": "Installed from an .rpm package: download the new package or update it with your package manager.", + "updates.ready": "Restart to update to {version}", + "updates.readyHint": "The update is downloaded and verified. Restarting installs it.", + "updates.restart": "Restart now", "updates.manual.package": "Installed by the system package manager: update it there or download the new package.", "updates.manual.appimage": "This AppImage is in a read-only folder: download the new AppImage to replace it.", "updates.manual.portable": "Portable copy: download the new version and replace this one, or use the installer for automatic updates.", diff --git a/src/lib/i18n/pt.ts b/src/lib/i18n/pt.ts index 387c7ca..046e6f5 100644 --- a/src/lib/i18n/pt.ts +++ b/src/lib/i18n/pt.ts @@ -608,8 +608,9 @@ export const pt: Dict = { "updates.later": "Depois", "updates.install": "Instalar e reiniciar", "updates.download": "Baixar", - "updates.manual.deb": "Instalado por um pacote .deb: baixe o pacote novo ou atualize pelo gerenciador de pacotes.", - "updates.manual.rpm": "Instalado por um pacote .rpm: baixe o pacote novo ou atualize pelo gerenciador de pacotes.", + "updates.ready": "Reiniciar para atualizar para {version}", + "updates.readyHint": "A atualização já foi baixada e verificada. Ao reiniciar, ela é instalada.", + "updates.restart": "Reiniciar agora", "updates.manual.package": "Instalado pelo gerenciador de pacotes do sistema: atualize por ele ou baixe o pacote novo.", "updates.manual.appimage": "Este AppImage está numa pasta sem permissão de escrita: baixe o AppImage novo para substituí-lo.", "updates.manual.portable": "Cópia portátil: baixe a versão nova e substitua esta, ou use o instalador para receber atualizações automáticas.", diff --git a/src/lib/state/updates.svelte.ts b/src/lib/state/updates.svelte.ts index cee5769..c8d577b 100644 --- a/src/lib/state/updates.svelte.ts +++ b/src/lib/state/updates.svelte.ts @@ -1,6 +1,10 @@ /** - * Checks GitHub Releases for a signed update. Installed copies download, - * verify, install and restart; other formats get a download link. + * Automatic updates from GitHub Releases. The app checks shortly after it + * opens, every few minutes and whenever the window regains focus. A copy that + * can update itself (Windows installer, macOS app, writable AppImage, .deb or + * .rpm) downloads the signed update in the background; once it is verified and + * ready, the rail offers "restart to update", which installs it right away. + * Other formats (Arch package, portable copy) get a download link. */ import { invoke } from "@tauri-apps/api/core"; import { getVersion } from "@tauri-apps/api/app"; @@ -18,13 +22,19 @@ export interface UpdatePolicy { const RELEASES_URL = "https://github.com/LowBloat/LowMail/releases/latest"; const FIRST_CHECK_MS = 5_000; -const CHECK_EVERY_MS = 6 * 60 * 60 * 1000; +const CHECK_EVERY_MS = 10 * 60 * 1000; +/** Focus comes and goes quickly; at most one extra check per this long. */ +const FOCUS_GAP_MS = 2 * 60 * 1000; class Updates { currentVersion = $state(""); policy = $state(null); available = $state<{ version: string; notes: string } | null>(null); checking = $state(false); + /** Downloading in the background, before anyone asked. */ + downloading = $state(false); + /** Downloaded and verified: a restart installs it. */ + ready = $state(false); installing = $state(false); /** Download progress from 0 to 1, or null when the size is unknown. */ progress = $state(null); @@ -34,16 +44,29 @@ class Updates { upToDate = $state(false); private update: Update | null = null; private timer: ReturnType | undefined; + private lastCheck = 0; + private prefetching: Promise | null = null; /** Self-update exists in the desktop app only. */ get supported() { return isDesktop && !isMobile; } + /** The rail and Settings offer the update once it is ready (or when it is manual). */ + get offered(): boolean { + return this.available !== null && !this.downloading; + } + + /** "Restart to update" once downloaded, "Update to" otherwise. */ + get label(): string { + if (!this.available) return ""; + return t(this.ready ? "updates.ready" : "updates.available", { version: this.available.version }); + } + /** Why this copy cannot update itself, shown next to the download link. */ get manualHint(): string | null { if (!this.policy || this.policy.canInstall) return null; - const known = ["deb", "rpm", "package", "appimage"]; + const known = ["package", "appimage"]; return t(`updates.manual.${known.includes(this.policy.channel) ? this.policy.channel : "portable"}`); } @@ -55,24 +78,41 @@ class Updates { .catch(() => {}); setTimeout(() => this.check(false), FIRST_CHECK_MS); this.timer = setInterval(() => this.check(false), CHECK_EVERY_MS); + window.addEventListener("focus", () => { + if (Date.now() - this.lastCheck > FOCUS_GAP_MS) void this.check(false); + }); } /** `interactive`: the user asked, so report "up to date" and errors. */ async check(interactive: boolean): Promise { - if (!this.supported || this.checking || this.installing) return; + if (!this.supported || this.checking || this.downloading || this.installing) return; this.checking = true; - this.error = null; + this.lastCheck = Date.now(); + if (interactive) this.error = null; this.upToDate = false; try { this.policy ??= await invoke("update_policy"); - // Packages that cannot install still read the AppImage entry to learn + // Copies that cannot install still read the AppImage entry to learn // the version and notes. const target = this.policy.target ?? (this.policy.canInstall ? undefined : "linux-x86_64-appimage"); const update = await check(target ? { target } : undefined); + if (!update) { + this.update = null; + this.available = null; + this.ready = false; + if (interactive) this.upToDate = true; + return; + } + // Already downloaded this one: nothing to do until the restart. + if (this.ready && this.available?.version === update.version) { + if (interactive) this.dialogOpen = true; + return; + } this.update = update; - this.available = update ? { version: update.version, notes: update.body ?? "" } : null; - if (update && interactive) this.dialogOpen = true; - if (!update && interactive) this.upToDate = true; + this.ready = false; + this.available = { version: update.version, notes: update.body ?? "" }; + if (interactive) this.dialogOpen = true; + if (this.policy.canInstall) this.prefetching = this.prefetch(update); } catch { // GitHub unreachable, or no release yet: the updater's own text is technical. if (interactive) this.error = t("updates.checkFailed"); @@ -81,21 +121,53 @@ class Updates { } } - async install(): Promise { - if (!this.update || !this.policy?.canInstall) return; - this.installing = true; - this.error = null; + /** Downloads and verifies in the background; the rail changes once it is ready. */ + private async prefetch(update: Update): Promise { + this.downloading = true; this.progress = null; let total = 0; let received = 0; try { - await this.update.downloadAndInstall((event) => { + await update.download((event) => { if (event.event === "Started") total = event.data.contentLength ?? 0; else if (event.event === "Progress") { received += event.data.chunkLength; this.progress = total > 0 ? Math.min(1, received / total) : null; - } else if (event.event === "Finished") this.progress = 1; + } }); + if (this.update === update) this.ready = true; + } catch { + // The dialog falls back to download-and-install in one go. + } finally { + this.downloading = false; + this.prefetching = null; + if (!this.installing) this.progress = null; + } + } + + async install(): Promise { + const update = this.update; + if (!update || !this.policy?.canInstall || this.installing) return; + this.installing = true; + this.error = null; + try { + // Clicked while the background download runs: let it finish first. + if (this.prefetching) await this.prefetching; + if (this.ready) { + this.progress = 1; + await update.install(); + } else { + this.progress = null; + let total = 0; + let received = 0; + await update.downloadAndInstall((event) => { + if (event.event === "Started") total = event.data.contentLength ?? 0; + else if (event.event === "Progress") { + received += event.data.chunkLength; + this.progress = total > 0 ? Math.min(1, received / total) : null; + } else if (event.event === "Finished") this.progress = 1; + }); + } await relaunch(); } catch (e) { this.error = errorText(e);