mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-19 03:25:56 +00:00
The page was a mock: it never read the database (always 0 accounts), showed a hard-coded schema and core version, looked for server files in the wrong folder, and its "transfer" reported accounts, characters and tables as moved without moving anything. Its locale was fixed to "ru". - remove server_migration.rs and its three commands - modular_copy::preview: classic/modular core, version, database state, counts and schemas from a running database (read only), database size, settings files, extra worlds; nothing is started or changed - the page shows that and hands over to the same modular-copy install screen as "Manage another server"; texts in en and ru via i18n - the modular copy now carries world settings changed in Server Configuration (Settings/worldserver.conf.template was not copied) - E2E preview_bare_and_copy_e2e checks the preview and the carried setting; passes against preview core 0.261108.9501 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
3.9 KiB
TypeScript
135 lines
3.9 KiB
TypeScript
import { useCallback, useEffect, useState } from "react";
|
|
import { api, type ServerSummary } from "@/lib/api";
|
|
import { Welcome } from "@/screens/Welcome";
|
|
import { ImportServer } from "@/screens/ImportServer";
|
|
import { Shell } from "@/screens/Shell";
|
|
import { InstallServer } from "@/screens/InstallServer";
|
|
import { RemoteClient } from "@/screens/RemoteClient";
|
|
import { UpdateBanner } from "@/components/UpdateBanner";
|
|
import { autoUpdateEnabled, installOnClose, lookForUpdate } from "@/lib/selfUpdate";
|
|
|
|
type View = "welcome" | "add" | "import" | "install" | "remote";
|
|
|
|
function initialView(): View {
|
|
try { return localStorage.getItem("coa-play-mode") === "remote" ? "remote" : "welcome"; }
|
|
catch { return "welcome"; }
|
|
}
|
|
|
|
function Main() {
|
|
const [servers, setServers] = useState<ServerSummary[] | null>(null);
|
|
const [view, setView] = useState<View>(initialView);
|
|
const [activeId, setActiveId] = useState<string | null>(null);
|
|
// A classic server the owner chose: the install screen makes a modular copy of it next to it.
|
|
const [copyFrom, setCopyFrom] = useState<string | null>(null);
|
|
// Where Cancel on that install screen goes back to: the import screen or the server's own pages.
|
|
const [copyBack, setCopyBack] = useState<View>("import");
|
|
|
|
const refresh = useCallback(async () => {
|
|
const list = await api.list().catch(() => []);
|
|
setServers(list);
|
|
setActiveId((cur) => (cur && list.some((s) => s.id === cur) ? cur : (list[0]?.id ?? null)));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
void refresh();
|
|
}, [refresh]);
|
|
|
|
if (servers === null) return null;
|
|
|
|
if (view === "remote") return <RemoteClient onHost={() => {
|
|
try { localStorage.setItem("coa-play-mode", "host"); } catch { /* storage unavailable */ }
|
|
setView(servers.length ? "welcome" : "add");
|
|
}} />;
|
|
|
|
if (servers.length > 0 && view === "welcome" && activeId) {
|
|
return (
|
|
<Shell
|
|
servers={servers}
|
|
activeId={activeId}
|
|
onSelect={setActiveId}
|
|
onAddAnother={() => setView("add")}
|
|
onCopy={(path) => {
|
|
setCopyFrom(path);
|
|
setCopyBack("welcome");
|
|
setView("install");
|
|
}}
|
|
onForget={async (id) => {
|
|
await api.forget(id);
|
|
await refresh();
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (view === "install") {
|
|
return (
|
|
<InstallServer
|
|
canCancel
|
|
copyFrom={copyFrom ?? undefined}
|
|
onCancel={() => {
|
|
setView(copyFrom ? copyBack : servers.length > 0 ? "add" : "welcome");
|
|
setCopyFrom(null);
|
|
}}
|
|
onDone={async (s) => {
|
|
setCopyFrom(null);
|
|
await refresh();
|
|
setActiveId(s.id);
|
|
setView("welcome");
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (view === "import") {
|
|
return (
|
|
<ImportServer
|
|
canCancel
|
|
onCancel={() => setView(servers.length > 0 ? "add" : "welcome")}
|
|
onAdded={async (s) => {
|
|
await refresh();
|
|
setActiveId(s.id);
|
|
setView("welcome");
|
|
}}
|
|
onCopy={(path) => {
|
|
setCopyFrom(path);
|
|
setCopyBack("import");
|
|
setView("install");
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Welcome
|
|
onConnect={() => {
|
|
try { localStorage.setItem("coa-play-mode", "remote"); } catch { /* storage unavailable */ }
|
|
setView("remote");
|
|
}}
|
|
onImport={() => setView("import")}
|
|
onInstall={() => setView("install")}
|
|
onBack={servers.length > 0 ? () => setView("welcome") : undefined}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default function App() {
|
|
// Quietly fetch a new Manager version a few seconds after start and install it when the window is closed.
|
|
useEffect(() => {
|
|
const stop = installOnClose();
|
|
const timer = setTimeout(() => {
|
|
if (autoUpdateEnabled()) void lookForUpdate({ download: true });
|
|
}, 5000);
|
|
return () => {
|
|
clearTimeout(timer);
|
|
stop();
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<Main />
|
|
<UpdateBanner />
|
|
</>
|
|
);
|
|
}
|