mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-22 11:25:56 +00:00
Integrate settings and release history for Manager 0.9.4
This commit is contained in:
commit
dad10d8a5d
38 files changed
+2298
-372
No files matched your search
+11
-33
@@ -1,12 +1,12 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { getVersion } from "@tauri-apps/api/app";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { Loader2, RefreshCw, Monitor } 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() {
|
||||
export function AboutCard({ onHistory }: { onHistory?: () => void }) {
|
||||
const t = useT();
|
||||
const s = useSelfUpdate();
|
||||
const [version, setVersion] = useState("");
|
||||
@@ -21,37 +21,12 @@ export function AboutCard() {
|
||||
|
||||
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>
|
||||
|
||||
<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="flex items-start justify-between gap-3">
|
||||
<div><h2 className="flex items-center gap-2 font-semibold"><Monitor className="h-4 w-4 text-gold" aria-hidden />{t("history.manager")}</h2><p className="mt-2 text-sm text-muted">{t("settings.version", { v: version || "…" })}</p></div>
|
||||
<Button size="sm" disabled={busy} aria-label={t("about.check")} title={t("about.check")} onClick={() => { setAsked(true); void lookForUpdate({ download: false }); }}><RefreshCw className={`h-4 w-4 ${s.phase === "checking" ? "animate-spin" : ""}`} aria-hidden /></Button>
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted">{t("about.autoHint")}</p>
|
||||
<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>
|
||||
{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 />}
|
||||
@@ -64,7 +39,7 @@ export function AboutCard() {
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{s.version && s.notes && s.phase !== "current" && <p className="mt-3 whitespace-pre-line text-sm text-muted">{s.notes}</p>}
|
||||
{onHistory ? <button className="mt-3 cursor-pointer text-sm text-gold hover:underline" onClick={onHistory}>{t(s.version && s.phase !== "current" ? "history.open" : "history.title")}</button> : 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" && (
|
||||
@@ -73,6 +48,9 @@ export function AboutCard() {
|
||||
{s.error && <p className="selectable mt-1 break-all text-xs text-muted">{s.error}</p>}
|
||||
</div>
|
||||
)}
|
||||
<label className="mt-5 flex cursor-pointer items-center justify-between gap-3 border-t border-line pt-4 text-sm" title={t("about.auto")}>
|
||||
<span>{t("settings.autoManager")}</span><input type="checkbox" role="switch" aria-description={t("about.auto")} checked={auto} onChange={e => { setAuto(e.target.checked); setAutoUpdate(e.target.checked); }} className="h-4 w-4 accent-[#c9a24a]" />
|
||||
</label>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
+13
-26
@@ -15,6 +15,7 @@ import { PublishRealmDialog } from "@/screens/PublishDialog";
|
||||
import { useRegistryStatus } from "@/lib/registry";
|
||||
import { usePublishRealms, type PublishRealm } from "@/lib/publishRealms";
|
||||
import { useAutoRestart } from "@/lib/autoRestartPrefs";
|
||||
import { SplitButton } from "@/components/ui/split-button";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
@@ -410,32 +411,21 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
|
||||
<div className="mt-7 flex flex-wrap items-center gap-x-4 gap-y-3">
|
||||
{running ? (
|
||||
<Button variant="secondary" size="xl" disabled={transitioning} onClick={() => run("stopping")} className="min-w-56">
|
||||
<Button variant="secondary" size="xl" disabled={transitioning} onClick={() => run("stopping")} className="min-w-40">
|
||||
{transitioning && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
{t("btn.stop")}
|
||||
</Button>
|
||||
) : upd.available ? (
|
||||
<Button
|
||||
variant="primary"
|
||||
size="xl"
|
||||
disabled={transitioning || upd.applying}
|
||||
onClick={() => (needsDecision ? onOpenUpdates() : void runServerUpdate())}
|
||||
className="min-w-56"
|
||||
>
|
||||
{upd.applying && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
{upd.applying ? t("btn.updating") : needsDecision ? t("overview.openUpdates") : t("btn.update")}
|
||||
</Button>
|
||||
<SplitButton label={t("overview.server")}
|
||||
primary={{ disabled: transitioning || upd.applying, onClick: () => (needsDecision ? onOpenUpdates() : void runServerUpdate()), children: <>{upd.applying && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{upd.applying ? t("btn.updating") : needsDecision ? t("overview.openUpdates") : t("btn.update")}</> }}
|
||||
secondary={{ disabled: transitioning || upd.applying, onClick: () => run("starting"), children: t("btn.startWithoutUpdate") }}
|
||||
/>
|
||||
) : (
|
||||
<Button variant="primary" size="xl" disabled={transitioning} onClick={() => run("starting")} className="min-w-56">
|
||||
<Button variant="primary" size="xl" disabled={transitioning} onClick={() => run("starting")} className="min-w-40">
|
||||
{transitioning && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
{transitioning ? (action === "stopping" ? t("btn.stoppingCaps") : t("btn.startingCaps")) : t("btn.start")}
|
||||
</Button>
|
||||
)}
|
||||
{!running && upd.available && (
|
||||
<Button variant="secondary" size="sm" disabled={transitioning || upd.applying} onClick={() => run("starting")}>
|
||||
{t("btn.startWithoutUpdate")}
|
||||
</Button>
|
||||
)}
|
||||
{running && (
|
||||
<Button variant="ghost" size="sm" disabled={transitioning || upd.applying} onClick={() => run("restarting")}>
|
||||
{t("btn.restart")}
|
||||
@@ -456,7 +446,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
{client && <RealmlistMenu serverId={server.id} />}
|
||||
{client && jobBusy ? (
|
||||
<div
|
||||
className="relative flex h-16 min-w-64 items-center overflow-hidden rounded-md border border-gold/50 bg-card-2"
|
||||
className="relative flex h-12 min-w-64 items-center overflow-hidden rounded-md border border-gold/50 bg-card-2"
|
||||
role="progressbar"
|
||||
aria-valuenow={jobPct}
|
||||
aria-valuemin={0}
|
||||
@@ -482,9 +472,10 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
</button>
|
||||
</div>
|
||||
) : client && (clientStatus?.update_available || job.phase === "choose") ? (
|
||||
<Button variant="primary" size="xl" disabled={playing || job.phase === "choose"} onClick={() => void startClientUpdate(server.id)} className="min-w-40">
|
||||
{t("btn.updateClient")}
|
||||
</Button>
|
||||
<SplitButton label={t("btn.play")}
|
||||
primary={{ disabled: playing || job.phase === "choose", onClick: () => void startClientUpdate(server.id), children: t("btn.updateClient") }}
|
||||
secondary={{ disabled: realmBusy || playing || upd.applying, onClick: () => void play(), children: <>{playing && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("btn.playWithoutUpdate")}</> }}
|
||||
/>
|
||||
) : client ? (
|
||||
<Button variant="primary" size="xl" disabled={realmBusy || playing} onClick={() => void play()} className="min-w-40">
|
||||
{playing && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
@@ -495,11 +486,6 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
{t("btn.setupClient")}
|
||||
</Button>
|
||||
) : null}
|
||||
{client && !jobBusy && (clientStatus?.update_available || job.phase === "choose") && (
|
||||
<Button variant="secondary" size="sm" disabled={realmBusy || playing || upd.applying} onClick={() => void play()}>
|
||||
{t("btn.playWithoutUpdate")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-6 flex flex-wrap items-center justify-between gap-3 border-t border-line/60 pt-4 text-xs text-muted">
|
||||
@@ -559,6 +545,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
<div className="mt-4 rounded-md border border-gold/40 bg-gold/5 p-3 text-sm">
|
||||
<p>{t("overview.updateAvail", { to: upd.preview.to_version, from: upd.preview.from_version ?? "?" })}</p>
|
||||
{upd.preview.latest_version && <p>{t("upd.intermediate", { to: upd.preview.to_version, latest: upd.preview.latest_version })}</p>}
|
||||
<button className="mt-2 cursor-pointer text-gold hover:underline" onClick={onOpenUpdates}>{t("history.open")}</button>
|
||||
{needsDecision && <p className="mt-1 text-muted">{t("overview.updateConflicts")}</p>}
|
||||
{upd.applying && (
|
||||
<div className="mt-2">
|
||||
|
||||
@@ -2,10 +2,11 @@ import { useState } from "react";
|
||||
import { Globe, Network } from "lucide-react";
|
||||
import { useT } from "@/i18n";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { PublishCard } from "./PublishCard";
|
||||
import { BrowsePage } from "@/screens/BrowsePage";
|
||||
import { FriendsPage } from "@/screens/FriendsPage";
|
||||
|
||||
export function PlayWithFriends({ serverId }: { serverId: string; path?: string }) {
|
||||
export function PlayWithFriends({ serverId, serverName = "" }: { serverId: string; serverName?: string; path?: string }) {
|
||||
const t = useT();
|
||||
const [tab, setTab] = useState<"servers" | "lan">("servers");
|
||||
|
||||
@@ -38,7 +39,7 @@ export function PlayWithFriends({ serverId }: { serverId: string; path?: string
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{tab === "servers" && <BrowsePage />}
|
||||
{tab === "servers" && <><PublishCard serverId={serverId} serverName={serverName} /><BrowsePage /></>}
|
||||
{tab === "lan" && <FriendsPage serverId={serverId} />}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ export function RealmStartupSettings({ serverId }: { serverId: string }) {
|
||||
{view?.with_reborn && <p className="mt-1 text-sm text-muted">{t("realm.rebornPort", { port: view.reborn_world_port ?? "—" })}</p>}
|
||||
{view && view.active !== "coa" && !view.with_reborn && <p className="mt-1 text-sm text-warn">{t("realm.rebornNeedsCoa")}</p>}
|
||||
{view?.simultaneous && view.with_reborn && <p className="mt-3 text-sm">{t("realm.allThree")}</p>}
|
||||
<p className="mt-3 text-sm text-muted">{t("realm.simultaneousHint")}</p>
|
||||
<details className="mt-4 text-sm text-muted"><summary className="cursor-pointer">{t("settings.startupHelp")}</summary><p className="mt-2 leading-relaxed">{t("realm.simultaneousHint")}</p></details>
|
||||
{busy && <p className="mt-2 text-sm" role="status">{t("realm.preparing")}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
|
||||
</Card>;
|
||||
|
||||
@@ -92,7 +92,7 @@ export function RealmlistMenu({ serverId, className }: { serverId: string; class
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={open}
|
||||
className="flex h-16 cursor-pointer items-center gap-3 rounded-md border border-line bg-card-2 px-4 text-left transition-colors hover:border-gold/50"
|
||||
className="flex h-12 cursor-pointer items-center gap-3 rounded-md border border-line bg-card-2 px-4 text-left transition-colors hover:border-gold/50"
|
||||
>
|
||||
<span>
|
||||
<span className="block text-[11px] uppercase tracking-wide text-muted">{t("realm.label")}</span>
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { getVersion } from "@tauri-apps/api/app";
|
||||
import { useI18n, LOCALES, type Locale } from "@/i18n";
|
||||
import { useSelfUpdate } from "@/lib/selfUpdate";
|
||||
import { bundledHistories, compareVersions, releasesForUpdate, repositories, translatedNotes, type Component, type History } from "@/lib/releaseHistory";
|
||||
import { api } from "@/lib/api";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export interface HistorySelection { component: Component; from?: string; to?: string }
|
||||
export function ReleaseHistory({ selection, onSelect }: { selection: HistorySelection; onSelect: (selection: HistorySelection) => void }) {
|
||||
const { locale, t } = useI18n();
|
||||
const [language, setLanguage] = useState<Locale>(locale);
|
||||
const [feeds, setFeeds] = useState(bundledHistories);
|
||||
const [fresh, setFresh] = useState<Partial<Record<Component, boolean>>>({});
|
||||
const [mode, setMode] = useState<"all" | "range">("all");
|
||||
const [selected, setSelected] = useState("");
|
||||
const [installed, setInstalled] = useState<string>();
|
||||
const updater = useSelfUpdate();
|
||||
const { component } = selection;
|
||||
const lastServer = useRef<HistorySelection>({ component: "server" });
|
||||
const [linkError, setLinkError] = useState<string>();
|
||||
useEffect(() => { if (component === "server") lastServer.current = selection; setLinkError(undefined); }, [selection, component]);
|
||||
const target = component === "manager" ? updater.version : selection.to;
|
||||
const from = component === "manager" ? installed : selection.from;
|
||||
useEffect(() => setLanguage(locale), [locale]);
|
||||
useEffect(() => { void getVersion().then(setInstalled).catch(() => {}); }, []);
|
||||
useEffect(() => {
|
||||
setSelected("");
|
||||
setMode(selection.to || (component === "manager" && updater.version) ? "range" : "all");
|
||||
}, [selection, component, updater.version]);
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
void invoke<History>("release_history", { component }).then(feed => {
|
||||
if (live && feed.component === component && Array.isArray(feed.releases)) {
|
||||
setFeeds(previous => ({ ...previous, [component]: feed }));
|
||||
setFresh(previous => ({ ...previous, [component]: feed.source === "remote" }));
|
||||
}
|
||||
}).catch(() => {}); // Bundled reviewed notes remain visible offline.
|
||||
return () => { live = false; };
|
||||
}, [component]);
|
||||
const releases = [...(mode === "range" ? releasesForUpdate(feeds[component].releases, from, target) : feeds[component].releases)]
|
||||
.sort((a, b) => compareVersions(b.version.split("-")[0], a.version.split("-")[0]) || b.date.localeCompare(a.date));
|
||||
const record = releases.find(r => r.version === selected) ?? releases[0];
|
||||
const notes = record ? translatedNotes(component, record, language) : undefined;
|
||||
return <Card id="release-history" tabIndex={-1} className="mt-6 scroll-mt-4 overflow-hidden">
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 border-b border-line p-5">
|
||||
<h2 className="font-semibold">{t("history.title")}</h2>
|
||||
<div className="flex rounded-md border border-line p-1" aria-label={t("history.title")}>
|
||||
{(["server", "manager"] as const).map(c => <button key={c} aria-pressed={component === c} onClick={() => onSelect(c === "server" ? lastServer.current : { component: c })} className={`cursor-pointer rounded px-3 py-1.5 text-sm ${component === c ? "bg-gold/10 text-gold" : "text-muted hover:text-ink"}`}>{t(`history.${c}`)}</button>)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-line px-5 py-3 text-sm">
|
||||
<div className="flex gap-3">
|
||||
<button className={mode === "all" ? "text-gold" : "cursor-pointer text-muted"} aria-pressed={mode === "all"} onClick={() => setMode("all")}>{t("history.all")}</button>
|
||||
{target && <button className={mode === "range" ? "text-gold" : "cursor-pointer text-muted"} aria-pressed={mode === "range"} onClick={() => setMode("range")}>{t("history.range")}{from ? ` · ${from} → ${target}` : ` · ${target}`}</button>}
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-muted">{t("history.language")}<select value={language} onChange={e => setLanguage(e.target.value as Locale)} className="rounded border border-line bg-panel px-2 py-1 text-ink">{LOCALES.map(l => <option key={l.id} value={l.id}>{l.name}</option>)}</select></label>
|
||||
</div>
|
||||
<div className="grid min-h-64 md:grid-cols-[180px_1fr]">
|
||||
<div className="flex max-h-96 gap-1 overflow-auto border-b border-line p-3 md:block md:border-r md:border-b-0" aria-label={t("history.all")}>
|
||||
{releases.map(r => <button key={r.tag} aria-pressed={r.version === record?.version} onClick={() => setSelected(r.version)} className={`mb-1 block shrink-0 cursor-pointer rounded-md px-3 py-2 text-left text-sm md:w-full ${r.version === record?.version ? "bg-gold/10 text-gold" : "text-muted hover:bg-white/5"}`}><span className="block font-medium">{r.version}</span><span className="text-xs text-muted">{r.date}{r.prerelease ? " · Pre-release" : ""}</span></button>)}
|
||||
</div>
|
||||
<div className="min-w-0 p-5" aria-live="polite">
|
||||
{record && notes ? <><h3 className="text-lg font-semibold">{t(`history.${component}`)} {record.version}</h3>
|
||||
{notes.fallback && <p className="mt-2 text-xs text-warn">{t("history.fallback")}</p>}
|
||||
<ul lang={notes.fallback ? "en" : language} className="mt-4 list-disc space-y-2 pl-5 text-sm leading-relaxed">{notes.notes.map((note, i) => <li key={i}>{note}</li>)}</ul>
|
||||
{record.experimentalFeatures?.includes("portable-characters") && <p className="mt-4 rounded border border-warn/30 p-3 text-sm text-warn">{t("history.experimental")}</p>}
|
||||
<a className="mt-5 inline-block text-sm text-gold hover:underline" href={`https://github.com/${repositories[component]}/releases/tag/${encodeURIComponent(record.tag)}`} onClick={e => { e.preventDefault(); void api.openLink(e.currentTarget.href).catch(error => setLinkError(String(error))); }}>GitHub ↗</a>
|
||||
{linkError && <p className="mt-2 break-words text-xs text-bad" role="alert">{linkError}</p>}
|
||||
</> : <p className="text-sm text-muted">{t("history.empty")}</p>}
|
||||
</div>
|
||||
</div>
|
||||
<p className="border-t border-line px-5 py-3 text-xs text-muted">{fresh[component] ? t("history.refreshed") : t("history.offline")}</p>
|
||||
</Card>;
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { ChevronDown, ChevronRight, Loader2, RefreshCw, Server } from "lucide-react";
|
||||
import { applyServerUpdate, clearServerUpdateResult, refreshServerUpdateState, useServerUpdate } from "@/lib/serverUpdate";
|
||||
import { isUpdateCurrent } from "@/lib/serverUpdateStatus";
|
||||
import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useStartAfterUpdate } from "@/lib/updatePrefs";
|
||||
import { hasKey, useHuman, useI18n, type Key } from "@/i18n";
|
||||
|
||||
function mb(bytes: number) {
|
||||
return bytes >= 1 << 20 ? `${(bytes / (1 << 20)).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
||||
}
|
||||
|
||||
export function ServerUpdateCard({ serverId, onHistory, onAttention }: { serverId: string; onHistory: (from?: string | null, to?: string) => void; onAttention: (value: boolean) => void }) {
|
||||
const { t } = useI18n();
|
||||
const upd = useServerUpdate(serverId);
|
||||
const human = useHuman();
|
||||
const [preview, setPreview] = useState<UpdatePreview | null>(upd.preview);
|
||||
const [pending, setPending] = useState<UpdateTxn | null>(null);
|
||||
const [pendingChecked, setPendingChecked] = useState(false);
|
||||
const [pendingStateError, setPendingStateError] = useState<UiError | null>(null);
|
||||
const [localBusy, setBusy] = useState<"check" | "rollback" | "retry" | null>(null);
|
||||
// an update keeps running in the background when this tab is left, so its state is the shared one
|
||||
const busy = upd.applying ? "update" : localBusy;
|
||||
const progress = upd.applying ? { step: upd.step ?? "Starting", percent: upd.percent } : null;
|
||||
const [localError, setError] = useState<UiError | null>(null);
|
||||
const error = pendingStateError ?? localError ?? upd.uiError;
|
||||
const [localDone, setDone] = useState<string | null>(null);
|
||||
const done = upd.result && "committed" in upd.result ? t("upd.updatedTo", { v: upd.result.committed }) : localDone;
|
||||
const [choices, setChoices] = useState<Record<string, "keep" | "replace">>(() => Object.fromEntries((upd.preview?.conflicts ?? []).map(c => [c, "keep" as const])));
|
||||
const [advanced, setAdvanced] = useState(false);
|
||||
const [source, setSource] = useState("");
|
||||
const [startAfter, setStartAfter] = useStartAfterUpdate("server", serverId);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
setPendingChecked(false);
|
||||
setPending(null);
|
||||
setPendingStateError(null);
|
||||
void api.pendingUpdate(serverId).then((txn) => {
|
||||
if (active) { setPending(txn); setPendingChecked(true); }
|
||||
}).catch((e) => { if (active) setPendingStateError(asUiError(e)); });
|
||||
return () => { active = false; };
|
||||
}, [serverId]);
|
||||
|
||||
// Every finished attempt refreshes the disk state, including failures in the background.
|
||||
useEffect(() => {
|
||||
if (!upd.stateRevision) return;
|
||||
setPreview(null);
|
||||
setPendingChecked(!upd.stateError);
|
||||
setPendingStateError(upd.stateError);
|
||||
if (!upd.stateError) setPending(upd.result && "pending" in upd.result ? upd.result.pending : null);
|
||||
}, [upd.stateRevision, serverId]);
|
||||
|
||||
useEffect(() => { onAttention(!!pending || !!pendingStateError); }, [pending, pendingStateError, onAttention]);
|
||||
|
||||
async function refreshPending() {
|
||||
setPendingChecked(false);
|
||||
try {
|
||||
const txn = await refreshServerUpdateState(serverId);
|
||||
setPending(txn);
|
||||
setPendingStateError(null);
|
||||
setPendingChecked(true);
|
||||
return txn;
|
||||
} catch (e) { setPendingStateError(asUiError(e)); throw e; }
|
||||
}
|
||||
|
||||
async function check() {
|
||||
setBusy("check");
|
||||
setError(null);
|
||||
setDone(null);
|
||||
clearServerUpdateResult(serverId);
|
||||
setPreview(null);
|
||||
try {
|
||||
const txn = await refreshPending();
|
||||
if (txn) return;
|
||||
const p = await api.checkUpdate(serverId, source.trim() || undefined);
|
||||
setPreview(p);
|
||||
setChoices(Object.fromEntries(p.conflicts.map((c) => [c, "keep" as const])));
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function update() {
|
||||
if (!pendingChecked || pendingStateError || pending) return;
|
||||
setError(null);
|
||||
setDone(null);
|
||||
await applyServerUpdate(serverId, { choices, source: source.trim() || undefined });
|
||||
}
|
||||
|
||||
async function rollback(txn: UpdateTxn) {
|
||||
if (!window.confirm(t("upd.confirmBack"))) return;
|
||||
setBusy("rollback");
|
||||
setError(null);
|
||||
try {
|
||||
await api.rollbackUpdate(serverId, txn.id);
|
||||
setPending(null);
|
||||
setDone(t("upd.wentBack"));
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function retryValidation(txn: UpdateTxn) {
|
||||
setBusy("retry");
|
||||
setError(null);
|
||||
try {
|
||||
const result = await api.retryUpdateValidation(serverId, txn.id);
|
||||
if (result.state === "committed") {
|
||||
setPending(null);
|
||||
setPreview(null);
|
||||
setDone(t("upd.updatedTo", { v: result.to_version }));
|
||||
clearServerUpdateResult(serverId);
|
||||
} else setPending(result);
|
||||
} catch (e) { setError(asUiError(e)); }
|
||||
finally {
|
||||
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function browse() {
|
||||
const p = await open({ directory: true, multiple: false, title: t("upd.dialogTitle") });
|
||||
if (typeof p === "string") setSource(p);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{pending && (
|
||||
<Card className="mt-6 border-warn/40 p-5" role="alert">
|
||||
<p className="font-medium text-warn">
|
||||
{pending.state === "needs-decision" ? t("upd.pendingBad") : t("upd.pendingUnfinished")}
|
||||
</p>
|
||||
<p className="mt-1 whitespace-pre-wrap text-sm text-muted">{pending.message ?? t("upd.safeBack")}</p>
|
||||
{pending.state === "needs-decision" && (
|
||||
<Button className="mt-3 mr-3" size="sm" disabled={!!busy} onClick={() => void retryValidation(pending)}>
|
||||
{busy === "retry" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{t("upd.retryValidation")}
|
||||
</Button>
|
||||
)}
|
||||
<p className="mt-1 text-sm text-muted">{t("upd.backNote")}</p>
|
||||
<Button className="mt-3" size="sm" disabled={!!busy} onClick={() => void rollback(pending)}>
|
||||
{busy === "rollback" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{pending.from_version ? t("upd.goBackTo", { v: pending.from_version }) : t("upd.goBackBefore")}
|
||||
</Button>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div><h2 className="flex items-center gap-2 font-semibold"><Server className="h-4 w-4 text-gold" aria-hidden />{t("history.server")}</h2>
|
||||
<p className="mt-2 text-sm text-muted">{preview?.from_version ? t("settings.version", { v: preview.from_version }) : "…"}</p></div>
|
||||
<Button size="sm" disabled={!!busy} onClick={() => void check()} aria-label={t("upd.check")} title={t("upd.check")}><RefreshCw className={`h-4 w-4 ${busy === "check" ? "animate-spin" : ""}`} aria-hidden /></Button>
|
||||
</div>
|
||||
<button className="mt-3 cursor-pointer text-sm text-gold hover:underline" onClick={() => onHistory(preview?.from_version, preview && !isUpdateCurrent(preview) ? preview.to_version : undefined)}>{t(preview && !isUpdateCurrent(preview) ? "history.open" : "history.title")}</button>
|
||||
<div className="mt-3"><button onClick={() => setAdvanced((v) => !v)} aria-expanded={advanced} className="flex cursor-pointer items-center gap-1 text-xs text-muted hover:text-ink">
|
||||
{advanced ? <ChevronDown className="h-3 w-3" aria-hidden /> : <ChevronRight className="h-3 w-3" aria-hidden />}{t("install.advanced")}
|
||||
</button></div>
|
||||
{advanced && (
|
||||
<div className="mt-3 flex gap-2">
|
||||
<input aria-label={t("upd.folderLabel")} value={source} onChange={(e) => setSource(e.target.value)} placeholder={t("upd.folderHint")} className="selectable flex-1 rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none focus:border-gold" />
|
||||
<Button size="sm" onClick={browse}>{t("install.browse")}</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{done && pendingChecked && !pendingStateError && <p className="mt-4 text-sm text-ok" role="status">{done}</p>}
|
||||
{error && (
|
||||
<div className="mt-4" role="alert">
|
||||
<p className="selectable whitespace-pre-wrap break-words text-sm text-bad">
|
||||
{error.human.code === "unknown" ? error.technical : human(error.human).message}
|
||||
</p>
|
||||
<button className="mt-1 cursor-pointer text-xs text-muted underline" onClick={() => void navigator.clipboard.writeText(error.technical)}>
|
||||
{t("common.copyError")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{preview?.database_check_error && (
|
||||
<p className="selectable mt-4 break-words text-sm text-warn" role="status">{t("upd.dbUnchecked", { why: preview.database_check_error })}</p>
|
||||
)}
|
||||
|
||||
{preview && isUpdateCurrent(preview) && (
|
||||
<div className="mt-5 border-t border-line pt-4">
|
||||
<p className="font-medium text-ok" role="status">{t("upd.current", { v: preview.to_version })}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{preview && !isUpdateCurrent(preview) && (
|
||||
<div className="mt-5 border-t border-line pt-4">
|
||||
<p className="font-medium">
|
||||
{preview.from_version ? t("upd.availableFrom", { to: preview.to_version, from: preview.from_version }) : t("upd.available", { to: preview.to_version })}
|
||||
</p>
|
||||
{preview.latest_version && <p className="mt-1 text-sm text-warn" role="status">{t("upd.intermediate", { to: preview.to_version, latest: preview.latest_version })}</p>}
|
||||
<p className="mt-1 text-sm text-muted">
|
||||
{!preview.database_check_error && (preview.pending_migrations ?? preview.migrations) > 0
|
||||
? t("upd.summaryDb", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length, db: preview.pending_migrations ?? preview.migrations })
|
||||
: t("upd.summary", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length })}
|
||||
</p>
|
||||
<details className="mt-3" open={preview.items.some(i => i.action === "conflict")}><summary className="cursor-pointer text-sm text-muted">{t("history.files")}</summary><ul className="mt-3 max-h-56 divide-y divide-line overflow-auto text-sm">
|
||||
{preview.items.filter((i) => i.action !== "skip").map((i) => (
|
||||
<li key={i.path} className="py-2">
|
||||
<div className="flex justify-between gap-3">
|
||||
<span className="selectable break-all">{i.path}</span>
|
||||
<span className={i.action === "conflict" ? "shrink-0 text-warn" : "shrink-0 text-muted"}>{t(`upd.act.${i.action}` as Key)}</span>
|
||||
</div>
|
||||
{i.action === "conflict" && (
|
||||
<fieldset className="mt-2 flex flex-wrap gap-4 text-xs text-muted">
|
||||
<legend className="sr-only">{t("upd.conflict")}</legend>
|
||||
<span className="text-warn">{t("upd.conflict")}</span>
|
||||
{(["keep", "replace"] as const).map((c) => (
|
||||
<label key={c} className="flex cursor-pointer items-center gap-1">
|
||||
<input type="radio" name={i.path} checked={choices[i.path] === c} onChange={() => setChoices((x) => ({ ...x, [i.path]: c }))} />
|
||||
{c === "keep" ? t("upd.keep") : t("upd.replace")}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul></details>
|
||||
<Button className="mt-4" variant="primary" disabled={!!busy || !pendingChecked || !!pendingStateError || !!pending} onClick={() => void update()}>
|
||||
{busy === "update" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{t("upd.now")}
|
||||
</Button>
|
||||
<p className="mt-2 text-xs text-muted">{t("upd.stopNote")}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{busy === "update" && progress && (
|
||||
<div className="mt-5">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span role="status">{hasKey(`ustep.${progress.step}`) ? t(`ustep.${progress.step}` as Key) : progress.step}</span>
|
||||
<span className="text-muted">{progress.percent}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-white/10" role="progressbar" aria-valuenow={progress.percent} aria-valuemin={0} aria-valuemax={100}>
|
||||
<div className="h-full rounded-full bg-gold transition-[width] duration-300" style={{ width: `${progress.percent}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<label className="mt-5 flex cursor-pointer items-center justify-between gap-3 border-t border-line pt-4 text-sm" title={t("upd.startAfter")}>
|
||||
<span>{t("settings.startServer")}</span><input type="checkbox" role="switch" checked={startAfter} onChange={(e) => setStartAfter(e.target.checked)} className="h-4 w-4 accent-[#c9a24a]" />
|
||||
</label>
|
||||
</Card>
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+49
-286
@@ -1,292 +1,55 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { ChevronDown, ChevronRight, Loader2 } from "lucide-react";
|
||||
import { applyServerUpdate, clearServerUpdateResult, refreshServerUpdateState, useServerUpdate } from "@/lib/serverUpdate";
|
||||
import { isUpdateCurrent } from "@/lib/serverUpdateStatus";
|
||||
import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ClientCard } from "@/screens/ClientCard";
|
||||
import { GameDataCard } from "@/screens/GameDataCard";
|
||||
import { DiagnosticsCard } from "@/screens/DiagnosticsCard";
|
||||
import { AboutCard } from "@/screens/AboutCard";
|
||||
import { RemoveServerCard } from "@/screens/RemoveServerCard";
|
||||
import { useStartAfterUpdate } from "@/lib/updatePrefs";
|
||||
import { hasKey, useHuman, useI18n, type Key } from "@/i18n";
|
||||
import { useState } from "react";
|
||||
import { Download, Power, FolderOpen, Wrench, Languages } from "lucide-react";
|
||||
import { useI18n } from "@/i18n";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { RealmStartupSettings } from "@/screens/RealmStartupSettings";
|
||||
import { RepairCard } from "@/screens/RepairCard";
|
||||
import { PublishCard } from "@/screens/PublishCard";
|
||||
import { AutoRestartSettings } from "@/screens/AutoRestartSettings";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useServerUpdate } from "@/lib/serverUpdate";
|
||||
import { ServerUpdateCard } from "./ServerUpdateCard";
|
||||
import { AboutCard } from "./AboutCard";
|
||||
import { ReleaseHistory, type HistorySelection } from "./ReleaseHistory";
|
||||
import { ClientCard } from "./ClientCard";
|
||||
import { GameDataCard } from "./GameDataCard";
|
||||
import { RealmStartupSettings } from "./RealmStartupSettings";
|
||||
import { AutoRestartSettings } from "./AutoRestartSettings";
|
||||
import { DiagnosticsCard } from "./DiagnosticsCard";
|
||||
import { RepairCard } from "./RepairCard";
|
||||
import { RemoveServerCard } from "./RemoveServerCard";
|
||||
|
||||
function mb(bytes: number) {
|
||||
return bytes >= 1 << 20 ? `${(bytes / (1 << 20)).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
||||
}
|
||||
|
||||
export function SettingsHome({ serverId, serverName = "", path, onForget }: { serverId: string; serverName?: string; path: string; onForget: () => Promise<void> }) {
|
||||
const sections = [["updates", Download], ["startup", Power], ["client", FolderOpen], ["service", Wrench], ["interface", Languages]] as const;
|
||||
export function SettingsHome({ serverId, path, onForget }: { serverId: string; serverName?: string; path: string; onForget: () => Promise<void> }) {
|
||||
const { t } = useI18n();
|
||||
const upd = useServerUpdate(serverId);
|
||||
const human = useHuman();
|
||||
const [preview, setPreview] = useState<UpdatePreview | null>(null);
|
||||
const [pending, setPending] = useState<UpdateTxn | null>(null);
|
||||
const [pendingChecked, setPendingChecked] = useState(false);
|
||||
const [pendingStateError, setPendingStateError] = useState<UiError | null>(null);
|
||||
const [localBusy, setBusy] = useState<"check" | "rollback" | "retry" | null>(null);
|
||||
// an update keeps running in the background when this tab is left, so its state is the shared one
|
||||
const busy = upd.applying ? "update" : localBusy;
|
||||
const progress = upd.applying ? { step: upd.step ?? "Starting", percent: upd.percent } : null;
|
||||
const [localError, setError] = useState<UiError | null>(null);
|
||||
const error = pendingStateError ?? localError ?? upd.uiError;
|
||||
const [localDone, setDone] = useState<string | null>(null);
|
||||
const done = upd.result && "committed" in upd.result ? t("upd.updatedTo", { v: upd.result.committed }) : localDone;
|
||||
const [choices, setChoices] = useState<Record<string, "keep" | "replace">>({});
|
||||
const [advanced, setAdvanced] = useState(false);
|
||||
const [source, setSource] = useState("");
|
||||
const [startAfter, setStartAfter] = useStartAfterUpdate("server", serverId);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
setPendingChecked(false);
|
||||
setPending(null);
|
||||
setPreview(null);
|
||||
setPendingStateError(null);
|
||||
void api.pendingUpdate(serverId).then((txn) => {
|
||||
if (active) { setPending(txn); setPendingChecked(true); }
|
||||
}).catch((e) => { if (active) setPendingStateError(asUiError(e)); });
|
||||
return () => { active = false; };
|
||||
}, [serverId]);
|
||||
|
||||
// Every finished attempt refreshes the disk state, including failures in the background.
|
||||
useEffect(() => {
|
||||
if (!upd.stateRevision) return;
|
||||
setPreview(null);
|
||||
setPendingChecked(!upd.stateError);
|
||||
setPendingStateError(upd.stateError);
|
||||
if (!upd.stateError) setPending(upd.result && "pending" in upd.result ? upd.result.pending : null);
|
||||
}, [upd.stateRevision, serverId]);
|
||||
|
||||
async function refreshPending() {
|
||||
setPendingChecked(false);
|
||||
try {
|
||||
const txn = await refreshServerUpdateState(serverId);
|
||||
setPending(txn);
|
||||
setPendingStateError(null);
|
||||
setPendingChecked(true);
|
||||
return txn;
|
||||
} catch (e) { setPendingStateError(asUiError(e)); throw e; }
|
||||
const [section, setSection] = useState<(typeof sections)[number][0]>("updates");
|
||||
const [attention, setAttention] = useState(false);
|
||||
const update = useServerUpdate(serverId);
|
||||
const [history, setHistory] = useState<HistorySelection>(() => ({ component: "server", from: update.preview?.from_version ?? undefined, to: update.available ? update.preview?.to_version : undefined }));
|
||||
function showHistory(selection: HistorySelection) {
|
||||
setHistory(selection);
|
||||
requestAnimationFrame(() => {
|
||||
const element = document.getElementById("release-history");
|
||||
element?.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
element?.focus({ preventScroll: true });
|
||||
});
|
||||
}
|
||||
|
||||
async function check() {
|
||||
setBusy("check");
|
||||
setError(null);
|
||||
setDone(null);
|
||||
clearServerUpdateResult(serverId);
|
||||
setPreview(null);
|
||||
try {
|
||||
const txn = await refreshPending();
|
||||
if (txn) return;
|
||||
const p = await api.checkUpdate(serverId, source.trim() || undefined);
|
||||
setPreview(p);
|
||||
setChoices(Object.fromEntries(p.conflicts.map((c) => [c, "keep" as const])));
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function update() {
|
||||
if (!pendingChecked || pendingStateError || pending) return;
|
||||
setError(null);
|
||||
setDone(null);
|
||||
await applyServerUpdate(serverId, { choices, source: source.trim() || undefined });
|
||||
}
|
||||
|
||||
async function rollback(txn: UpdateTxn) {
|
||||
if (!window.confirm(t("upd.confirmBack"))) return;
|
||||
setBusy("rollback");
|
||||
setError(null);
|
||||
try {
|
||||
await api.rollbackUpdate(serverId, txn.id);
|
||||
setPending(null);
|
||||
setDone(t("upd.wentBack"));
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function retryValidation(txn: UpdateTxn) {
|
||||
setBusy("retry");
|
||||
setError(null);
|
||||
try {
|
||||
const result = await api.retryUpdateValidation(serverId, txn.id);
|
||||
if (result.state === "committed") {
|
||||
setPending(null);
|
||||
setPreview(null);
|
||||
setDone(t("upd.updatedTo", { v: result.to_version }));
|
||||
clearServerUpdateResult(serverId);
|
||||
} else setPending(result);
|
||||
} catch (e) { setError(asUiError(e)); }
|
||||
finally {
|
||||
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function browse() {
|
||||
const p = await open({ directory: true, multiple: false, title: t("upd.dialogTitle") });
|
||||
if (typeof p === "string") setSource(p);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl">
|
||||
<h1 className="text-2xl font-semibold">{t("settings.title")}</h1>
|
||||
<p className="mt-1 text-muted">{t("q.settings")}</p>
|
||||
|
||||
{pending && (
|
||||
<Card className="mt-6 border-warn/40 p-5" role="alert">
|
||||
<p className="font-medium text-warn">
|
||||
{pending.state === "needs-decision" ? t("upd.pendingBad") : t("upd.pendingUnfinished")}
|
||||
</p>
|
||||
<p className="mt-1 whitespace-pre-wrap text-sm text-muted">{pending.message ?? t("upd.safeBack")}</p>
|
||||
{pending.state === "needs-decision" && (
|
||||
<Button className="mt-3 mr-3" size="sm" disabled={!!busy} onClick={() => void retryValidation(pending)}>
|
||||
{busy === "retry" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{t("upd.retryValidation")}
|
||||
</Button>
|
||||
)}
|
||||
<p className="mt-1 text-sm text-muted">{t("upd.backNote")}</p>
|
||||
<Button className="mt-3" size="sm" disabled={!!busy} onClick={() => void rollback(pending)}>
|
||||
{busy === "rollback" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{pending.from_version ? t("upd.goBackTo", { v: pending.from_version }) : t("upd.goBackBefore")}
|
||||
</Button>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("settings.language")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("settings.languageHint")}</p>
|
||||
<LanguagePicker className="mt-3" />
|
||||
</Card>
|
||||
|
||||
<ClientCard serverId={serverId} />
|
||||
<RealmStartupSettings serverId={serverId} />
|
||||
<AutoRestartSettings serverId={serverId} />
|
||||
|
||||
<GameDataCard serverId={serverId} />
|
||||
|
||||
<DiagnosticsCard serverId={serverId} />
|
||||
<RepairCard key={serverId} serverId={serverId} />
|
||||
<PublishCard key={`publish-${serverId}`} serverId={serverId} serverName={serverName} />
|
||||
|
||||
<AboutCard />
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("upd.title")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("upd.text")}</p>
|
||||
<label className="mt-3 flex cursor-pointer items-center gap-2 text-sm">
|
||||
<input type="checkbox" checked={startAfter} onChange={(e) => setStartAfter(e.target.checked)} className="h-4 w-4 accent-[#c9a24a]" />
|
||||
<span>{t("upd.startAfter")}</span>
|
||||
</label>
|
||||
|
||||
<div className="mt-4 flex items-center gap-3">
|
||||
<Button variant="primary" disabled={!!busy} onClick={() => void check()}>
|
||||
{busy === "check" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{t("upd.check")}
|
||||
</Button>
|
||||
<button onClick={() => setAdvanced((v) => !v)} aria-expanded={advanced} className="flex cursor-pointer items-center gap-1 text-sm text-muted hover:text-ink">
|
||||
{advanced ? <ChevronDown className="h-4 w-4" aria-hidden /> : <ChevronRight className="h-4 w-4" aria-hidden />}
|
||||
{t("install.advanced")}
|
||||
</button>
|
||||
</div>
|
||||
{advanced && (
|
||||
<div className="mt-3 flex gap-2">
|
||||
<input aria-label={t("upd.folderLabel")} value={source} onChange={(e) => setSource(e.target.value)} placeholder={t("upd.folderHint")} className="selectable flex-1 rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none focus:border-gold" />
|
||||
<Button size="sm" onClick={browse}>{t("install.browse")}</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{done && pendingChecked && !pendingStateError && <p className="mt-4 text-sm text-ok" role="status">{done}</p>}
|
||||
{upd.result && "committed" in upd.result && !!upd.result.preexistingCharacters && <p className="mt-3 text-sm text-warn" role="status">{t("upd.preexistingCharacters", { n: upd.result.preexistingCharacters })}</p>}
|
||||
{error && (
|
||||
<div className="mt-4" role="alert">
|
||||
<p className="selectable whitespace-pre-wrap break-words text-sm text-bad">
|
||||
{error.human.code === "unknown" ? error.technical : human(error.human).message}
|
||||
</p>
|
||||
<button className="mt-1 cursor-pointer text-xs text-muted underline" onClick={() => void navigator.clipboard.writeText(error.technical)}>
|
||||
{t("common.copyError")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{preview?.database_check_error && (
|
||||
<p className="selectable mt-4 break-words text-sm text-warn" role="status">{t("upd.dbUnchecked", { why: preview.database_check_error })}</p>
|
||||
)}
|
||||
|
||||
{preview && isUpdateCurrent(preview) && (
|
||||
<div className="mt-5 border-t border-line pt-4">
|
||||
<p className="font-medium text-ok" role="status">{t("upd.current", { v: preview.to_version })}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{preview && !isUpdateCurrent(preview) && (
|
||||
<div className="mt-5 border-t border-line pt-4">
|
||||
<p className="font-medium">
|
||||
{preview.from_version ? t("upd.availableFrom", { to: preview.to_version, from: preview.from_version }) : t("upd.available", { to: preview.to_version })}
|
||||
</p>
|
||||
{preview.latest_version && <p className="mt-1 text-sm text-warn" role="status">{t("upd.intermediate", { to: preview.to_version, latest: preview.latest_version })}</p>}
|
||||
<p className="mt-1 text-sm text-muted">
|
||||
{!preview.database_check_error && (preview.pending_migrations ?? preview.migrations) > 0
|
||||
? t("upd.summaryDb", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length, db: preview.pending_migrations ?? preview.migrations })
|
||||
: t("upd.summary", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length })}
|
||||
</p>
|
||||
<ul className="mt-3 max-h-56 divide-y divide-line overflow-auto text-sm">
|
||||
{preview.items.filter((i) => i.action !== "skip").map((i) => (
|
||||
<li key={i.path} className="py-2">
|
||||
<div className="flex justify-between gap-3">
|
||||
<span className="selectable break-all">{i.path}</span>
|
||||
<span className={i.action === "conflict" ? "shrink-0 text-warn" : "shrink-0 text-muted"}>{t(`upd.act.${i.action}` as Key)}</span>
|
||||
</div>
|
||||
{i.action === "conflict" && (
|
||||
<fieldset className="mt-2 flex flex-wrap gap-4 text-xs text-muted">
|
||||
<legend className="sr-only">{t("upd.conflict")}</legend>
|
||||
<span className="text-warn">{t("upd.conflict")}</span>
|
||||
{(["keep", "replace"] as const).map((c) => (
|
||||
<label key={c} className="flex cursor-pointer items-center gap-1">
|
||||
<input type="radio" name={i.path} checked={choices[i.path] === c} onChange={() => setChoices((x) => ({ ...x, [i.path]: c }))} />
|
||||
{c === "keep" ? t("upd.keep") : t("upd.replace")}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Button className="mt-4" variant="primary" disabled={!!busy || !pendingChecked || !!pendingStateError || !!pending} onClick={() => void update()}>
|
||||
{busy === "update" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{t("upd.now")}
|
||||
</Button>
|
||||
<p className="mt-2 text-xs text-muted">{t("upd.stopNote")}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{busy === "update" && progress && (
|
||||
<div className="mt-5">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span role="status">{hasKey(`ustep.${progress.step}`) ? t(`ustep.${progress.step}` as Key) : progress.step}</span>
|
||||
<span className="text-muted">{progress.percent}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-white/10" role="progressbar" aria-valuenow={progress.percent} aria-valuemin={0} aria-valuemax={100}>
|
||||
<div className="h-full rounded-full bg-gold transition-[width] duration-300" style={{ width: `${progress.percent}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<RemoveServerCard serverId={serverId} path={path} onForget={onForget} />
|
||||
return <div className="mx-auto w-full max-w-5xl pb-8">
|
||||
<h1 className="text-2xl font-semibold">{t("settings.title")}</h1>
|
||||
<p className="mt-1 text-sm text-muted">{t("settings.organized")}</p>
|
||||
<nav aria-label={t("settings.title")} className="mt-6 flex flex-wrap gap-1 border-b border-line pb-3">
|
||||
{sections.map(([id, Icon]) => <button key={id} aria-current={section === id ? "page" : undefined} onClick={() => setSection(id)} className={`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm ${section === id ? "bg-gold/10 text-gold" : "text-muted hover:bg-white/5 hover:text-ink"}`}>
|
||||
<Icon className="h-4 w-4" aria-hidden />{t(`settings.section.${id}`)}
|
||||
</button>)}
|
||||
</nav>
|
||||
{attention && section !== "updates" && <button role="alert" onClick={() => setSection("updates")} className="mt-4 w-full cursor-pointer rounded-lg border border-warn/40 p-4 text-left text-sm text-warn">{t("settings.attention")}</button>}
|
||||
<div hidden={section !== "updates"}>
|
||||
<div className="grid items-start gap-x-5 lg:grid-cols-2">
|
||||
<ServerUpdateCard onAttention={setAttention} serverId={serverId} onHistory={(from, to) => showHistory({ component: "server", from: from ?? undefined, to })} />
|
||||
<AboutCard onHistory={() => showHistory({ component: "manager" })} />
|
||||
</div>
|
||||
<button onClick={() => setSection("client")} className="mt-5 flex w-full cursor-pointer items-center justify-between gap-3 rounded-lg border border-line px-5 py-4 text-left text-sm hover:bg-white/5"><span>{t("settings.clientLink")}</span><span aria-hidden>→</span></button>
|
||||
<ReleaseHistory selection={history} onSelect={setHistory} />
|
||||
</div>
|
||||
);
|
||||
<div hidden={section !== "startup"} className="max-w-3xl"><RealmStartupSettings serverId={serverId} /><AutoRestartSettings serverId={serverId} /></div>
|
||||
<div hidden={section !== "client"} className="max-w-3xl"><ClientCard serverId={serverId} /><GameDataCard serverId={serverId} /></div>
|
||||
<div hidden={section !== "service"} className="max-w-3xl"><DiagnosticsCard serverId={serverId} /><RepairCard serverId={serverId} /><RemoveServerCard serverId={serverId} path={path} onForget={onForget} /></div>
|
||||
<div hidden={section !== "interface"} className="max-w-3xl"><Card className="mt-6 p-6"><h2 className="font-semibold">{t("settings.language")}</h2><p className="mt-1 text-sm text-muted">{t("settings.languageHint")}</p><LanguagePicker className="mt-4" /></Card></div>
|
||||
</div>;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ export function Shell(props: {
|
||||
) : page === "report" ? (
|
||||
<ReportPage key={server.id} serverId={server.id} />
|
||||
) : page === "friends" ? (
|
||||
<PlayWithFriends key={server.id} serverId={server.id} path={server.path} />
|
||||
<PlayWithFriends key={server.id} serverName={server.name} serverId={server.id} path={server.path} />
|
||||
) : page === "settings" ? (
|
||||
<SettingsHome key={server.id} serverId={server.id} serverName={server.name} path={server.path} onForget={() => props.onForget(server.id)} />
|
||||
) : page === "characters" ? (
|
||||
|
||||
Reference in new issue
Block a user