feat: settings update panel with signed updater states
This commit is contained in:
parent
ef36812a8e
commit
b200598254
2 changed files with 278 additions and 0 deletions
|
|
@ -43,6 +43,7 @@ import {
|
|||
} from "./utils/tauriBridge";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { check as checkTauriUpdate } from "@tauri-apps/plugin-updater";
|
||||
import UpdatePanel from "./components/UpdatePanel";
|
||||
|
||||
const EMPTY_STATUS = {
|
||||
isConnected: false,
|
||||
|
|
@ -1158,6 +1159,7 @@ export default function App() {
|
|||
VPN açık. DPI ayarları kilitli; değiştirmek için önce VPN sekmesinden bağlantıyı kesin.
|
||||
</div>
|
||||
)}
|
||||
<UpdatePanel appVersion={appVersion} lang={lang} />
|
||||
<div className="order-1 px-1 text-[10px] font-semibold uppercase tracking-wider text-slate-500">
|
||||
{lang === "tr" ? "Genel" : "General"}
|
||||
</div>
|
||||
|
|
|
|||
276
src/components/UpdatePanel.jsx
Normal file
276
src/components/UpdatePanel.jsx
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
AlertTriangle,
|
||||
CheckCircle2,
|
||||
Download,
|
||||
Loader2,
|
||||
RefreshCw,
|
||||
ShieldCheck,
|
||||
} from "lucide-react";
|
||||
import { check } from "@tauri-apps/plugin-updater";
|
||||
import { invokeTauri } from "../utils/tauriBridge";
|
||||
|
||||
const T = {
|
||||
tr: {
|
||||
kicker: "Güncelleme",
|
||||
title: "Güncelleme Kontrolü",
|
||||
current: "Mevcut sürüm",
|
||||
check: "Güncellemeleri Kontrol Et",
|
||||
checking: "Güncellemeler kontrol ediliyor...",
|
||||
upToDate: "En son sürümdesiniz",
|
||||
available: "Yeni sürüm mevcut",
|
||||
published: "Yayın tarihi",
|
||||
notes: "Sürüm notları",
|
||||
install: "Hemen Güncelle",
|
||||
preparing: "Hazırlanıyor...",
|
||||
downloading: "İndiriliyor ve doğrulanıyor...",
|
||||
retry: "Tekrar Dene",
|
||||
failed: "Güncelleme kontrolü başarısız oldu.",
|
||||
installFailed: "Güncelleme indirilemedi veya doğrulanamadı.",
|
||||
signature: "Minisign imzası doğrulanmadan kurulum başlatılmaz.",
|
||||
latest: "En son sürüm",
|
||||
},
|
||||
en: {
|
||||
kicker: "Update",
|
||||
title: "Check for Updates",
|
||||
current: "Current version",
|
||||
check: "Check for Updates",
|
||||
checking: "Checking for updates...",
|
||||
upToDate: "You are on the latest version",
|
||||
available: "New version available",
|
||||
published: "Published",
|
||||
notes: "Release notes",
|
||||
install: "Update Now",
|
||||
preparing: "Preparing...",
|
||||
downloading: "Downloading and verifying...",
|
||||
retry: "Try Again",
|
||||
failed: "Update check failed.",
|
||||
installFailed: "The update could not be downloaded or verified.",
|
||||
signature: "Installation only starts after Minisign verification.",
|
||||
latest: "Latest version",
|
||||
},
|
||||
};
|
||||
|
||||
function fmtDate(value, lang) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
return date.toLocaleDateString(lang === "tr" ? "tr-TR" : "en-US", {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
function messageOf(error) {
|
||||
if (error instanceof Error) return error.message;
|
||||
return String(error || "unknown error");
|
||||
}
|
||||
|
||||
function Spinner() {
|
||||
return <Loader2 className="w-4 h-4 animate-spin" />;
|
||||
}
|
||||
|
||||
export default function UpdatePanel({ appVersion = "1.7.1", lang = "tr" }) {
|
||||
const t = T[lang] || T.tr;
|
||||
const [state, setState] = useState("idle");
|
||||
const [update, setUpdate] = useState(null);
|
||||
const [percent, setPercent] = useState(null);
|
||||
const [error, setError] = useState(null);
|
||||
const mounted = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
mounted.current = true;
|
||||
return () => {
|
||||
mounted.current = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const checkNow = async () => {
|
||||
setState("checking");
|
||||
setError(null);
|
||||
setPercent(null);
|
||||
try {
|
||||
const found = await check();
|
||||
if (!mounted.current) return;
|
||||
if (!found) {
|
||||
setUpdate(null);
|
||||
setState("current");
|
||||
return;
|
||||
}
|
||||
setUpdate(found);
|
||||
setState("available");
|
||||
} catch (e) {
|
||||
if (!mounted.current) return;
|
||||
setError(messageOf(e));
|
||||
setState("error");
|
||||
}
|
||||
};
|
||||
|
||||
const installNow = async () => {
|
||||
if (!update || state === "downloading") return;
|
||||
setState("downloading");
|
||||
setPercent(0);
|
||||
setError(null);
|
||||
try {
|
||||
// Stop SpoofDPI/VPN and clear loopback proxy before replacing files.
|
||||
await invokeTauri("prepare_for_update");
|
||||
|
||||
let total = 0;
|
||||
let downloaded = 0;
|
||||
await update.downloadAndInstall((event) => {
|
||||
if (!mounted.current) return;
|
||||
if (event.event === "Started") {
|
||||
total = event.data.contentLength || 0;
|
||||
setPercent(total ? 0 : null);
|
||||
} else if (event.event === "Progress") {
|
||||
downloaded += event.data.chunkLength || 0;
|
||||
setPercent(total ? Math.min(100, Math.round((downloaded / total) * 100)) : null);
|
||||
} else if (event.event === "Finished") {
|
||||
setPercent(100);
|
||||
}
|
||||
});
|
||||
|
||||
// On Windows the updater normally exits the app. If it returns, restart.
|
||||
await invokeTauri("restart_app");
|
||||
} catch (e) {
|
||||
if (!mounted.current) return;
|
||||
setError(messageOf(e));
|
||||
setState("error");
|
||||
}
|
||||
};
|
||||
|
||||
const busy = state === "checking" || state === "downloading";
|
||||
|
||||
return (
|
||||
<section className="order-0 mica-card rounded-2xl p-5 space-y-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex items-start gap-3 min-w-0">
|
||||
<div className="w-9 h-9 rounded-xl bg-cyan-500/10 border border-cyan-400/25 flex items-center justify-center shrink-0">
|
||||
<RefreshCw className="w-4 h-4 text-cyan-300" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<div className="text-[10px] font-semibold uppercase tracking-wider text-cyan-400/80">
|
||||
{t.kicker}
|
||||
</div>
|
||||
<h2 className="text-sm font-semibold text-slate-100">{t.title}</h2>
|
||||
<p className="text-[11px] text-slate-400 mt-0.5 flex items-center gap-1.5">
|
||||
<span className="font-mono text-slate-300">v{appVersion}</span>
|
||||
<span className="text-slate-600">·</span>
|
||||
<span>{t.current}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{state !== "available" && state !== "downloading" && (
|
||||
<button
|
||||
onClick={checkNow}
|
||||
disabled={busy}
|
||||
className="shrink-0 flex items-center gap-2 px-3 py-2 rounded-xl border border-slate-700/70 bg-slate-900/60 text-[11px] font-semibold text-slate-200 hover:border-cyan-400/40 hover:text-cyan-100 disabled:opacity-50"
|
||||
>
|
||||
{state === "checking" ? <Spinner /> : <RefreshCw className="w-3.5 h-3.5" />}
|
||||
{state === "checking" ? t.checking : state === "error" ? t.retry : t.check}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{state === "idle" && (
|
||||
<p className="text-[11px] text-slate-500 leading-relaxed">
|
||||
{lang === "tr"
|
||||
? "Sürüm kontrolü latest.json üzerinden yapılır. Güncellemeler Minisign ile doğrulanır."
|
||||
: "Updates are checked via latest.json and verified with Minisign."}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{state === "checking" && (
|
||||
<div className="flex items-center gap-2 text-[11px] text-cyan-200/80">
|
||||
<Spinner />
|
||||
{t.checking}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{state === "current" && (
|
||||
<div className="rounded-xl border border-emerald-500/25 bg-emerald-500/10 px-3 py-2.5 flex items-center gap-2 text-[11px] text-emerald-200">
|
||||
<CheckCircle2 className="w-4 h-4 shrink-0" />
|
||||
{t.upToDate} (v{appVersion})
|
||||
</div>
|
||||
)}
|
||||
|
||||
{state === "available" && update && (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-xl border border-cyan-400/30 bg-cyan-500/10 px-3 py-2.5 flex items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] font-semibold text-cyan-100">
|
||||
{t.available}: v{update.version}
|
||||
</div>
|
||||
{update.date && (
|
||||
<div className="text-[10px] text-cyan-200/60 mt-0.5">
|
||||
{t.published}: {fmtDate(update.date, lang)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={installNow}
|
||||
className="shrink-0 flex items-center gap-2 px-3 py-2 rounded-xl bg-cyan-500/20 border border-cyan-400/40 text-[11px] font-semibold text-cyan-100 hover:bg-cyan-500/30"
|
||||
>
|
||||
<Download className="w-3.5 h-3.5" />
|
||||
{t.install}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{update.body && (
|
||||
<div>
|
||||
<div className="text-[10px] uppercase tracking-wider text-slate-500 mb-1">
|
||||
{t.notes}
|
||||
</div>
|
||||
<pre className="max-h-28 overflow-auto whitespace-pre-wrap rounded-lg border border-slate-800 bg-slate-950/60 p-2.5 text-[10px] leading-relaxed text-slate-400 font-sans">
|
||||
{update.body}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-slate-500">
|
||||
<ShieldCheck className="w-3.5 h-3.5 text-emerald-400/80" />
|
||||
{t.signature}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{state === "downloading" && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-[11px] text-cyan-200/80">
|
||||
<span className="flex items-center gap-2">
|
||||
<Spinner />
|
||||
{t.downloading}
|
||||
</span>
|
||||
{percent !== null && <span className="font-mono">{percent}%</span>}
|
||||
</div>
|
||||
<div className="h-1.5 rounded-full bg-slate-800 overflow-hidden">
|
||||
<div
|
||||
className={`h-full rounded-full bg-cyan-400 transition-all duration-300 ${
|
||||
percent === null ? "w-1/3 animate-pulse" : ""
|
||||
}`}
|
||||
style={percent === null ? undefined : { width: `${percent}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{state === "error" && (
|
||||
<div className="rounded-xl border border-rose-500/30 bg-rose-500/10 px-3 py-2.5 space-y-1">
|
||||
<div className="flex items-center gap-2 text-[11px] font-semibold text-rose-200">
|
||||
<AlertTriangle className="w-4 h-4 shrink-0" />
|
||||
{error && error.toLowerCase().includes("verify") ? t.installFailed : t.failed}
|
||||
</div>
|
||||
<div className="text-[10px] text-rose-200/60 break-words">{error}</div>
|
||||
<button
|
||||
onClick={checkNow}
|
||||
className="text-[10px] font-semibold text-rose-200 underline underline-offset-2 hover:text-rose-100"
|
||||
>
|
||||
{t.retry}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue