mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
- A new server goes on to the preview core without compiling any module (recommended modules are declined once; modules come from the Modules page). - Choosing a server with the classic core makes a modular copy next to it: every acore_* database (read from the running database, or from a private copy of the stopped data files opened by the new server's own mysqld), module configs and realm profiles, ports and console login. The old server is only read. The copy then takes the preview core with the modules the old server had switched on. - Installs and the preview update run on unused ports, so a server running on the shipped ports (the old one, or any other) no longer stops them; the schema check after "Preparing database" used the shipped port before. - Dungeon Clear is part of SQUID's Playerbots: no card of its own (it said "Always on" while SQUID was off), switched with SQUID, settings on the SQUID card. E2E (examples/preview_bare_and_copy_e2e, disposable servers, another server running on the shipped ports): fresh install committed with no plugins and a clean boot report; copy of a stopped and of a running classic server: data identical, old server's files byte-for-byte unchanged, Content Scaling and Companions built on the copy, preview core committed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
186 lines
7.2 KiB
TypeScript
186 lines
7.2 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { open } from "@tauri-apps/plugin-dialog";
|
|
import { AlertTriangle, Check, Minus } from "lucide-react";
|
|
import { api, asUiError, type Classification, type ScanReport, type ServerSummary, type UiError } from "@/lib/api";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card } from "@/components/ui/card";
|
|
import { hasKey, useHuman, useT, type Key } from "@/i18n";
|
|
|
|
const HEADLINE: Record<Classification, { title: Key; tone: string; text: Key }> = {
|
|
healthy: { title: "import.healthy.title", tone: "text-ok", text: "import.healthy.text" },
|
|
partial: { title: "import.partial.title", tone: "text-warn", text: "import.partial.text" },
|
|
"unknown-custom": { title: "import.custom.title", tone: "text-warn", text: "import.custom.text" },
|
|
incompatible: { title: "import.incompatible.title", tone: "text-bad", text: "import.incompatible.text" },
|
|
};
|
|
|
|
export function ImportServer(props: {
|
|
canCancel: boolean;
|
|
onCancel: () => void;
|
|
onAdded: (s: ServerSummary) => void | Promise<void>;
|
|
onCopy: (path: string) => void;
|
|
}) {
|
|
const t = useT();
|
|
const human = useHuman();
|
|
const [report, setReport] = useState<ScanReport | null>(null);
|
|
// A classic core (modules compiled in) is not added as it is: the Modules Preview makes a modular copy next to it.
|
|
const [classic, setClassic] = useState(false);
|
|
useEffect(() => {
|
|
setClassic(false);
|
|
if (report && report.classification !== "incompatible") void api.isClassicServer(report.path).then(setClassic).catch(() => setClassic(false));
|
|
}, [report]);
|
|
const [error, setError] = useState<UiError | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function choose() {
|
|
setError(null);
|
|
const picked = await open({ directory: true, multiple: false, title: t("import.dialogTitle") });
|
|
if (typeof picked !== "string") return;
|
|
setBusy(true);
|
|
setReport(null);
|
|
try {
|
|
setReport(await api.scan(picked));
|
|
} catch (e) {
|
|
setError(asUiError(e));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
async function scanPath(path: string) {
|
|
setError(null);
|
|
setBusy(true);
|
|
setReport(null);
|
|
try {
|
|
setReport(await api.scan(path));
|
|
} catch (e) {
|
|
setError(asUiError(e));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
async function add() {
|
|
if (!report) return;
|
|
setBusy(true);
|
|
try {
|
|
await props.onAdded(await api.add(report.path));
|
|
} catch (e) {
|
|
setError(asUiError(e));
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
const head = report ? HEADLINE[report.classification] : null;
|
|
|
|
return (
|
|
<main className="mx-auto flex h-full max-w-2xl flex-col justify-center gap-5 px-8 py-10">
|
|
<div>
|
|
<h1 className="text-2xl font-semibold">{t("import.title")}</h1>
|
|
<p className="mt-1 text-muted">{t("import.subtitle")}</p>
|
|
</div>
|
|
|
|
<div className="flex gap-3">
|
|
<Button variant="secondary" onClick={choose} disabled={busy}>
|
|
{report ? t("import.chooseAnother") : t("import.choose")}
|
|
</Button>
|
|
{props.canCancel && (
|
|
<Button variant="ghost" onClick={props.onCancel}>
|
|
{t("common.cancel")}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
|
|
{busy && !report && <p className="text-muted">{t("import.looking")}</p>}
|
|
|
|
{error && (
|
|
<Card className="border-bad/40 p-4" role="alert">
|
|
<p className="font-medium text-bad">{human(error.human).title}</p>
|
|
<p className="mt-1 text-sm text-muted">{human(error.human).message}</p>
|
|
<details className="mt-2 text-xs text-muted">
|
|
<summary className="cursor-pointer">{t("import.techDetails")}</summary>
|
|
<pre className="mt-1 whitespace-pre-wrap">{error.technical}</pre>
|
|
</details>
|
|
</Card>
|
|
)}
|
|
|
|
{report && head && (
|
|
<Card className="p-5">
|
|
<div className="flex items-start gap-3">
|
|
{report.classification === "healthy" ? (
|
|
<Check className={`mt-0.5 h-5 w-5 ${head.tone}`} aria-hidden />
|
|
) : (
|
|
<AlertTriangle className={`mt-0.5 h-5 w-5 ${head.tone}`} aria-hidden />
|
|
)}
|
|
<div>
|
|
<h2 className="font-semibold">{t(head.title)}</h2>
|
|
<p className="text-sm text-muted">{t(head.text)}</p>
|
|
<p className="selectable mt-1 break-all text-xs text-muted">{report.path}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<ul className="mt-4 divide-y divide-line text-sm">
|
|
{report.items.map((it) => (
|
|
<li key={it.key} className="flex items-center justify-between py-2">
|
|
<span>{hasKey(`scan.label.${it.key}`) ? t(`scan.label.${it.key}` as Key) : it.label}</span>
|
|
<span className="flex items-center gap-2 text-muted">
|
|
{it.detail && <span className="text-xs">{it.detail}</span>}
|
|
{it.status === "found" ? (
|
|
<span className="flex items-center gap-1 text-ok">
|
|
<Check className="h-4 w-4" aria-hidden /> {t("import.detected")}
|
|
</span>
|
|
) : (
|
|
<span className="flex items-center gap-1">
|
|
<Minus className="h-4 w-4" aria-hidden /> {it.key === "companions" ? t("import.notInstalled") : t("import.notFound")}
|
|
</span>
|
|
)}
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
|
|
{report.suggested_path && (
|
|
<div className="mt-4 rounded-md border border-gold/40 bg-gold/5 p-3" role="status">
|
|
<p className="font-medium">{t("import.suggest.title")}</p>
|
|
<p className="mt-1 text-sm text-muted">{t("import.suggest.text")}</p>
|
|
<p className="selectable mt-1 break-all text-sm">{report.suggested_path}</p>
|
|
<Button className="mt-2" size="sm" variant="primary" disabled={busy} onClick={() => void scanPath(report.suggested_path!)}>
|
|
{t("import.suggest.use")}
|
|
</Button>
|
|
</div>
|
|
)}
|
|
{report.hint === "not-repack" && <p className="mt-3 text-sm text-warn">{t("import.notRepack")}</p>}
|
|
|
|
{report.notes.map((n) => (
|
|
<p key={n} className="mt-3 text-sm text-warn">
|
|
{hasKey(n) ? t(n as Key) : n}
|
|
</p>
|
|
))}
|
|
|
|
{classic ? (
|
|
<div className="mt-5 border-t border-line pt-4">
|
|
<p className="font-medium">{t("import.classic.title")}</p>
|
|
<p className="mt-1 text-sm text-muted">{t("import.classic.text")}</p>
|
|
<div className="mt-3 flex justify-end">
|
|
<Button variant="primary" disabled={busy} onClick={() => props.onCopy(report.path)}>
|
|
{t("import.classic.copy")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="mt-5 flex items-center justify-between border-t border-line pt-4">
|
|
<p className="text-sm text-muted">{t("import.noChanges")}</p>
|
|
<Button
|
|
variant="primary"
|
|
onClick={add}
|
|
disabled={busy || report.classification === "incompatible"}
|
|
>
|
|
{t("import.add")}
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</Card>
|
|
)}
|
|
</main>
|
|
);
|
|
}
|