diff --git a/src/App.jsx b/src/App.jsx index 29e1c9d..58659ee 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -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. )} +
{lang === "tr" ? "Genel" : "General"}
diff --git a/src/components/UpdatePanel.jsx b/src/components/UpdatePanel.jsx new file mode 100644 index 0000000..2e04dca --- /dev/null +++ b/src/components/UpdatePanel.jsx @@ -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 ; +} + +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 ( +
+
+
+
+ +
+
+
+ {t.kicker} +
+

{t.title}

+

+ v{appVersion} + · + {t.current} +

+
+
+ + {state !== "available" && state !== "downloading" && ( + + )} +
+ + {state === "idle" && ( +

+ {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."} +

+ )} + + {state === "checking" && ( +
+ + {t.checking} +
+ )} + + {state === "current" && ( +
+ + {t.upToDate} (v{appVersion}) +
+ )} + + {state === "available" && update && ( +
+
+
+
+ {t.available}: v{update.version} +
+ {update.date && ( +
+ {t.published}: {fmtDate(update.date, lang)} +
+ )} +
+ +
+ + {update.body && ( +
+
+ {t.notes} +
+
+                {update.body}
+              
+
+ )} + +
+ + {t.signature} +
+
+ )} + + {state === "downloading" && ( +
+
+ + + {t.downloading} + + {percent !== null && {percent}%} +
+
+
+
+
+ )} + + {state === "error" && ( +
+
+ + {error && error.toLowerCase().includes("verify") ? t.installFailed : t.failed} +
+
{error}
+ +
+ )} +
+ ); +}