mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-26 03:25:56 +00:00
Phase 1/2: Tauri shell, React UI (welcome, read-only import, overview with start/stop), e2e driver
Verified in the native window against a disposable fixture: import writes only <folder>.manager + registry; start surfaces a human 'database update required' message; stop returns to Offline. Live install untouched throughout. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bbf06793ba
commit
2e8803a067
50 files changed
+7331
-9
No files matched your search
@@ -0,0 +1,150 @@
|
||||
import { 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";
|
||||
|
||||
const HEADLINE: Record<Classification, { title: string; tone: string; text: string }> = {
|
||||
healthy: { title: "Existing server detected", tone: "text-ok", text: "Everything needed to run this server was found." },
|
||||
partial: {
|
||||
title: "Server partly found",
|
||||
tone: "text-warn",
|
||||
text: "Some parts are missing. You can still add it; nothing will be fixed automatically.",
|
||||
},
|
||||
"unknown-custom": {
|
||||
title: "Custom server detected",
|
||||
tone: "text-warn",
|
||||
text: "This build is not recognised. Some update and install features will be disabled.",
|
||||
},
|
||||
incompatible: {
|
||||
title: "This is not a server folder",
|
||||
tone: "text-bad",
|
||||
text: "Choose the folder that contains Core, Data and mysql (or your worldserver.exe).",
|
||||
},
|
||||
};
|
||||
|
||||
export function ImportServer(props: {
|
||||
canCancel: boolean;
|
||||
onCancel: () => void;
|
||||
onAdded: (s: ServerSummary) => void | Promise<void>;
|
||||
}) {
|
||||
const [report, setReport] = useState<ScanReport | null>(null);
|
||||
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: "Choose your server folder" });
|
||||
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 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">Add an existing server</h1>
|
||||
<p className="mt-1 text-muted">Pick the folder your server runs from. It will only be read.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<Button variant="secondary" onClick={choose} disabled={busy}>
|
||||
{report ? "Choose another folder" : "Choose folder…"}
|
||||
</Button>
|
||||
{props.canCancel && (
|
||||
<Button variant="ghost" onClick={props.onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{busy && !report && <p className="text-muted">Looking at your server…</p>}
|
||||
|
||||
{error && (
|
||||
<Card className="border-bad/40 p-4" role="alert">
|
||||
<p className="font-medium text-bad">{error.human.title}</p>
|
||||
<p className="mt-1 text-sm text-muted">{error.human.message}</p>
|
||||
<details className="mt-2 text-xs text-muted">
|
||||
<summary className="cursor-pointer">Show technical details</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">{head.title}</h2>
|
||||
<p className="text-sm text-muted">{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>{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 /> Detected
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex items-center gap-1">
|
||||
<Minus className="h-4 w-4" aria-hidden /> {it.key === "companions" ? "Not installed" : "Not found"}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
{report.notes.map((n) => (
|
||||
<p key={n} className="mt-3 text-sm text-warn">
|
||||
{n}
|
||||
</p>
|
||||
))}
|
||||
|
||||
<div className="mt-5 flex items-center justify-between border-t border-line pt-4">
|
||||
<p className="text-sm text-muted">No files will be changed during import.</p>
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={add}
|
||||
disabled={busy || report.classification === "incompatible"}
|
||||
>
|
||||
Add server
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type Human, type ServerSummary, type ServiceStatus, type StatusView } from "@/lib/api";
|
||||
import { cn, formatUptime } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
type Action = "starting" | "stopping" | "restarting" | null;
|
||||
type Failure = { human: Human; technical: string };
|
||||
|
||||
function Row({ label, s }: { label: string; s: ServiceStatus }) {
|
||||
const running = s.state === "running";
|
||||
const starting = s.state === "starting";
|
||||
return (
|
||||
<div className="flex items-center justify-between py-2.5">
|
||||
<span>{label}</span>
|
||||
<span
|
||||
className={cn("flex items-center gap-2 text-sm", running ? "text-ok" : starting ? "text-warn" : "text-muted")}
|
||||
role="status"
|
||||
>
|
||||
<span
|
||||
aria-hidden
|
||||
className={cn(
|
||||
"h-2 w-2 rounded-full",
|
||||
running ? "bg-ok" : starting ? "animate-[pulse-dot_1.2s_ease-in-out_infinite] bg-warn" : "bg-muted/50",
|
||||
)}
|
||||
/>
|
||||
{running ? "Running" : starting ? "Starting…" : "Stopped"}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Overview({ server, onForget }: { server: ServerSummary; onForget: () => Promise<void> }) {
|
||||
const [status, setStatus] = useState<StatusView | null>(null);
|
||||
const [action, setAction] = useState<Action>(null);
|
||||
const [failure, setFailure] = useState<Failure | null>(null);
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const alive = useRef(true);
|
||||
|
||||
const poll = useCallback(async () => {
|
||||
try {
|
||||
const s = await api.status(server.id);
|
||||
if (alive.current) setStatus(s);
|
||||
} catch {
|
||||
/* transient; next poll retries */
|
||||
}
|
||||
}, [server.id]);
|
||||
|
||||
useEffect(() => {
|
||||
alive.current = true;
|
||||
void poll();
|
||||
const t = setInterval(poll, 2000);
|
||||
return () => {
|
||||
alive.current = false;
|
||||
clearInterval(t);
|
||||
};
|
||||
}, [poll]);
|
||||
|
||||
async function run(kind: Exclude<Action, null>) {
|
||||
setFailure(null);
|
||||
setShowDetails(false);
|
||||
setAction(kind);
|
||||
try {
|
||||
if (kind !== "starting") {
|
||||
const out = await api.stop(server.id);
|
||||
if (!out.ok) throw { human: out.human, technical: out.output };
|
||||
}
|
||||
if (kind !== "stopping") {
|
||||
setAction("starting");
|
||||
const out = await api.start(server.id);
|
||||
if (!out.ok) throw { human: out.human, technical: out.output };
|
||||
}
|
||||
} catch (e) {
|
||||
const ui = asUiError(e);
|
||||
setFailure({ human: ui.human ?? asUiError(String(e)).human, technical: ui.technical });
|
||||
} finally {
|
||||
setAction(null);
|
||||
void poll();
|
||||
}
|
||||
}
|
||||
|
||||
if (!status) return <p className="text-muted">Checking your server…</p>;
|
||||
if (!status.path_exists) {
|
||||
return (
|
||||
<div className="max-w-xl">
|
||||
<h1 className="text-2xl font-semibold">Server folder not found</h1>
|
||||
<p className="mt-2 text-muted">{server.path} is missing or was moved.</p>
|
||||
<Button className="mt-4" onClick={() => void onForget()}>
|
||||
Remove from Manager (no files are deleted)
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { mysql, auth, world } = status.observed;
|
||||
const all = [mysql, auth, world];
|
||||
const running = all.every((s) => s.state === "running");
|
||||
const anyUp = all.some((s) => s.state !== "stopped");
|
||||
const transitioning = action !== null || status.busy;
|
||||
const conflict = all.find((s) => s.conflict)?.conflict ?? null;
|
||||
|
||||
const headline = transitioning
|
||||
? action === "stopping"
|
||||
? "Stopping…"
|
||||
: "Starting…"
|
||||
: running
|
||||
? "Online"
|
||||
: anyUp
|
||||
? "Needs attention"
|
||||
: "Offline";
|
||||
const tone = transitioning ? "text-warn" : running ? "text-ok" : anyUp ? "text-warn" : "text-muted";
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl">
|
||||
<h1 className="text-2xl font-semibold">{server.name}</h1>
|
||||
<p className="selectable mt-0.5 text-xs text-muted">{server.path}</p>
|
||||
|
||||
<Card className="mt-6 p-7">
|
||||
<div className="mb-1 text-xs font-medium uppercase tracking-[0.14em] text-muted">Server</div>
|
||||
<div className={cn("flex items-center gap-3 text-3xl font-semibold", tone)} role="status" aria-live="polite">
|
||||
<span
|
||||
aria-hidden
|
||||
className={cn("h-3 w-3 rounded-full", running && !transitioning ? "bg-ok" : transitioning || anyUp ? "bg-warn" : "bg-muted/50")}
|
||||
/>
|
||||
{headline}
|
||||
</div>
|
||||
|
||||
<div className="mt-5 divide-y divide-line border-y border-line">
|
||||
<Row label="Database" s={mysql} />
|
||||
<Row label="Auth server" s={auth} />
|
||||
<Row label="World server" s={world} />
|
||||
</div>
|
||||
|
||||
<dl className="mt-4 grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<dt className="text-muted">Uptime</dt>
|
||||
<dd className="mt-0.5 text-lg">{world.state === "running" ? formatUptime(world.uptime_secs) : "—"}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted">Players online</dt>
|
||||
<dd className="mt-0.5 text-lg text-muted">—</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<div className="mt-7 flex items-center gap-4">
|
||||
{running ? (
|
||||
<Button variant="secondary" size="xl" disabled={transitioning} onClick={() => run("stopping")} className="min-w-56">
|
||||
{transitioning && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
STOP SERVER
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="primary" size="xl" disabled={transitioning} onClick={() => run("starting")} className="min-w-56">
|
||||
{transitioning && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
{transitioning ? (action === "stopping" ? "STOPPING…" : "STARTING…") : "START SERVER"}
|
||||
</Button>
|
||||
)}
|
||||
{running && (
|
||||
<Button variant="ghost" size="sm" disabled={transitioning} onClick={() => run("restarting")}>
|
||||
Restart
|
||||
</Button>
|
||||
)}
|
||||
{anyUp && !running && (
|
||||
<Button variant="ghost" size="sm" disabled={transitioning} onClick={() => run("stopping")}>
|
||||
Stop
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{anyUp && !running && !transitioning && (
|
||||
<p className="mt-3 text-sm text-muted">Some parts are running. Press Start to bring up the rest, or Stop to shut everything down.</p>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{conflict && !anyUp && (
|
||||
<Card className="mt-4 border-warn/40 p-4" role="alert">
|
||||
<p className="font-medium text-warn">A port this server needs is already in use</p>
|
||||
<p className="mt-1 text-sm text-muted">
|
||||
Port {conflict.port} is used by another program{conflict.exe ? ` (${conflict.exe})` : ""}.
|
||||
</p>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{failure && (
|
||||
<Card className="mt-4 border-bad/40 p-5" role="alert">
|
||||
<p className="font-medium text-bad">{failure.human.title}</p>
|
||||
<p className="mt-1 text-sm text-muted">{failure.human.message}</p>
|
||||
<div className="mt-3 flex gap-2">
|
||||
<Button size="sm" onClick={() => setShowDetails((v) => !v)}>
|
||||
{showDetails ? "Hide details" : "View details"}
|
||||
</Button>
|
||||
<Button size="sm" variant="ghost" onClick={() => void navigator.clipboard.writeText(failure.technical)}>
|
||||
Copy error
|
||||
</Button>
|
||||
</div>
|
||||
{showDetails && (
|
||||
<pre className="mt-3 max-h-56 overflow-auto whitespace-pre-wrap rounded bg-black/40 p-3 text-xs text-muted">
|
||||
{failure.technical || "(no output)"}
|
||||
</pre>
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export function Placeholder({ title, question }: { title: string; question: string }) {
|
||||
return (
|
||||
<div className="max-w-xl">
|
||||
<h1 className="text-2xl font-semibold">{title}</h1>
|
||||
<p className="mt-1 text-muted">{question}</p>
|
||||
<p className="mt-8 rounded-card border border-line bg-card/70 p-5 text-sm text-muted">
|
||||
This section is being built in a later release.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useState } from "react";
|
||||
import { Archive, Bot, Gauge, Globe, Server, Settings, Terminal, Users, type LucideIcon } from "lucide-react";
|
||||
import { type ServerSummary } from "@/lib/api";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Overview } from "@/screens/Overview";
|
||||
import { Placeholder } from "@/screens/Placeholder";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
type Page = "overview" | "bots" | "server" | "players" | "friends" | "backups" | "console" | "settings";
|
||||
|
||||
const NAV: { id: Page; label: string; icon: LucideIcon; question: string }[] = [
|
||||
{ id: "overview", label: "Overview", icon: Gauge, question: "Is my server running?" },
|
||||
{ id: "bots", label: "Bots", icon: Bot, question: "How are my bots configured?" },
|
||||
{ id: "server", label: "Server", icon: Server, question: "How does my server behave?" },
|
||||
{ id: "players", label: "Players", icon: Users, question: "Who is playing right now?" },
|
||||
{ id: "friends", label: "Play with Friends", icon: Globe, question: "How can my friend join?" },
|
||||
{ id: "backups", label: "Backups", icon: Archive, question: "Is my data safe?" },
|
||||
{ id: "console", label: "Console", icon: Terminal, question: "What is the server doing?" },
|
||||
{ id: "settings", label: "Settings", icon: Settings, question: "How does Manager behave?" },
|
||||
];
|
||||
|
||||
export function Shell(props: {
|
||||
servers: ServerSummary[];
|
||||
activeId: string;
|
||||
onSelect: (id: string) => void;
|
||||
onAddAnother: () => void;
|
||||
onForget: (id: string) => Promise<void>;
|
||||
}) {
|
||||
const [page, setPage] = useState<Page>("overview");
|
||||
const server = props.servers.find((s) => s.id === props.activeId)!;
|
||||
const current = NAV.find((n) => n.id === page)!;
|
||||
|
||||
return (
|
||||
<div className="flex h-full">
|
||||
<nav className="flex w-60 shrink-0 flex-col border-r border-line bg-[#0b0c0e] p-3" aria-label="Main">
|
||||
<div className="px-3 pb-4 pt-2 text-sm font-semibold tracking-wide text-gold">CoA Server Manager</div>
|
||||
<ul className="flex flex-col gap-0.5">
|
||||
{NAV.map(({ id, label, icon: Icon }) => (
|
||||
<li key={id}>
|
||||
<button
|
||||
onClick={() => setPage(id)}
|
||||
aria-current={page === id ? "page" : undefined}
|
||||
className={cn(
|
||||
"flex h-10 w-full cursor-pointer items-center gap-3 rounded-md px-3 text-left text-[15px] transition-colors",
|
||||
page === id ? "bg-white/[0.07] text-ink" : "text-muted hover:bg-white/5 hover:text-ink",
|
||||
)}
|
||||
>
|
||||
<Icon className={cn("h-[18px] w-[18px]", page === id && "text-gold")} aria-hidden />
|
||||
{label}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<div className="mt-auto border-t border-line pt-3">
|
||||
{props.servers.length > 1 && (
|
||||
<select
|
||||
className="mb-2 w-full rounded-md border border-line bg-card px-2 py-2 text-sm"
|
||||
value={props.activeId}
|
||||
onChange={(e) => props.onSelect(e.target.value)}
|
||||
aria-label="Server"
|
||||
>
|
||||
{props.servers.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
<Button variant="ghost" size="sm" className="w-full justify-start" onClick={props.onAddAnother}>
|
||||
Manage another server
|
||||
</Button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main className="h-full flex-1 overflow-y-auto px-10 py-8">
|
||||
{page === "overview" ? (
|
||||
<Overview key={server.id} server={server} onForget={() => props.onForget(server.id)} />
|
||||
) : (
|
||||
<Placeholder title={current.label} question={current.question} />
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { FolderSearch, Download } from "lucide-react";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export function Welcome({ onImport }: { onImport: () => void }) {
|
||||
return (
|
||||
<main className="flex h-full flex-col items-center justify-center px-8">
|
||||
<div className="mb-10 text-center">
|
||||
<div className="mx-auto mb-5 h-12 w-12 rounded-full border-2 border-gold/80 bg-card-2" aria-hidden />
|
||||
<h1 className="text-3xl font-semibold tracking-tight">Welcome to CoA Server Manager</h1>
|
||||
<p className="mt-2 text-muted">Run your own Conquest of Azeroth server — no technical knowledge needed.</p>
|
||||
</div>
|
||||
|
||||
<div className="grid w-full max-w-3xl grid-cols-2 gap-5">
|
||||
<Card className="p-7 opacity-60" aria-disabled="true">
|
||||
<Download className="mb-4 h-7 w-7 text-gold" aria-hidden />
|
||||
<h2 className="text-lg font-semibold">Install new server</h2>
|
||||
<p className="mt-1 text-sm text-muted">One-click setup with everything included.</p>
|
||||
<p className="mt-4 inline-block rounded bg-white/5 px-2 py-1 text-xs text-muted">Coming in a later release</p>
|
||||
</Card>
|
||||
|
||||
<button
|
||||
onClick={onImport}
|
||||
className="cursor-pointer rounded-card border border-line bg-card/90 p-7 text-left shadow-[0_8px_30px_rgb(0_0_0/0.28)] transition-colors hover:border-gold/60"
|
||||
>
|
||||
<FolderSearch className="mb-4 h-7 w-7 text-gold" aria-hidden />
|
||||
<h2 className="text-lg font-semibold">I already have a server</h2>
|
||||
<p className="mt-1 text-sm text-muted">
|
||||
Add your existing server. It is only read — nothing is changed.
|
||||
</p>
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user