mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-26 03:25:56 +00:00
Stabilize server lifecycle, client settings and release qualification
This commit is contained in:
1 parent
4d1a6e0b21
commit
30d2f56997
71 files changed
+2785
-168
No files matched your search
@@ -193,6 +193,17 @@ function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog:
|
||||
}
|
||||
|
||||
export function BrowsePage() {
|
||||
const { t } = useI18n();
|
||||
const [enabled, setEnabled] = useState<boolean | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => { void browse.enabled().then(setEnabled).catch(e => setError(asUiError(e).technical)); }, []);
|
||||
if (error) return <p role="alert" className="text-bad">{error}</p>;
|
||||
if (enabled === null) return <Loader2 className="h-5 w-5 animate-spin" aria-label={t("portable.make.loading")} />;
|
||||
if (!enabled) return <div><h1 className="text-2xl font-semibold">{t("browse.title")}</h1><p className="mt-2 text-muted">{t("browse.disabled")}</p></div>;
|
||||
return <EnabledBrowsePage />;
|
||||
}
|
||||
|
||||
function EnabledBrowsePage() {
|
||||
const { t } = useI18n();
|
||||
const { status } = useRegistryStatus(5000);
|
||||
const [q, setQ] = useState("");
|
||||
@@ -213,6 +224,7 @@ export function BrowsePage() {
|
||||
const [preferredSaved, setPreferredSaved] = useState("");
|
||||
const [preferredNote, setPreferredNote] = useState<string | null>(null);
|
||||
const ticket = useRef(0);
|
||||
const [requested, setRequested] = useState(false);
|
||||
|
||||
useEffect(() => { void control.status().then((c) => { setPreferred(c.preferred_username); setPreferredSaved(c.preferred_username); }).catch(() => {}); }, []);
|
||||
useEffect(() => { void browse.modules().then((m) => setCatalog(Object.fromEntries(m.map((x) => [x.id, x])))).catch(() => {}); }, []);
|
||||
@@ -244,10 +256,10 @@ export function BrowsePage() {
|
||||
}, [params]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!status?.url) return;
|
||||
if (!requested || !status?.url) return;
|
||||
const timer = setTimeout(() => void load(), q ? 300 : 0);
|
||||
return () => clearTimeout(timer);
|
||||
}, [load, status?.url]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [load, status?.url, requested]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
function onSort(k: SortKey) {
|
||||
if (k === sort) setOrder((o) => (o === "asc" ? "desc" : "asc"));
|
||||
@@ -263,7 +275,7 @@ export function BrowsePage() {
|
||||
<h1 className="text-2xl font-semibold">{t("browse.title")}</h1>
|
||||
<p className="mt-1 text-sm text-muted">{t("browse.text")}</p>
|
||||
</div>
|
||||
<Button size="sm" onClick={() => void load()} disabled={loading || noUrl}>{loading ? <Loader2 className="h-4 w-4 animate-spin" aria-hidden /> : <RefreshCw className="h-4 w-4" aria-hidden />}{t("browse.refresh")}</Button>
|
||||
<Button size="sm" onClick={() => { if (requested) void load(); else setRequested(true); }} disabled={loading || noUrl}>{loading ? <Loader2 className="h-4 w-4 animate-spin" aria-hidden /> : <RefreshCw className="h-4 w-4" aria-hidden />}{t("browse.refresh")}</Button>
|
||||
</div>
|
||||
|
||||
{noUrl && <p className="mt-2 text-sm text-warn">{t("browse.noUrl")}</p>}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { listen } from "@tauri-apps/api/event";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { api, asUiError, type ClientInfo, type ClientStatus, type UiError } from "@/lib/api";
|
||||
import { checkClient } from "@/lib/clientUpdate";
|
||||
import { ClientGraphics } from "./ClientGraphics";
|
||||
import { ClientDialog, type ClientDialogMode } from "@/screens/ClientDialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
@@ -95,6 +96,7 @@ export function ClientCard({ serverId, remote = false }: { serverId: string; rem
|
||||
<dt className="text-muted">{t("client.otherAddons")}</dt>
|
||||
<dd>{t("client.leftAsIs", { n: info.other_addons })}</dd>
|
||||
</dl>
|
||||
<ClientGraphics key={info.path} serverId={serverId} />
|
||||
{!remote && (
|
||||
<label className="mt-4 flex cursor-pointer items-center gap-2 text-sm">
|
||||
<input type="checkbox" checked={playAfter} onChange={(e) => setPlayAfter(e.target.checked)} className="h-4 w-4 accent-[#c9a24a]" />
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, asUiError } from "@/lib/api";
|
||||
import { checkClient } from "@/lib/clientUpdate";
|
||||
import { useI18n } from "@/i18n";
|
||||
|
||||
export function ClientGraphics({ serverId }: { serverId: string }) {
|
||||
const { t } = useI18n();
|
||||
const [state, setState] = useState<{ dxvk_disabled: boolean; enhancements_disabled: boolean } | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => { void api.clientGraphics(serverId).then(setState).catch(e => setError(asUiError(e).technical)); }, [serverId]);
|
||||
async function change(name: string, disabled: boolean) {
|
||||
setBusy(true); setError(null);
|
||||
try { setState(await api.clientSetGraphics(serverId, name, disabled)); await checkClient(serverId); }
|
||||
catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <div className="mt-5 space-y-3 border-t border-line pt-4">
|
||||
<label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={state?.dxvk_disabled ?? false} disabled={!state || busy} onChange={e => void change("d3d9.dll", e.target.checked)} />{t("client.graphics.dxvk")}</label>
|
||||
<label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={state?.enhancements_disabled ?? false} disabled={!state || busy} onChange={e => void change("dxgi.dll", e.target.checked)} />{t("client.graphics.enhancements")}</label>
|
||||
<p className="text-xs text-muted">{t("client.graphics.hint")}</p>
|
||||
{error && <p className="text-sm text-bad" role="alert">{error}</p>}
|
||||
</div>;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useI18n } from "@/i18n";
|
||||
|
||||
export function ForceStopDialog({ onCancel, onConfirm }: { onCancel: () => void; onConfirm: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const panel = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
const previous = document.activeElement;
|
||||
panel.current?.querySelector<HTMLButtonElement>("button")?.focus();
|
||||
return () => { if (previous instanceof HTMLElement) previous.focus(); };
|
||||
}, []);
|
||||
return <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-5">
|
||||
<div ref={panel} role="alertdialog" aria-modal="true" aria-labelledby="force-stop-title" aria-describedby="force-stop-warning" className="w-full max-w-lg rounded-lg border border-bad/40 bg-card p-6" onKeyDown={e => {
|
||||
if (e.key === "Escape") { e.preventDefault(); onCancel(); }
|
||||
if (e.key === "Tab") {
|
||||
const buttons = panel.current?.querySelectorAll<HTMLButtonElement>("button");
|
||||
if (!buttons?.length) return;
|
||||
if (e.shiftKey && document.activeElement === buttons[0]) { e.preventDefault(); buttons[buttons.length - 1].focus(); }
|
||||
else if (!e.shiftKey && document.activeElement === buttons[buttons.length - 1]) { e.preventDefault(); buttons[0].focus(); }
|
||||
}
|
||||
}}>
|
||||
<h2 id="force-stop-title" className="text-lg font-semibold">{t("stop.forceTitle")}</h2>
|
||||
<p id="force-stop-warning" className="mt-3 text-sm text-muted">{t("stop.forceWarning")}</p>
|
||||
<div className="mt-5 flex justify-end gap-3"><Button onClick={onCancel}>{t("stop.cancel")}</Button><Button variant="secondary" onClick={onConfirm}>{t("stop.force")}</Button></div>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
+27
-15
@@ -1,3 +1,6 @@
|
||||
import { ForceStopDialog } from "./ForceStopDialog";
|
||||
import { serverLifecycle } from "@/lib/serverLifecycle";
|
||||
import { serverUpdateBlocksRestart } from "@/lib/serverUpdate";
|
||||
import { dismissClientJob, startClientUpdate, stopClientJob, syncClient, useClientJob } from "@/lib/clientJob";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { AlertTriangle, Loader2, X } from "lucide-react";
|
||||
@@ -91,6 +94,8 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
}, [bothWorlds, server.id]);
|
||||
const [action, setAction] = useState<Action>(null);
|
||||
const [realmBusy, setRealmBusy] = useState(false);
|
||||
const [stopFailed, setStopFailed] = useState(false);
|
||||
const [confirmForce, setConfirmForce] = useState(false);
|
||||
const [failure, setFailure] = useState<Failure | null>(null);
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const [pop, setPop] = useState<Population | null>(null);
|
||||
@@ -131,8 +136,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
const [crashLoopPaused, setCrashLoopPaused] = useState(false);
|
||||
const [crashRestartNotice, setCrashRestartNotice] = useState<string | null>(null);
|
||||
|
||||
const userStoppedRef = useRef(false);
|
||||
const wasWorldRunningRef = useRef(false);
|
||||
const lifecycle = serverLifecycle(server.id);
|
||||
const actionRef = useRef<Action>(null);
|
||||
const crashTimestampsRef = useRef<number[]>([]);
|
||||
const pollRef = useRef<() => Promise<void>>(undefined);
|
||||
@@ -168,10 +172,9 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
|
||||
const run = useCallback(
|
||||
async (kind: Exclude<Action, null>) => {
|
||||
if (kind === "stopping") {
|
||||
userStoppedRef.current = true;
|
||||
} else {
|
||||
userStoppedRef.current = false;
|
||||
setStopFailed(false);
|
||||
lifecycle.request(kind);
|
||||
if (kind !== "stopping") {
|
||||
setCrashLoopPaused(false);
|
||||
setCrashRestartNotice(null);
|
||||
}
|
||||
@@ -181,8 +184,8 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
actionRef.current = kind;
|
||||
try {
|
||||
if (kind !== "starting") {
|
||||
const out = await api.stop(server.id);
|
||||
if (!out.ok) throw { human: out.human, technical: out.output };
|
||||
const out = await api.stop(server.id).catch(e => { setStopFailed(true); throw e; });
|
||||
if (!out.ok) { setStopFailed(true); throw { human: out.human, technical: out.output }; }
|
||||
}
|
||||
if (kind !== "stopping") {
|
||||
setAction("starting");
|
||||
@@ -194,6 +197,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
const ui = asUiError(e);
|
||||
setFailure({ human: ui.human ?? asUiError(String(e)).human, technical: ui.technical });
|
||||
} finally {
|
||||
lifecycle.complete(kind);
|
||||
setAction(null);
|
||||
actionRef.current = null;
|
||||
void pollRef.current?.();
|
||||
@@ -202,24 +206,30 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
[server.id],
|
||||
);
|
||||
|
||||
async function forceStop() {
|
||||
setConfirmForce(false); setFailure(null); setShowDetails(false); setStopFailed(false);
|
||||
lifecycle.request("stopping"); setAction("stopping"); actionRef.current = "stopping";
|
||||
try {
|
||||
const out = await api.forceStop(server.id);
|
||||
if (!out.ok) throw { human: out.human, technical: out.output };
|
||||
} catch (e) { setStopFailed(true); setFailure(asUiError(e)); }
|
||||
finally { lifecycle.complete("stopping"); setAction(null); actionRef.current = null; void pollRef.current?.(); }
|
||||
}
|
||||
|
||||
const poll = useCallback(async () => {
|
||||
try {
|
||||
const s = await api.status(server.id);
|
||||
if (alive.current) setStatus(s);
|
||||
const isWorldRunning = s.observed.world.state === "running";
|
||||
if (isWorldRunning) {
|
||||
wasWorldRunningRef.current = true;
|
||||
userStoppedRef.current = false;
|
||||
lifecycle.observe(true, actionRef.current !== null, serverUpdateBlocksRestart(server.id));
|
||||
const p = await api.population(server.id).catch(() => null);
|
||||
if (alive.current) setPop(p);
|
||||
} else {
|
||||
if (alive.current) setPop(null);
|
||||
if (
|
||||
wasWorldRunningRef.current &&
|
||||
!userStoppedRef.current &&
|
||||
actionRef.current === null
|
||||
lifecycle.observe(false, actionRef.current !== null, serverUpdateBlocksRestart(server.id))
|
||||
) {
|
||||
wasWorldRunningRef.current = false;
|
||||
setHasCrashHistory(true);
|
||||
const now = Date.now();
|
||||
const recent = crashTimestampsRef.current.filter((ts) => now - ts < 180000);
|
||||
@@ -401,7 +411,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-muted">{t("overview.players")}</dt>
|
||||
<dd className="mt-0.5 text-lg">{pop ? `${pop.players_online}` : "—"}{companions && pop && pop.bots_online > 0 ? <span className="ml-2 text-sm text-muted">{t("overview.companions", { n: pop.bots_online })}</span> : null}</dd>
|
||||
<dd className="mt-0.5 text-lg">{pop ? `${pop.players_online}` : "—"}{pop && pop.bots_online > 0 ? <span className="ml-2 text-sm text-muted">{t("overview.bots", { n: pop.bots_online })}</span> : null}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
{companions && startBots !== undefined && (
|
||||
@@ -620,6 +630,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
<Card className="mt-4 border-bad/40 p-5" role="alert">
|
||||
<p className="font-medium text-bad">{human(visibleFailure.human).title}</p>
|
||||
<p className="mt-1 text-sm text-muted">{human(visibleFailure.human).message}</p>
|
||||
{anyUp && (stopFailed || /still stopping|could not be stopped|Stop the server before updating/i.test(visibleFailure.technical)) && <Button className="mt-3" size="sm" variant="secondary" disabled={transitioning || upd.applying} onClick={() => setConfirmForce(true)}>{t("stop.force")}</Button>}
|
||||
<div className="mt-3 flex gap-2">
|
||||
<Button size="sm" onClick={() => setShowDetails((v) => !v)}>
|
||||
{showDetails ? t("common.hideDetails") : t("common.viewDetails")}
|
||||
@@ -650,6 +661,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
)}
|
||||
|
||||
{publishing && <PublishRealmDialog realm={publishing} onClose={() => setPublishing(null)} />}
|
||||
{confirmForce && <ForceStopDialog onCancel={() => setConfirmForce(false)} onConfirm={() => void forceStop()} />}
|
||||
{showCrashModal && (
|
||||
<CrashHistoryModal
|
||||
serverId={server.id}
|
||||
|
||||
@@ -36,12 +36,12 @@ export function PlayersPage({ serverId }: { serverId: string }) {
|
||||
try {
|
||||
await api.createAccount(serverId, username, password, admin);
|
||||
setDone(username);
|
||||
setCreated((n) => n + 1);
|
||||
setUsername("");
|
||||
setPassword("");
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
setCreated((n) => n + 1);
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useI18n } from "@/i18n";
|
||||
import { browse } from "@/lib/browse";
|
||||
import { asUiError } from "@/lib/api";
|
||||
|
||||
export function PublicServerSettings() {
|
||||
const { t } = useI18n();
|
||||
const [enabled, setEnabled] = useState<boolean | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => { void browse.enabled().then(setEnabled).catch(e => setError(asUiError(e).technical)); }, []);
|
||||
async function change(next: boolean) {
|
||||
setBusy(true); setError(null);
|
||||
try { await browse.setEnabled(next); setEnabled(next); }
|
||||
catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <Card className="mt-6 p-6">
|
||||
<label className="flex items-center gap-3 font-semibold"><input type="checkbox" checked={enabled === true} disabled={enabled === null || busy} onChange={e => void change(e.target.checked)} aria-describedby="public-server-hint" />{t("settings.publicServers")}</label>
|
||||
<p id="public-server-hint" className="mt-2 text-sm text-muted">{t("settings.publicServersHint")}</p>
|
||||
{error && <p role="alert" className="mt-2 text-sm text-bad">{error}</p>}
|
||||
</Card>;
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import { ClientDialog, type ClientDialogMode } from "@/screens/ClientDialog";
|
||||
import { AboutCard } from "@/screens/AboutCard";
|
||||
import { PortablePage } from "@/screens/PortablePage";
|
||||
import { BrowsePage } from "@/screens/BrowsePage";
|
||||
import { WindowSettings } from "./WindowSettings";
|
||||
import { PublicServerSettings } from "./PublicServerSettings";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
@@ -65,7 +67,7 @@ export function RemoteClient({ onHost }: { onHost: () => void }) {
|
||||
<div className="mt-auto border-t border-line pt-3"><Button variant="ghost" size="sm" className="w-full justify-start" onClick={onHost}>{t("remote.hostInstead")}</Button></div>
|
||||
</nav>
|
||||
<main className="h-full flex-1 overflow-y-auto px-10 py-8">
|
||||
{page === "servers" ? <BrowsePage /> : page === "characters" ? <PortablePage /> : page === "settings" ? <><div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("nav.settings")}</h1><LanguagePicker /></div><AboutCard /></> : <>
|
||||
{page === "servers" ? <BrowsePage /> : page === "characters" ? <PortablePage /> : page === "settings" ? <><div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("nav.settings")}</h1><LanguagePicker /></div><WindowSettings /><PublicServerSettings /><AboutCard /></> : <>
|
||||
<div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("welcome.connect.title")}</h1><LanguagePicker /></div>
|
||||
<p className="mt-2 text-muted">{t("remote.intro")}</p>
|
||||
<Card className="mt-6 p-6">
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import { Download, Power, FolderOpen, Wrench, Languages } from "lucide-react";
|
||||
import { useI18n } from "@/i18n";
|
||||
import { WindowSettings } from "./WindowSettings";
|
||||
import { PublicServerSettings } from "./PublicServerSettings";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useServerUpdate } from "@/lib/serverUpdate";
|
||||
@@ -50,6 +52,6 @@ export function SettingsHome({ serverId, path, onForget }: { serverId: string; s
|
||||
<div hidden={section !== "startup"} className="max-w-3xl"><RealmStartupSettings serverId={serverId} /><AutoRestartSettings serverId={serverId} /></div>
|
||||
<div hidden={section !== "client"} className="max-w-3xl"><ClientCard serverId={serverId} /><GameDataCard serverId={serverId} /></div>
|
||||
<div hidden={section !== "service"} className="max-w-3xl"><DiagnosticsCard serverId={serverId} /><RepairCard serverId={serverId} /><RemoveServerCard serverId={serverId} path={path} onForget={onForget} /></div>
|
||||
<div hidden={section !== "interface"} className="max-w-3xl"><Card className="mt-6 p-6"><h2 className="font-semibold">{t("settings.language")}</h2><p className="mt-1 text-sm text-muted">{t("settings.languageHint")}</p><LanguagePicker className="mt-4" /></Card></div>
|
||||
<div hidden={section !== "interface"} className="max-w-3xl"><Card className="mt-6 p-6"><h2 className="font-semibold">{t("settings.language")}</h2><p className="mt-1 text-sm text-muted">{t("settings.languageHint")}</p><LanguagePicker className="mt-4" /></Card><WindowSettings /><PublicServerSettings /></div>
|
||||
</div>;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useI18n } from "@/i18n";
|
||||
import { asUiError } from "@/lib/api";
|
||||
|
||||
export function WindowSettings() {
|
||||
const { t } = useI18n();
|
||||
const [enabled, setEnabled] = useState<boolean | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => { void invoke<boolean>("close_to_tray").then(setEnabled).catch(e => setError(asUiError(e).technical)); }, []);
|
||||
async function change(next: boolean) {
|
||||
setBusy(true); setError(null);
|
||||
try { await invoke("set_close_to_tray", { enabled: next }); setEnabled(next); }
|
||||
catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <Card className="mt-6 p-6">
|
||||
<label className="flex items-center gap-3 font-semibold"><input type="checkbox" checked={enabled === true} disabled={enabled === null || busy} onChange={e => void change(e.target.checked)} aria-describedby="close-window-hint" />{t("settings.closeToTray")}</label>
|
||||
<p id="close-window-hint" className="mt-2 text-sm text-muted">{t("settings.closeToTrayHint")}</p>
|
||||
{error && <p role="alert" className="mt-2 text-sm text-bad">{error}</p>}
|
||||
</Card>;
|
||||
}
|
||||
Reference in new issue
Block a user