diff --git a/apps/app/src/desktop/UpdateNotice.tsx b/apps/app/src/desktop/UpdateNotice.tsx index 060906b..f80b605 100644 --- a/apps/app/src/desktop/UpdateNotice.tsx +++ b/apps/app/src/desktop/UpdateNotice.tsx @@ -9,7 +9,8 @@ interface UpdateInfo { notes: string | null; } -const EVERY_MS = 6 * 3600_000; +/** How often an open app looks again. A new shell installs itself; this only has to notice it soon. */ +const EVERY_MS = 60_000; type Listen = (event: string, handler: () => void) => Promise<() => void>; @@ -98,9 +99,9 @@ export async function askServer(apiUrl = API_URL): Promise const message = (err: unknown) => (err instanceof Error ? err.message : String(err)); /** - * Desktop only: a new version of the app's shell, installed with one click (it restarts). When the installed shell - * cannot do that (its own check fails, or it was built without the update key), the page asks the server itself and - * offers the full installer instead, with the reason, so an update is never missed in silence. + * Desktop only: a new version of the app's shell installs itself and restarts. When the installed shell cannot do + * that (its own check fails, or it was built without the update key), the page asks the server itself and offers + * the full installer instead, with the reason, so an update is never missed in silence. */ export function UpdateNotice({ invoke = desktopInvoke, @@ -118,18 +119,32 @@ export function UpdateNotice({ const [state, setState] = useState<"idle" | "installing" | "failed">("idle"); const [error, setError] = useState(null); const [dismissed, setDismissed] = useState(false); + const started = useRef(false); useEffect(() => { if (!enabled) return; let alive = true; + const install = (found: UpdateInfo) => { + setUpdate(found); + setManual(null); + if (started.current) return; + started.current = true; + setState("installing"); + setError(null); + invoke("update_install").catch((err: unknown) => { + if (!alive) return; + started.current = false; + setState("failed"); + setError(message(err)); + }); + }; const check = async () => { let reason: string | null = null; try { const found = await invoke("update_check"); if (!alive) return; if (found) { - setUpdate(found); - setManual(null); + install(found); return; } } catch (err) { @@ -156,20 +171,26 @@ export function UpdateNotice({
{t.update.available(update.version, update.currentVersion)} {update.notes && {update.notes}} - + {state === "failed" ? ( + + ) : ( + {t.update.installing} + )} {state === "failed" && ( {t.update.failed} diff --git a/apps/app/src/desktop/desktop.test.tsx b/apps/app/src/desktop/desktop.test.tsx index ff5a4e1..ab80ad4 100644 --- a/apps/app/src/desktop/desktop.test.tsx +++ b/apps/app/src/desktop/desktop.test.tsx @@ -64,12 +64,11 @@ describe("interface update notice", () => { }); describe("update notice", () => { - it("offers a newer shell and installs it", async () => { + it("installs a newer shell as soon as it finds one", async () => { const invoke = vi.fn(async (cmd: string) => (cmd === "update_check" ? { version: "0.3.0", currentVersion: "0.2.0", notes: "Catálogo local" } : null)) as unknown as Invoke; render( null} />); expect(await screen.findByText("Nova versão da app: 0.3.0 (tens a 0.2.0).")).toBeTruthy(); - fireEvent.click(screen.getByText("Instalar e reiniciar")); - expect(invoke).toHaveBeenCalledWith("update_install"); + await waitFor(() => expect(invoke).toHaveBeenCalledWith("update_install")); }); it("offers the installer when the app cannot update itself, with the reason", async () => { diff --git a/apps/app/src/i18n.ts b/apps/app/src/i18n.ts index c028332..4decd2d 100644 --- a/apps/app/src/i18n.ts +++ b/apps/app/src/i18n.ts @@ -879,7 +879,7 @@ export const t = { update: { available: (v: string, current: string) => `Nova versão da app: ${v} (tens a ${current}).`, install: "Instalar e reiniciar", - installing: "A instalar…", + installing: "A instalar a nova versão. A app reinicia sozinha.", failed: "Não foi possível instalar. Tenta mais tarde.", manual: "Esta instalação não se atualiza sozinha: descarrega o instalador e abre-o (só desta vez).", download: "Descarregar instalador", diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 8b5564b..ebc0c04 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -19,7 +19,7 @@ What the shell adds today: - Works without network: when the server can't be reached at start-up, the window opens the copy of the web app bundled in the installer (photo engine included), so the catalogue, local FTP and editing originals on disk go on; edits wait in the offline queue. -- Updates itself (`src/updater.rs`): a notice offers each new shell version; one click installs it and restarts. +- Updates itself (`src/updater.rs`): a new shell version installs itself and the app restarts. Replaces `PhotoReport_Studio` (Flutter) and the archived `bridge.photoreport.pt`. @@ -35,7 +35,8 @@ are in the app's config folder (`catalog.json`, `catalog-cache.json`, `local-ind ## Updates The web app inside the window updates with every web deploy. The shell checks -`/v1/desktop/update/{target}/{arch}/{version}` at start and every 6 hours; the API reads the latest +`/v1/desktop/update/{target}/{arch}/{version}` at start and about once a minute, and installs a newer +signed shell at once; the API reads the latest `desktop-v*` release on Gitea (`DESKTOP_RELEASES_API`, `DESKTOP_RELEASES_TOKEN`, read-only) and passes the installer through, so the private repository stays private. Installers are signed with the release key (`tauri signer generate`): the private key and its password are the Gitea secrets `TAURI_SIGNING_PRIVATE_KEY` and diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 9dfab3e..c566921 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -1,6 +1,6 @@ { "name": "@photoreport/desktop", - "version": "0.3.31", + "version": "0.3.32", "private": true, "type": "module", "scripts": { diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 26031a5..45a918a 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "photoreport-desktop" -version = "0.3.31" +version = "0.3.32" edition = "2024" publish = false description = "PhotoReport desktop: the web app in a native shell, with keychain sign-in and (later) local FTP and the native engine." diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.json index 2e8e254..cc4ac5c 100644 --- a/apps/desktop/src-tauri/tauri.conf.json +++ b/apps/desktop/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "PhotoReport", - "version": "0.3.31", + "version": "0.3.32", "identifier": "pt.photoreport.desktop", "build": { "devUrl": "http://localhost:5173",