mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
Phase 8: game client integration (read-only detection, backed-up realmlist change, isolated addon install, START & PLAY)
Verified in the native UI with a stub client: realmlist pointed and backed up, addon installed without touching other addons, START & PLAY starts the server, waits for ready, then launches the client. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7b1942e6a1
commit
d85050ff95
8 files changed
+505
-2
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { api, asUiError, type ClientInfo, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export function ClientCard({ serverId }: { serverId: string }) {
|
||||
const [info, setInfo] = useState<ClientInfo | null | undefined>(undefined);
|
||||
const [error, setError] = useState<UiError | null>(null);
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const refresh = () => api.clientInfo(serverId).then(setInfo).catch((e) => setError(asUiError(e)));
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
}, [serverId]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
async function run(fn: () => Promise<string | void>) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setNote(null);
|
||||
try {
|
||||
const msg = await fn();
|
||||
if (msg) setNote(msg);
|
||||
await refresh();
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function choose() {
|
||||
const picked = await open({ directory: true, multiple: false, title: "Choose your game client folder" });
|
||||
if (typeof picked === "string") await run(async () => void (await api.setClient(serverId, picked)));
|
||||
}
|
||||
|
||||
const hosts = info?.realmlists.map((r) => r.host) ?? [];
|
||||
const pointsLocal = hosts.length > 0 && hosts.every((h) => h === "127.0.0.1" || h === "localhost");
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">Game client</h2>
|
||||
{info === undefined && <p className="mt-2 text-sm text-muted">Looking…</p>}
|
||||
{info === null && (
|
||||
<>
|
||||
<p className="mt-1 text-sm text-muted">Tell Manager where your game is installed to get a PLAY button. Your game files are never changed except the server address and the companion addon.</p>
|
||||
<Button className="mt-4" onClick={() => void choose()} disabled={busy}>Choose game folder…</Button>
|
||||
</>
|
||||
)}
|
||||
{info && (
|
||||
<>
|
||||
<p className="selectable mt-1 break-all text-sm text-muted">{info.path}</p>
|
||||
<dl className="mt-4 grid grid-cols-[auto_1fr] gap-x-6 gap-y-2 text-sm">
|
||||
<dt className="text-muted">Connects to</dt>
|
||||
<dd>
|
||||
{hosts.length ? hosts.filter(Boolean).join(", ") : "—"}
|
||||
{pointsLocal ? <span className="ml-2 text-ok">✓ this computer</span> : <span className="ml-2 text-warn">not this server</span>}
|
||||
</dd>
|
||||
<dt className="text-muted">Companion addon</dt>
|
||||
<dd>
|
||||
{info.addon.installed ? `Installed${info.addon.version ? ` (version ${info.addon.version})` : ""}` : "Not installed"}
|
||||
{info.addon.up_to_date === false && <span className="ml-2 text-warn">an update is available</span>}
|
||||
</dd>
|
||||
<dt className="text-muted">Other addons</dt>
|
||||
<dd>{info.other_addons} — left exactly as they are</dd>
|
||||
</dl>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
{!pointsLocal && (
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.setRealmlist(serverId, "127.0.0.1"); return "The game now connects to this computer. The previous address was saved."; })}>
|
||||
Point the game at this server
|
||||
</Button>
|
||||
)}
|
||||
{(!info.addon.installed || info.addon.up_to_date === false) && (
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.installAddon(serverId); return "Companion addon installed. Other addons were not touched."; })}>
|
||||
{info.addon.installed ? "Update companion addon" : "Install companion addon"}
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" variant="ghost" disabled={busy} onClick={() => void choose()}>Change folder…</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{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 : error.human.message}</p>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type Human, type Population, type ServerSummary, type ServiceStatus, type StatusView } from "@/lib/api";
|
||||
import { api, asUiError, type ClientInfo, type Human, type Population, 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";
|
||||
@@ -37,6 +37,8 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget
|
||||
const [failure, setFailure] = useState<Failure | null>(null);
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const [pop, setPop] = useState<Population | null>(null);
|
||||
const [client, setClient] = useState<ClientInfo | null>(null);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const alive = useRef(true);
|
||||
|
||||
const poll = useCallback(async () => {
|
||||
@@ -54,6 +56,7 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget
|
||||
|
||||
useEffect(() => {
|
||||
alive.current = true;
|
||||
void api.clientInfo(server.id).then(setClient).catch(() => setClient(null));
|
||||
void poll();
|
||||
const t = setInterval(poll, 2000);
|
||||
return () => {
|
||||
@@ -85,6 +88,22 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget
|
||||
}
|
||||
}
|
||||
|
||||
async function play() {
|
||||
setFailure(null);
|
||||
setShowDetails(false);
|
||||
setPlaying(true);
|
||||
try {
|
||||
const out = await api.play(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 {
|
||||
setPlaying(false);
|
||||
void poll();
|
||||
}
|
||||
}
|
||||
|
||||
if (!status) return <p className="text-muted">Checking your server…</p>;
|
||||
if (!status.path_exists) {
|
||||
return (
|
||||
@@ -170,6 +189,12 @@ export function Overview({ server, onForget }: { server: ServerSummary; onForget
|
||||
Stop
|
||||
</Button>
|
||||
)}
|
||||
{client && (
|
||||
<Button variant={running ? "primary" : "secondary"} size="xl" disabled={transitioning || playing} onClick={() => void play()} className="ml-auto min-w-40">
|
||||
{playing && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
{running ? "PLAY" : "START & PLAY"}
|
||||
</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>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ChevronDown, ChevronRight, Loader2 } from "lucide-react";
|
||||
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";
|
||||
|
||||
const ACTION_TEXT: Record<string, string> = {
|
||||
create: "New file",
|
||||
@@ -110,6 +111,8 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<ClientCard serverId={serverId} />
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">Server updates</h2>
|
||||
<p className="mt-1 text-sm text-muted">Updates are checked for authenticity, backed up first, and can be undone.</p>
|
||||
|
||||
Reference in new issue
Block a user