mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-20 03:25:56 +00:00
Merge master (0.6.6) into feat/portable-characters
Conflicts were additive only: the rusqlite and if-addrs dependencies sit side by side, and the portable.* and fr.lan.* translation blocks are both kept in en and ru. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
d05bfe8b09
89 files changed
+3444
-233
No files matched your search
@@ -5,6 +5,15 @@ import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT, type Key } from "@/i18n";
|
||||
|
||||
/** Convenience only; Rust validates again before applying or saving. */
|
||||
function validLanIpv4(value: string): boolean {
|
||||
if (!/^(0|[1-9]\d{0,2})(\.(0|[1-9]\d{0,2})){3}$/.test(value)) return false;
|
||||
const octets = value.split(".").map(Number);
|
||||
const [a, b] = octets;
|
||||
return octets.every((n) => n <= 255) && a > 0 && a < 224 && a !== 127
|
||||
&& !(a === 169 && b === 254) && !(a === 100 && b >= 64 && b <= 127);
|
||||
}
|
||||
|
||||
function Line({ ok, children, warn }: { ok: boolean; warn?: boolean; children: React.ReactNode }) {
|
||||
const t = useT();
|
||||
return (
|
||||
@@ -81,11 +90,28 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [needsRestart, setNeedsRestart] = useState(false);
|
||||
const [lanChoice, setLanChoice] = useState("automatic");
|
||||
const [customLan, setCustomLan] = useState("");
|
||||
|
||||
const refresh = useCallback(() => api.friendsStatus(serverId).then(setSt).catch((e) => setError(asUiError(e))), [serverId]);
|
||||
const refresh = useCallback(() => api.friendsStatus(serverId).then((status) => {
|
||||
setSt(status);
|
||||
}).catch((e) => setError(asUiError(e))), [serverId]);
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
}, [refresh]);
|
||||
let cancelled = false;
|
||||
setSt(null);
|
||||
setNet(null);
|
||||
void api.friendsStatus(serverId).then((status) => {
|
||||
if (cancelled) return;
|
||||
const saved = status.settings.lan_address_override;
|
||||
setCustomLan(saved ?? "");
|
||||
setLanChoice(saved === null ? "automatic" : status.lan_addresses.some((a) => a.address === saved) ? saved : "custom");
|
||||
setSt(status);
|
||||
}).catch((e) => { if (!cancelled) setError(asUiError(e)); });
|
||||
return () => { cancelled = true; };
|
||||
}, [serverId]);
|
||||
|
||||
const lanOverride = lanChoice === "automatic" ? null : lanChoice === "custom" ? customLan.trim() : lanChoice;
|
||||
const lanValid = lanOverride === null || validLanIpv4(lanOverride);
|
||||
|
||||
async function run(label: string, fn: () => Promise<string | void>) {
|
||||
setBusy(label);
|
||||
@@ -109,7 +135,12 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
|
||||
const enable = (mode: FriendsMode) =>
|
||||
run(`enable-${mode}`, async () => {
|
||||
const r = await api.friendsEnable(serverId, mode, net?.public_ip ?? undefined, mode === "direct" && !!net?.router_found);
|
||||
const r = await api.friendsEnable(
|
||||
serverId, mode,
|
||||
mode === "direct" ? net?.public_ip ?? undefined : undefined,
|
||||
mode === "direct" && !!net?.router_found,
|
||||
mode === "lan" ? lanOverride : null,
|
||||
);
|
||||
setNeedsRestart(r.restart_required);
|
||||
return [r.restart_required ? t("fr.restartToApply") : null, r.note ? (r.note.startsWith("Your router was asked") ? t("fr.note.forwarded") : r.note.startsWith("Your router does not support") ? t("fr.note.manual") : r.note) : null].filter(Boolean).join(" ") || t("fr.ready");
|
||||
});
|
||||
@@ -119,6 +150,8 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
const cur = st.settings;
|
||||
const exposed = st.exposure.filter((e) => (e.what === "database" || e.what === "server console") && e.reachable_from_network);
|
||||
const connection = cur.mode === "local" ? null : `set realmlist ${cur.host}`;
|
||||
const selectedLan = lanOverride ?? st.lan_ip;
|
||||
const lanUnavailable = lanOverride !== null && lanValid && !st.lan_addresses.some((a) => a.address === lanOverride);
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl">
|
||||
@@ -157,8 +190,28 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
|
||||
{m.id === "lan" && (
|
||||
<>
|
||||
<p className="mt-2 text-sm">{t("fr.yourLan")} <b className="selectable">{st.lan_ip ?? t("fr.unknown")}</b></p>
|
||||
{st.lan_ip && cur.mode !== m.id && <RealmlistLine host={st.lan_ip} />}
|
||||
<label htmlFor="lan-address" className="mt-3 block text-sm">{t("fr.lan.address")}</label>
|
||||
<select id="lan-address" value={lanChoice} disabled={!!busy}
|
||||
className="mt-1 w-full rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none focus:border-gold"
|
||||
onChange={(e) => {
|
||||
if (e.target.value === "custom" && lanOverride) setCustomLan(lanOverride);
|
||||
setLanChoice(e.target.value);
|
||||
}}>
|
||||
<option value="automatic">{t("fr.lan.automatic")} — {st.lan_ip ?? t("fr.unknown")}</option>
|
||||
{st.lan_addresses.map((a) => <option key={a.address} value={a.address}>{a.interface} — {a.address}{a.is_default ? ` (${t("fr.lan.default")})` : ""}</option>)}
|
||||
{lanChoice !== "automatic" && lanChoice !== "custom" && !st.lan_addresses.some((a) => a.address === lanChoice) && <option value={lanChoice}>{lanChoice}</option>}
|
||||
<option value="custom">{t("fr.lan.custom")}</option>
|
||||
</select>
|
||||
{lanChoice === "custom" && <>
|
||||
<label htmlFor="lan-custom" className="mt-2 block text-sm">{t("fr.lan.customIpv4")}</label>
|
||||
<input id="lan-custom" value={customLan} disabled={!!busy} spellCheck={false} inputMode="decimal"
|
||||
aria-invalid={!lanValid} aria-describedby={!lanValid ? "lan-invalid" : undefined}
|
||||
className="mt-1 w-full rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none focus:border-gold"
|
||||
onChange={(e) => setCustomLan(e.target.value)} />
|
||||
</>}
|
||||
{!lanValid && <p id="lan-invalid" className="mt-2 text-sm text-bad" role="alert">{t("fr.lan.invalid")}</p>}
|
||||
{lanUnavailable && <p className="mt-2 text-sm text-warn" role="status"><b>{t("fr.lan.unavailable")}</b> {t("fr.lan.unavailableText")}</p>}
|
||||
{selectedLan && lanValid && <RealmlistLine host={selectedLan} />}
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -221,7 +274,7 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
<Button
|
||||
size="sm"
|
||||
variant={m.id === "private" && net?.reachability === "cgnat" ? "primary" : "secondary"}
|
||||
disabled={!!busy || (m.id === "direct" && !net?.public_ip) || (m.id === "private" && !st.tailscale.connected)}
|
||||
disabled={!!busy || (m.id === "lan" && (!lanValid || !selectedLan)) || (m.id === "direct" && !net?.public_ip) || (m.id === "private" && !st.tailscale.connected)}
|
||||
onClick={() => void enable(m.id)}
|
||||
title={m.id === "direct" && !net?.public_ip ? t("fr.checkFirst") : undefined}
|
||||
>
|
||||
|
||||
@@ -145,7 +145,7 @@ export function ImportServer(props: {
|
||||
|
||||
{report.notes.map((n) => (
|
||||
<p key={n} className="mt-3 text-sm text-warn">
|
||||
{n}
|
||||
{hasKey(n) ? t(n as Key) : n}
|
||||
</p>
|
||||
))}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ export function ModulesPage({ serverId, onChanged }: { serverId: string; onChang
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
|
||||
<h2 className="font-semibold leading-tight">{m.name}</h2>
|
||||
{m.version && <span className="ml-2 text-xs font-normal text-muted">{m.version}</span>}
|
||||
<StatusBadge status={m.status} />
|
||||
</div>
|
||||
<p className="mt-1.5 line-clamp-2 text-sm text-muted">{m.description[locale] ?? m.description.en}</p>
|
||||
@@ -210,7 +211,7 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
|
||||
async function save() {
|
||||
const errors: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(edits)) {
|
||||
const field = moduleField(key, locale);
|
||||
const field = moduleField(key, locale, items?.find(item => item.key === key)?.field);
|
||||
if (field && ["int", "float", "range"].includes(field.type)) {
|
||||
const number = Number(value);
|
||||
const message = !value.trim() || !Number.isFinite(number) ? t("set.enterNumber")
|
||||
@@ -248,18 +249,24 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
|
||||
return next;
|
||||
});
|
||||
const available = items?.filter(s => s.key !== moduleEnableKey(module.id)) ?? [];
|
||||
const advancedCount = available.filter(s => !auctionWeightKey(s.key) && (!moduleField(s.key, locale) || moduleField(s.key, locale)?.advanced)).length;
|
||||
const advancedCount = available.filter(s => !auctionWeightKey(s.key) && (!moduleField(s.key, locale, s.field) || moduleField(s.key, locale, s.field)?.advanced)).length;
|
||||
const visible = available.filter(s => {
|
||||
if (module.id === "ah-bot" && auctionWeightKey(s.key)) return false;
|
||||
const field = moduleField(s.key, locale);
|
||||
const field = moduleField(s.key, locale, s.field);
|
||||
if (!advanced && !query.trim() && (!field || field.advanced)) return false;
|
||||
const title = field ? sx.title({ key: s.key, title: field.title }) : s.key;
|
||||
const description = field ? sx.description({ key: s.key, description: field.description }) : s.doc;
|
||||
const title = field ? (s.field ? field.title : sx.title({ key: s.key, title: field.title })) : s.key;
|
||||
const description = field ? (s.field ? field.description : sx.description({ key: s.key, description: field.description })) : s.doc;
|
||||
return `${title} ${description} ${s.key}`.toLocaleLowerCase(locale).includes(query.trim().toLocaleLowerCase(locale));
|
||||
});
|
||||
return (
|
||||
<div className="mt-3 border-t border-line pt-3">
|
||||
{items === null && !error && <Loader2 className="h-4 w-4 animate-spin text-muted" aria-hidden />}
|
||||
{module.id === "npc-enchanter" && (
|
||||
<div className="mb-4 space-y-2 text-sm text-muted">
|
||||
<p>{t("mod.enchanter.add")}</p>
|
||||
<p>{t("mod.enchanter.remove")}</p>
|
||||
</div>
|
||||
)}
|
||||
{module.id === "ah-bot" && (
|
||||
<div className="mb-4 space-y-2 text-sm text-muted">
|
||||
<p>{t("mod.ahbot.setup")}</p>
|
||||
@@ -278,9 +285,9 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
|
||||
{items && !visible.length && !available.some(s => module.id === "ah-bot" && auctionWeightKey(s.key)) && <p className="py-3 text-sm text-muted">{t(available.length ? "all.none" : "mod.noSettings")}</p>}
|
||||
<ul className="divide-y divide-line">
|
||||
{visible.map((s) => {
|
||||
const field = moduleField(s.key, locale);
|
||||
const title = field ? sx.title({ key: s.key, title: field.title }) : s.key;
|
||||
const description = field ? sx.description({ key: s.key, description: field.description }) : s.doc;
|
||||
const field = moduleField(s.key, locale, s.field);
|
||||
const title = field ? (s.field ? field.title : sx.title({ key: s.key, title: field.title })) : s.key;
|
||||
const description = field ? (s.field ? field.description : sx.description({ key: s.key, description: field.description })) : s.doc;
|
||||
const value = edits[s.key] ?? s.value;
|
||||
const normalized = canonicalModuleValue(s.key, value);
|
||||
const options = field?.options ?? [];
|
||||
|
||||
@@ -64,7 +64,7 @@ function Row({ label, s }: { label: string; s: ServiceStatus }) {
|
||||
);
|
||||
}
|
||||
|
||||
export function Overview({ server, companions = true, onForget, onOpenUpdates, onRealmChanged }: { server: ServerSummary; /** the companions module is on */ companions?: boolean; onForget: () => Promise<void>; onOpenUpdates: () => void; onRealmChanged: () => void }) {
|
||||
export function Overview({ server, companions = true, onForget, onOpenUpdates, onRealmChanged, onReport }: { server: ServerSummary; /** the companions module is on */ companions?: boolean; onForget: () => Promise<void>; onOpenUpdates: () => void; onRealmChanged: () => void; /** open the problem report, which collects the diagnostics */ onReport: () => void }) {
|
||||
const t = useT();
|
||||
const human = useHuman();
|
||||
const [status, setStatus] = useState<StatusView | null>(null);
|
||||
@@ -228,6 +228,12 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
/>
|
||||
{headline}
|
||||
</div>
|
||||
{!transitioning && !running && anyUp && (
|
||||
<p className="mt-2 text-sm text-muted">
|
||||
{t("overview.reportHint")}{" "}
|
||||
<button onClick={onReport} className="cursor-pointer text-gold underline hover:text-ink">{t("overview.reportBtn")}</button>
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mt-5 divide-y divide-line border-y border-line">
|
||||
<Row label={t("overview.database")} s={mysql} />
|
||||
|
||||
+90
-30
@@ -1,22 +1,36 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type ReportContext, type UiError } from "@/lib/api";
|
||||
import { api, asUiError, type ReportContext, type ReportTarget, type ReportTargetId, type UiError } from "@/lib/api";
|
||||
import { MAX_LINK, issueUrl, reportBody } from "@/lib/report";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT } from "@/i18n";
|
||||
import { useHuman, useT, type Key } from "@/i18n";
|
||||
|
||||
const field = "mt-1 block w-full rounded-md border border-line bg-bg px-3 py-2.5 text-[15px] outline-none focus:border-gold";
|
||||
|
||||
/** A problem report that becomes a prefilled GitHub issue. Nothing is sent from here: the person reviews and submits it on GitHub. */
|
||||
const TARGET_LABEL: Record<ReportTargetId, Key> = {
|
||||
manager: "rep.target.manager",
|
||||
companions: "rep.target.companions",
|
||||
squid: "rep.target.squid",
|
||||
};
|
||||
|
||||
const FALLBACK: ReportTarget = { id: "manager", repo: "Corfirean/coa-server-manager", ours: true };
|
||||
|
||||
/**
|
||||
* A problem report that becomes a prefilled GitHub issue in the repository of whatever it is about. One button collects
|
||||
* the diagnostics (and shows the file in its folder) and opens the issue; the person reviews it and submits it on GitHub.
|
||||
*/
|
||||
export function ReportPage({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const human = useHuman();
|
||||
const [ctx, setCtx] = useState<ReportContext | null>(null);
|
||||
const [targets, setTargets] = useState<ReportTarget[]>([]);
|
||||
const [targetId, setTargetId] = useState<ReportTargetId | null>(null);
|
||||
const [title, setTitle] = useState("");
|
||||
const [what, setWhat] = useState("");
|
||||
const [expected, setExpected] = useState("");
|
||||
const [steps, setSteps] = useState("");
|
||||
const [withDiag, setWithDiag] = useState(true);
|
||||
const [file, setFile] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
@@ -25,30 +39,44 @@ export function ReportPage({ serverId }: { serverId: string }) {
|
||||
|
||||
useEffect(() => {
|
||||
void api.reportContext(serverId).then(setCtx).catch(() => setCtx(null));
|
||||
void api.reportTargets().then(setTargets).catch(() => setTargets([]));
|
||||
}, [serverId]);
|
||||
|
||||
const body = useMemo(
|
||||
() =>
|
||||
reportBody({
|
||||
managerVersion: ctx?.manager_version ?? "",
|
||||
windows: ctx?.windows ?? "",
|
||||
installKind: ctx?.install_kind ?? "new",
|
||||
serverVersion: ctx?.server_version ?? null,
|
||||
what,
|
||||
expected,
|
||||
steps,
|
||||
diagnostics: file !== null,
|
||||
}),
|
||||
[ctx, what, expected, steps, file],
|
||||
);
|
||||
const issueTitle = `[Bug] ${title.trim()}`;
|
||||
// start on the bot system that is switched on, until the person picks one
|
||||
const chosen: ReportTargetId = targetId ?? ctx?.suggested_target ?? "manager";
|
||||
const shown = targets.length ? targets : [FALLBACK];
|
||||
const target = shown.find((x) => x.id === chosen) ?? shown[0];
|
||||
|
||||
function bodyFor(hasFile: boolean): string {
|
||||
return reportBody({
|
||||
managerVersion: ctx?.manager_version ?? "",
|
||||
windows: ctx?.windows ?? "",
|
||||
installKind: ctx?.install_kind ?? "new",
|
||||
serverVersion: ctx?.server_version ?? null,
|
||||
target: target.id,
|
||||
botsVersion: ctx?.bots_version ?? null,
|
||||
what,
|
||||
expected,
|
||||
steps,
|
||||
diagnostics: hasFile,
|
||||
});
|
||||
}
|
||||
const issueTitle = target.ours ? `[Bug] ${title.trim()}` : title.trim();
|
||||
const ready = title.trim().length > 0 && what.trim().length > 0;
|
||||
|
||||
async function makeFile() {
|
||||
/** Collects the diagnostics once; the Manager shows the file in its folder. */
|
||||
async function collect(): Promise<string> {
|
||||
if (file) return file;
|
||||
const path = await api.exportDiagnostics(serverId);
|
||||
setFile(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
async function collectOnly() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
setFile(await api.exportDiagnostics(serverId));
|
||||
await collect();
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
@@ -56,26 +84,32 @@ export function ReportPage({ serverId }: { serverId: string }) {
|
||||
}
|
||||
}
|
||||
|
||||
/** One button: collect the diagnostics (if asked), then open the issue with everything filled in. */
|
||||
async function openIssue() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setNote(null);
|
||||
try {
|
||||
const full = issueUrl(issueTitle, body);
|
||||
const path = withDiag ? await collect() : null;
|
||||
const body = bodyFor(path !== null);
|
||||
const full = issueUrl(target, issueTitle, body);
|
||||
if (full.length <= MAX_LINK) {
|
||||
await api.openLink(full);
|
||||
setNote(t("rep.opened"));
|
||||
} else {
|
||||
await navigator.clipboard.writeText(body);
|
||||
await api.openLink(issueUrl(issueTitle, "Paste the report text here (it was copied to the clipboard by CoA Server Manager)."));
|
||||
await api.openLink(issueUrl(target, issueTitle, "Paste the report text here (it was copied to the clipboard by CoA Server Manager)."));
|
||||
setNote(t("rep.openedLong"));
|
||||
}
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
await navigator.clipboard.writeText(`${issueTitle}\n\n${body}`);
|
||||
await navigator.clipboard.writeText(`${issueTitle}\n\n${bodyFor(file !== null)}`);
|
||||
setNote(t("rep.copied"));
|
||||
}
|
||||
|
||||
@@ -85,6 +119,22 @@ export function ReportPage({ serverId }: { serverId: string }) {
|
||||
<p className="mt-1 text-muted">{t("q.report")}</p>
|
||||
<p className="mt-3 text-sm text-muted">{t("rep.intro")}</p>
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold" id="rep-target">{t("rep.targetTitle")}</h2>
|
||||
<div role="radiogroup" aria-labelledby="rep-target" className="mt-3 space-y-2">
|
||||
{shown.map((x) => (
|
||||
<label key={x.id} className={`flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5 ${chosen === x.id ? "border-gold" : "border-line"}`}>
|
||||
<input type="radio" name="rep-target" className="mt-1" checked={chosen === x.id} onChange={() => setTargetId(x.id)} />
|
||||
<span>
|
||||
<span className="block text-[15px]">{t(TARGET_LABEL[x.id])}</span>
|
||||
<span className="selectable block text-xs text-muted">{x.repo}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted">{t("rep.targetPublic", { repo: target.repo })}</p>
|
||||
</Card>
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("rep.autoTitle")}</h2>
|
||||
<dl className="mt-3 grid grid-cols-[auto_1fr] gap-x-6 gap-y-1 text-sm">
|
||||
@@ -100,6 +150,12 @@ export function ReportPage({ serverId }: { serverId: string }) {
|
||||
<dd>{ctx.server_version}</dd>
|
||||
</>
|
||||
)}
|
||||
{target.id !== "manager" && ctx?.bots_version && (
|
||||
<>
|
||||
<dt className="text-muted">{t("rep.botsVersion")}</dt>
|
||||
<dd>{ctx.bots_version}</dd>
|
||||
</>
|
||||
)}
|
||||
</dl>
|
||||
</Card>
|
||||
|
||||
@@ -125,16 +181,20 @@ export function ReportPage({ serverId }: { serverId: string }) {
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("rep.attachTitle")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("rep.attachText")}</p>
|
||||
<Button className="mt-3" size="sm" disabled={busy} onClick={() => void makeFile()}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{t("rep.makeFile")}
|
||||
</Button>
|
||||
<label className="mt-3 flex cursor-pointer items-start gap-3 text-sm">
|
||||
<input type="checkbox" className="mt-1" checked={withDiag} onChange={(e) => setWithDiag(e.target.checked)} />
|
||||
<span>{t("rep.withDiag")}</span>
|
||||
</label>
|
||||
{file && <p className="selectable mt-3 break-all text-sm text-ok" role="status">{t("rep.fileSaved", { path: file })}</p>}
|
||||
<p className="mt-4 text-xs text-warn">{t("rep.privacy")}</p>
|
||||
</Card>
|
||||
|
||||
<div className="mt-6 flex flex-wrap items-center gap-3">
|
||||
<Button variant="primary" disabled={!ready} onClick={() => void openIssue()}>{t("rep.open")}</Button>
|
||||
<Button variant="primary" disabled={!ready || busy} onClick={() => void openIssue()}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{busy ? t("rep.collecting") : withDiag ? t("rep.collectOpen") : t("rep.open")}
|
||||
</Button>
|
||||
<Button variant="ghost" disabled={busy} onClick={() => void collectOnly()}>{t("rep.makeFile")}</Button>
|
||||
<Button variant="ghost" disabled={!ready} onClick={() => void copy()}>{t("rep.copy")}</Button>
|
||||
<button onClick={() => setShowPreview((v) => !v)} aria-expanded={showPreview} className="cursor-pointer text-sm text-muted underline hover:text-ink">
|
||||
{t("rep.preview")}
|
||||
@@ -144,7 +204,7 @@ export function ReportPage({ serverId }: { serverId: string }) {
|
||||
<p className="mt-2 text-xs text-muted">{t("rep.githubNote")}</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.human.code === "unknown" ? error.technical : human(error.human).message}</p>}
|
||||
{showPreview && <pre className="selectable mt-3 max-h-80 overflow-auto whitespace-pre-wrap rounded bg-black/40 p-3 text-xs text-muted">{`${issueTitle}\n\n${body}`}</pre>}
|
||||
{showPreview && <pre className="selectable mt-3 max-h-80 overflow-auto whitespace-pre-wrap rounded bg-black/40 p-3 text-xs text-muted">{`${issueTitle}\n\n${bodyFor(file !== null || withDiag)}`}</pre>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { ChevronDown, ChevronRight, Loader2 } from "lucide-react";
|
||||
import { applyServerUpdate, clearServerUpdateResult, useServerUpdate } from "@/lib/serverUpdate";
|
||||
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";
|
||||
@@ -23,12 +24,14 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
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 = localError ?? upd.uiError;
|
||||
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">>({});
|
||||
@@ -36,16 +39,36 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
const [source, setSource] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
void api.pendingUpdate(serverId).then(setPending).catch(() => {});
|
||||
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]);
|
||||
|
||||
// the update finished (possibly while another tab was open): drop the stale preview, show what is left to decide
|
||||
// Every finished attempt refreshes the disk state, including failures in the background.
|
||||
useEffect(() => {
|
||||
if (!upd.result) return;
|
||||
if (!upd.stateRevision) return;
|
||||
setPreview(null);
|
||||
if ("pending" in upd.result) setPending(upd.result.pending);
|
||||
else void api.pendingUpdate(serverId).then(setPending).catch(() => {});
|
||||
}, [upd.result, serverId]);
|
||||
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; }
|
||||
}
|
||||
|
||||
async function check() {
|
||||
setBusy("check");
|
||||
@@ -54,6 +77,8 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
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])));
|
||||
@@ -65,6 +90,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
}
|
||||
|
||||
async function update() {
|
||||
if (!pendingChecked || pendingStateError || pending) return;
|
||||
setError(null);
|
||||
setDone(null);
|
||||
await applyServerUpdate(serverId, { choices, source: source.trim() || undefined });
|
||||
@@ -81,6 +107,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +124,10 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
clearServerUpdateResult(serverId);
|
||||
} else setPending(result);
|
||||
} catch (e) { setError(asUiError(e)); }
|
||||
finally { setBusy(null); }
|
||||
finally {
|
||||
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function browse() {
|
||||
@@ -165,28 +195,27 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{done && <p className="mt-4 text-sm text-ok" role="status">{done}</p>}
|
||||
{done && pendingChecked && !pendingStateError && <p className="mt-4 text-sm text-ok" role="status">{done}</p>}
|
||||
{error && (
|
||||
<p className="mt-4 text-sm text-bad" role="alert">
|
||||
{error.human.code === "unknown" ? error.technical : human(error.human).message}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{preview && preview.from_version === preview.to_version && preview.items.every((i) => i.action === "skip") && (
|
||||
// The same version with no file to change: the database scripts of this package are all in the ledger already.
|
||||
{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 && !(preview.from_version === preview.to_version && preview.items.every((i) => i.action === "skip")) && (
|
||||
{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>
|
||||
<p className="mt-1 text-sm text-muted">
|
||||
{preview.migrations > 0
|
||||
? t("upd.summaryDb", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length, db: preview.migrations })
|
||||
{(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">
|
||||
@@ -211,7 +240,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Button className="mt-4" variant="primary" disabled={!!busy} onClick={() => void update()}>
|
||||
<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>
|
||||
|
||||
@@ -178,12 +178,15 @@ export function SettingsPage(props: { serverId: string; scope: Scope; botModule?
|
||||
const [raw, setRaw] = useState<AllSetting[] | null>(null);
|
||||
const [rawEdits, setRawEdits] = useState<Record<string, string>>({});
|
||||
const [onlyChanged, setOnlyChanged] = useState(false);
|
||||
const [squidVersion, setSquidVersion] = useState<string | null>(null);
|
||||
const [cols, setCols] = useState<ModuleSetting[]>([]);
|
||||
const [colEdits, setColEdits] = useState<Record<string, string>>({});
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const v = squid ? squidSettingsView(await api.moduleSettings(serverId, "playerbots"), locale) : await api.settings(serverId, scope);
|
||||
const data = squid ? await Promise.all([api.moduleSettings(serverId, "playerbots"), api.modulesList(serverId)]) : null;
|
||||
if (data) setSquidVersion(data[1].find(module => module.id === "playerbots")?.version ?? null);
|
||||
const v = data ? squidSettingsView(data[0], locale) : await api.settings(serverId, scope);
|
||||
setView(v);
|
||||
setDraft({});
|
||||
setErrors({});
|
||||
@@ -363,7 +366,7 @@ export function SettingsPage(props: { serverId: string; scope: Scope; botModule?
|
||||
return (
|
||||
<div className="max-w-3xl pb-24">
|
||||
<h1 className="text-2xl font-semibold">{props.title}</h1>
|
||||
<p className="mt-1 text-muted">{squid ? "SQUID’s Playerbots" : props.question}</p>
|
||||
<p className="mt-1 text-muted">{squid ? `SQUID’s Playerbots${squidVersion ? " · " + squidVersion : ""}` : props.question}</p>
|
||||
|
||||
{scope === "bots" && !squid && <CompanionsCard serverId={serverId} />}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ export function Shell(props: {
|
||||
|
||||
<main className="h-full flex-1 overflow-y-auto px-10 py-8">
|
||||
{page === "overview" ? (
|
||||
<Overview key={server.id} server={server} companions={botModule === "companions" && !hiddenPages.includes("bots")} onForget={() => props.onForget(server.id)} onOpenUpdates={() => setPage("settings")} onRealmChanged={reloadModules} />
|
||||
<Overview key={server.id} server={server} companions={botModule === "companions" && !hiddenPages.includes("bots")} onForget={() => props.onForget(server.id)} onOpenUpdates={() => setPage("settings")} onRealmChanged={reloadModules} onReport={() => setPage("report")} />
|
||||
) : page === "bots" || page === "server" ? (
|
||||
<SettingsPage key={`${server.id}-${page}-${botModule}`} serverId={server.id} scope={page} botModule={botModule} title={t(current.label)} question={t(current.question)} />
|
||||
) : page === "console" ? (
|
||||
|
||||
Reference in new issue
Block a user