mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 19:25:56 +00:00
Companions: progress bar while the server creates them (n of N added); offline creation shows a busy bar
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5bbe5adff1
commit
dd066f2094
9 files changed
+77
-8
No files matched your search
+2
-1
@@ -30,7 +30,8 @@ export {};
|
||||
if(cmd==="list_presets"){const pr=args?.scope==="server"?serverPresets:botsPresets;return (pr.presets as any[]).map(p=>({id:p.id,title:p.title,description:p.description}));}
|
||||
if(cmd==="preview_preset"){const a=args;const sc=a.scope==="server"?serverSchema:botsSchema;const pr=(a.scope==="server"?serverPresets:botsPresets).presets as any[];const p=pr.find(x=>x.id===a.preset)??{id:a.preset??"defaults",title:"Recommended defaults",description:"Every setting returns to its default value."};const st=(sc.settings as any[]).filter(x=>x.type==="int"||x.type==="float"||x.type==="enum").slice(0,3);return {id:p.id,title:p.title,description:p.description,changes:st.map(x=>({key:x.key,title:x.title,from:x.default,to:x.type==="enum"?(x.options?.[1]?.value??x.default):(Number(x.default)||1)*2,dangerous:false}))};}
|
||||
if(cmd==="companion_sizes") return {hardware:{cores:16,ram_gb:31,free_ram_gb:12},sizes:[{id:"small",title:"Small",bots:50,warning:null},{id:"medium",title:"Medium",bots:250,warning:null},{id:"large",title:"Large",bots:500,warning:"500 companions may need more CPU and memory than this computer has (8 cores, 16 GB)."}]};
|
||||
if(cmd==="get_population") return null;
|
||||
if(cmd==="add_companions"){const base=(window as any).__bots??85;(window as any).__target=base+args.count;return {spawned:"queued",created:null,baseline:base};}
|
||||
if(cmd==="get_population"){if(!running) return null;let b=(window as any).__bots??85;const t=(window as any).__target??0;if(t>b){b=Math.min(t,b+25);(window as any).__bots=b;}return {online_total:b,bots_online:Math.max(0,b-7),players_online:0,bots_total:b};}
|
||||
if(cmd==="get_performance") return running?{mean_ms:14,median_ms:15,p95_ms:24,p99_ms:30,max_ms:61,ticks_per_sec:71.4}:null;
|
||||
if(cmd==="run_diagnostics") return {problems:2,checks:[{id:"files",title:"Server files",level:"ok",detail:"All expected server parts were found."},{id:"world",title:"World server",level:"warn",detail:"Not running."},{id:"disk",title:"Free disk space",level:"warn",detail:"Only 3 GB free; backups and updates need room."},{id:"exposure",title:"Private services",level:"ok",detail:"Database and server console are not reachable from the network."}]};
|
||||
if(cmd==="plugin:event|listen") return 1;
|
||||
|
||||
@@ -543,6 +543,12 @@ const de: Partial<Record<keyof typeof en, string>> = {
|
||||
|
||||
// Offline bots
|
||||
"comp.offlineDone": "{n} Begleiter samt Ausrüstung erstellt. Sie melden sich beim Serverstart an.",
|
||||
|
||||
// Companions progress
|
||||
"comp.progress": "{done} von {target} hinzugefügt",
|
||||
"comp.progressDone": "Alle {n} Begleiter sind erstellt. Sie melden sich jetzt an.",
|
||||
"comp.progressOffline": "{n} Begleiter werden samt Ausrüstung erstellt … das dauert einige Minuten.",
|
||||
"comp.progressStalled": "Warte darauf, dass der Server weitere erstellt …",
|
||||
};
|
||||
|
||||
export default de;
|
||||
@@ -543,6 +543,12 @@ const en = {
|
||||
|
||||
// Offline bots
|
||||
"comp.offlineDone": "Created {n} companions with their equipment. They log in when the server starts.",
|
||||
|
||||
// Companions progress
|
||||
"comp.progress": "{done} of {target} added",
|
||||
"comp.progressDone": "All {n} companions are created. They are logging in now.",
|
||||
"comp.progressOffline": "Creating {n} companions with their equipment… this takes a few minutes.",
|
||||
"comp.progressStalled": "Waiting for the server to create more…",
|
||||
} as const;
|
||||
|
||||
export default en;
|
||||
@@ -543,6 +543,12 @@ const es: Partial<Record<keyof typeof en, string>> = {
|
||||
|
||||
// Offline bots
|
||||
"comp.offlineDone": "Se crearon {n} compañeros con su equipo. Iniciarán sesión cuando arranque el servidor.",
|
||||
|
||||
// Companions progress
|
||||
"comp.progress": "{done} de {target} añadidos",
|
||||
"comp.progressDone": "Se crearon los {n} compañeros. Están iniciando sesión.",
|
||||
"comp.progressOffline": "Creando {n} compañeros con su equipo… esto tarda unos minutos.",
|
||||
"comp.progressStalled": "Esperando a que el servidor cree más…",
|
||||
};
|
||||
|
||||
export default es;
|
||||
@@ -543,6 +543,12 @@ const fr: Partial<Record<keyof typeof en, string>> = {
|
||||
|
||||
// Offline bots
|
||||
"comp.offlineDone": "{n} compagnons créés avec leur équipement. Ils se connecteront au démarrage du serveur.",
|
||||
|
||||
// Companions progress
|
||||
"comp.progress": "{done} sur {target} ajoutés",
|
||||
"comp.progressDone": "Les {n} compagnons sont créés. Ils se connectent maintenant.",
|
||||
"comp.progressOffline": "Création de {n} compagnons avec leur équipement… cela prend quelques minutes.",
|
||||
"comp.progressStalled": "En attente de la création des suivants par le serveur…",
|
||||
};
|
||||
|
||||
export default fr;
|
||||
@@ -543,6 +543,12 @@ const ru: Partial<Record<keyof typeof en, string>> = {
|
||||
|
||||
// Offline bots
|
||||
"comp.offlineDone": "Создано компаньонов: {n}, сразу со снаряжением. Они войдут в игру при запуске сервера.",
|
||||
|
||||
// Companions progress
|
||||
"comp.progress": "Добавлено {done} из {target}",
|
||||
"comp.progressDone": "Все компаньоны ({n}) созданы. Они входят в игру.",
|
||||
"comp.progressOffline": "Создаю компаньонов ({n}) со снаряжением… это займёт несколько минут.",
|
||||
"comp.progressStalled": "Жду, пока сервер создаст остальных…",
|
||||
};
|
||||
|
||||
export default ru;
|
||||
+1
-1
@@ -292,7 +292,7 @@ export const api = {
|
||||
openLink: (url: string) => invoke<void>("open_link", { url }),
|
||||
performance: (id: string) => invoke<Performance | null>("get_performance", { id }),
|
||||
companionSizes: () => invoke<CompanionSizes>("companion_sizes"),
|
||||
addCompanions: (id: string, count: number) => invoke<{ spawned: string | null; created: number | null }>("add_companions", { id, count }),
|
||||
addCompanions: (id: string, count: number) => invoke<{ spawned: string | null; created: number | null; baseline: number | null }>("add_companions", { id, count }),
|
||||
clientInfo: (id: string) => invoke<ClientInfo | null>("client_info", { id }),
|
||||
setClient: (id: string, path: string) => invoke<ClientInfo>("set_client", { id, path }),
|
||||
setRealmlist: (id: string, host: string) => invoke<string[]>("client_realmlist", { id, host }),
|
||||
|
||||
@@ -19,6 +19,8 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
// Start-up login: how many existing bots the server brings online by itself every time it starts.
|
||||
const [autoOn, setAutoOn] = useState(true);
|
||||
const [autoMax, setAutoMax] = useState("");
|
||||
// A creation that is still in progress on the running server: how many existed before and how many were asked for.
|
||||
const [job, setJob] = useState<{ baseline: number; target: number; since: number } | null>(null);
|
||||
const [startNote, setStartNote] = useState<string | null>(null);
|
||||
const [startBusy, setStartBusy] = useState(false);
|
||||
|
||||
@@ -62,12 +64,23 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
setPop(up ? await api.population(serverId).catch(() => null) : null);
|
||||
};
|
||||
void poll();
|
||||
const t = setInterval(poll, 4000);
|
||||
// Faster while companions are being created, so the progress bar moves.
|
||||
const t = setInterval(poll, job ? 1500 : 4000);
|
||||
return () => {
|
||||
alive = false;
|
||||
clearInterval(t);
|
||||
};
|
||||
}, [serverId]);
|
||||
}, [serverId, job !== null]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const done = job && pop ? Math.max(0, Math.min(job.target, pop.bots_total - job.baseline)) : 0;
|
||||
useEffect(() => {
|
||||
if (!job) return;
|
||||
// Finished, or the server went away, or nothing new appeared for two minutes.
|
||||
if ((pop && done >= job.target) || !running) {
|
||||
if (pop && done >= job.target) setNote(t("comp.progressDone", { n: job.target }));
|
||||
setJob(null);
|
||||
}
|
||||
}, [done, running]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// The backend describes a size's warning in English; show the translated text for the two known kinds.
|
||||
const warningFor = (size?: { bots: number; warning: string | null }) => {
|
||||
@@ -86,6 +99,7 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
setNote(null);
|
||||
try {
|
||||
const r = await api.addCompanions(serverId, count);
|
||||
if (r.spawned && r.baseline !== null) setJob({ baseline: r.baseline, target: count, since: Date.now() });
|
||||
setNote(r.created ? t("comp.offlineDone", { n: r.created }) : r.spawned ? t("comp.spawned", { n: count }) : t("comp.saved", { n: count }));
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
@@ -128,13 +142,33 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
{sizes && <p className="mt-2 text-xs text-muted">{t("comp.hardware", { cores: sizes.hardware.cores, ram: sizes.hardware.ram_gb.toFixed(0) })}</p>}
|
||||
|
||||
<div className="mt-4 flex items-center gap-3">
|
||||
<Button variant="primary" disabled={busy || !valid} onClick={() => void add()}>
|
||||
<Button variant="primary" disabled={busy || !valid || job !== null} onClick={() => void add()}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{valid ? t("comp.add", { n: count }) : t("comp.addPlain")}
|
||||
</Button>
|
||||
{!running && <span className="text-xs text-muted">{t("comp.stoppedHint")}</span>}
|
||||
</div>
|
||||
{note && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
|
||||
{busy && !running && count >= 100 && (
|
||||
<div className="mt-3">
|
||||
<p className="text-sm text-muted" role="status">{t("comp.progressOffline", { n: count })}</p>
|
||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-white/10" role="progressbar" aria-busy="true">
|
||||
<div className="h-full w-full animate-pulse rounded-full bg-gold/70" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{job && (
|
||||
<div className="mt-3">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span role="status">{t("comp.progress", { done, target: job.target })}</span>
|
||||
<span className="text-muted">{Math.round((done / job.target) * 100)}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-white/10" role="progressbar" aria-valuenow={done} aria-valuemin={0} aria-valuemax={job.target}>
|
||||
<div className="h-full rounded-full bg-gold transition-[width] duration-500" style={{ width: `${(done / job.target) * 100}%` }} />
|
||||
</div>
|
||||
{done === 0 && Date.now() - job.since > 20000 && <p className="mt-1 text-xs text-muted">{t("comp.progressStalled")}</p>}
|
||||
</div>
|
||||
)}
|
||||
{note && !job && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
|
||||
|
||||
<div className="mt-5 border-t border-line pt-4">
|
||||
<h3 className="text-sm font-semibold">{t("comp.startTitle")}</h3>
|
||||
|
||||
Reference in new issue
Block a user