Self-update in the background (install on close), module configs created from .dist, quiet-logging + table fixups in clean-base, backlog notes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-09-30 15:36:07 +05:00
1 parent 2d0bfd0a38
commit a6ae4e78a3
15 files changed
+358 -55

No files matched your search

+50 -53
View File
@@ -1,81 +1,78 @@
import { useEffect, useState } from "react";
import { getVersion } from "@tauri-apps/api/app";
import { check, type Update } from "@tauri-apps/plugin-updater";
import { relaunch } from "@tauri-apps/plugin-process";
import { Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { useT } from "@/i18n";
import { autoUpdateEnabled, installNow, lookForUpdate, setAutoUpdate, useSelfUpdate } from "@/lib/selfUpdate";
export function AboutCard() {
const t = useT();
const s = useSelfUpdate();
const [version, setVersion] = useState("");
const [update, setUpdate] = useState<Update | null>(null);
const [busy, setBusy] = useState<"check" | "install" | null>(null);
const [percent, setPercent] = useState<number | null>(null);
const [note, setNote] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
const [auto, setAuto] = useState(autoUpdateEnabled());
const [asked, setAsked] = useState(false);
useEffect(() => {
void getVersion().then(setVersion).catch(() => {});
}, []);
async function look() {
setBusy("check");
setError(null);
setNote(null);
try {
const u = await check();
setUpdate(u);
if (!u) setNote(t("about.upToDate"));
} catch {
setError(t("about.checkFailed"));
} finally {
setBusy(null);
}
}
async function install() {
if (!update) return;
setBusy("install");
setError(null);
let total = 0;
let done = 0;
try {
await update.downloadAndInstall((e) => {
if (e.event === "Started") total = e.data.contentLength ?? 0;
if (e.event === "Progress") {
done += e.data.chunkLength;
if (total) setPercent(Math.round((done / total) * 100));
}
});
await relaunch();
} catch {
setError(t("about.installFailed"));
setBusy(null);
}
}
const busy = s.phase === "checking" || s.phase === "downloading" || s.phase === "installing";
return (
<Card className="mt-6 p-6">
<h2 className="font-semibold">{t("app.name")}</h2>
<p className="mt-1 text-sm text-muted">{t("about.version", { v: version || "…" })}</p>
<div className="mt-4 flex items-center gap-3">
<Button size="sm" disabled={!!busy} onClick={() => void look()}>
{busy === "check" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
<label className="mt-3 flex cursor-pointer items-start gap-2 text-sm">
<input
type="checkbox"
className="mt-1"
checked={auto}
onChange={(e) => {
setAuto(e.target.checked);
setAutoUpdate(e.target.checked);
}}
/>
<span>
{t("about.auto")}
<span className="block text-xs text-muted">{t("about.autoHint")}</span>
</span>
</label>
<div className="mt-4 flex flex-wrap items-center gap-3">
<Button
size="sm"
disabled={busy}
onClick={() => {
setAsked(true);
void lookForUpdate({ download: false });
}}
>
{s.phase === "checking" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
{t("about.check")}
</Button>
{update && (
<Button size="sm" variant="primary" disabled={!!busy} onClick={() => void install()}>
{busy === "install" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
{t("about.install", { v: update.version })}
{s.version && s.phase !== "current" && (
<Button size="sm" variant="primary" disabled={busy} onClick={() => void installNow()}>
{(s.phase === "downloading" || s.phase === "installing") && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
{t("about.install", { v: s.version })}
</Button>
)}
{percent !== null && busy === "install" && <span className="text-sm text-muted" role="status">{percent}%</span>}
{s.percent !== null && s.phase === "downloading" && (
<span className="text-sm text-muted" role="status">
{s.percent}%
</span>
)}
</div>
{update?.body && <p className="mt-3 whitespace-pre-line text-sm text-muted">{update.body}</p>}
{note && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
{s.version && s.notes && s.phase !== "current" && <p className="mt-3 whitespace-pre-line text-sm text-muted">{s.notes}</p>}
{s.phase === "ready" && <p className="mt-3 text-sm text-ok" role="status">{t("selfupd.onClose")}</p>}
{asked && s.phase === "current" && <p className="mt-3 text-sm text-ok" role="status">{t("about.upToDate")}</p>}
{s.phase === "error" && (
<div className="mt-3 text-sm text-bad" role="alert">
<p>{t("about.checkFailed")}</p>
{s.error && <p className="selectable mt-1 break-all text-xs text-muted">{s.error}</p>}
</div>
)}
</Card>
);
}