import { useEffect, useState, useCallback } from "react";
import {
checkForAppUpdate,
installAppUpdate,
skipUpdateVersion,
getLastUpdateCheck,
formatLastCheck,
isTauri,
} from "../utils/updater.js";
function Section({ title, children }) {
return (
);
}
export default function UpdatesSupport({ fallbackVersion }) {
const [version, setVersion] = useState(fallbackVersion || "");
const [lastCheck, setLastCheck] = useState(() => getLastUpdateCheck());
const [state, setState] = useState("idle");
const [update, setUpdate] = useState(null);
const [error, setError] = useState(null);
const [downloaded, setDownloaded] = useState(0);
const [total, setTotal] = useState(0);
useEffect(() => {
if (!isTauri()) return;
import("@tauri-apps/api/app").then(({ getVersion }) => {
getVersion().then(setVersion).catch(() => {});
});
}, []);
const runCheck = useCallback(async () => {
setError(null);
if (!isTauri()) {
setState("not-tauri");
return;
}
setState("checking");
try {
const res = await checkForAppUpdate({ respectSkip: false });
setLastCheck(getLastUpdateCheck());
if (res.available) {
setUpdate(res.update);
setState("available");
} else {
setUpdate(null);
setState("no-update");
}
} catch (e) {
console.error("Update-Check fehlgeschlagen:", e);
setError(String(e?.message || e));
setState("idle");
}
}, []);
const install = async () => {
if (!update) return;
setError(null);
try {
setState("downloading");
setDownloaded(0);
setTotal(0);
await installAppUpdate(update, (event) => {
if (event.event === "Started") {
setTotal(event.data.contentLength || 0);
} else if (event.event === "Progress") {
setDownloaded((d) => d + (event.data.chunkLength || 0));
} else if (event.event === "Finished") {
setState("installing");
}
});
} catch (e) {
console.error("Update-Installation fehlgeschlagen:", e);
setError(String(e?.message || e));
setState("available");
}
};
const skipVersion = () => {
skipUpdateVersion(update?.version);
setUpdate(null);
setState("idle");
};
const isBusy = state === "downloading" || state === "installing";
const pct = total > 0 ? Math.min(100, Math.round((downloaded / total) * 100)) : null;
return (
Aktuelle Version
{version || "—"}
Letzte Prüfung
{formatLastCheck(lastCheck)}
{state === "no-update" && (
✓ Rapport ist auf dem neuesten Stand.
)}
{state === "available" && update && (
UPDATE VERFÜGBAR
Rapport {update.version}
{update.body && (
{update.body}
)}
)}
{isBusy && (
{state === "downloading"
? (pct !== null ? `Wird heruntergeladen … ${pct}%` : "Wird heruntergeladen …")
: "Wird installiert …"}
)}
{state === "not-tauri" && (
Updates sind nur in der Desktop-App verfügbar.
)}
{error && (
{error}
)}
Updates werden automatisch beim Start der App geprüft. Hier kannst du manuell suchen — z.B. wenn die App selten geschlossen wird.
Anleitungen, Dokumentation und Support findest du auf der offiziellen Website:
rapport.kgva.ch ↗
Dort findest du auch das Changelog, Fehlerberichte und Kontaktmöglichkeiten für direkten Support.
);
}