From dd066f20949316765f1e624bc8de33ec1722de78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 30 Sep 2026 23:24:27 +0500 Subject: [PATCH] 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 --- src-tauri/src/lib.rs | 8 +++++-- src/dev/mock.ts | 3 ++- src/i18n/locales/de.ts | 6 +++++ src/i18n/locales/en.ts | 6 +++++ src/i18n/locales/es.ts | 6 +++++ src/i18n/locales/fr.ts | 6 +++++ src/i18n/locales/ru.ts | 6 +++++ src/lib/api.ts | 2 +- src/screens/CompanionsCard.tsx | 42 ++++++++++++++++++++++++++++++---- 9 files changed, 77 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 96a7965..fc6f37d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -546,6 +546,8 @@ struct CompanionsResult { spawned: Option, /// Created offline with their equipment (server was stopped and the batch was large). created: Option, + /// Companions that existed before this request (for a progress bar while the server creates the new ones). + baseline: Option, } /// Turn on automatic bot login for `count` bots and, if the server is running, ask it to create them. @@ -592,11 +594,13 @@ async fn add_companions(state: State<'_, AppState>, id: String, count: u32) -> s } made?; tracing::info!(count, "companions created offline"); - return Ok(CompanionsResult { spawned: None, created: Some(count) }); + return Ok(CompanionsResult { spawned: None, created: Some(count), baseline: None }); } + let mut baseline = None; let spawned = if o.world.state == coa_core::process::ServiceState::Running { // Older servers have no template characters to copy bots from: add them first. coa_core::companions::ensure_templates(&coa_core::db::Db::from_repack(&root, coa_core::db::Account::Admin)?)?; + baseline = coa_core::population::query(&root).ok().map(|p| p.bots_total); Some(Ra::connect(&root)?.spawn_bots(count)?) } else { // The server is stopped: creating bots needs it running, so remember the request and do it after the next start. @@ -604,7 +608,7 @@ async fn add_companions(state: State<'_, AppState>, id: String, count: u32) -> s None }; tracing::info!(count, spawned = spawned.is_some(), "companions requested"); - Ok(CompanionsResult { spawned, created: None }) + Ok(CompanionsResult { spawned, created: None, baseline }) }) .await } diff --git a/src/dev/mock.ts b/src/dev/mock.ts index e42c383..80d310c 100644 --- a/src/dev/mock.ts +++ b/src/dev/mock.ts @@ -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; diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index 2ac468c..9dc589c 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -543,6 +543,12 @@ const de: Partial> = { // 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; diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index 7dc5c08..c1fd4bb 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -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; diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index be3d469..5078feb 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -543,6 +543,12 @@ const es: Partial> = { // 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; diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index 94512d7..0989617 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -543,6 +543,12 @@ const fr: Partial> = { // 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; diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index bf79b50..9743a1a 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -543,6 +543,12 @@ const ru: Partial> = { // Offline bots "comp.offlineDone": "Создано компаньонов: {n}, сразу со снаряжением. Они войдут в игру при запуске сервера.", + + // Companions progress + "comp.progress": "Добавлено {done} из {target}", + "comp.progressDone": "Все компаньоны ({n}) созданы. Они входят в игру.", + "comp.progressOffline": "Создаю компаньонов ({n}) со снаряжением… это займёт несколько минут.", + "comp.progressStalled": "Жду, пока сервер создаст остальных…", }; export default ru; diff --git a/src/lib/api.ts b/src/lib/api.ts index f147472..aaf0d37 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -292,7 +292,7 @@ export const api = { openLink: (url: string) => invoke("open_link", { url }), performance: (id: string) => invoke("get_performance", { id }), companionSizes: () => invoke("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("client_info", { id }), setClient: (id: string, path: string) => invoke("set_client", { id, path }), setRealmlist: (id: string, host: string) => invoke("client_realmlist", { id, host }), diff --git a/src/screens/CompanionsCard.tsx b/src/screens/CompanionsCard.tsx index 6b188fb..935bdb1 100644 --- a/src/screens/CompanionsCard.tsx +++ b/src/screens/CompanionsCard.tsx @@ -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(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 &&

{t("comp.hardware", { cores: sizes.hardware.cores, ram: sizes.hardware.ram_gb.toFixed(0) })}

}
- {!running && {t("comp.stoppedHint")}}
- {note &&

{note}

} + {busy && !running && count >= 100 && ( +
+

{t("comp.progressOffline", { n: count })}

+
+
+
+
+ )} + {job && ( +
+
+ {t("comp.progress", { done, target: job.target })} + {Math.round((done / job.target) * 100)}% +
+
+
+
+ {done === 0 && Date.now() - job.since > 20000 &&

{t("comp.progressStalled")}

} +
+ )} + {note && !job &&

{note}

}

{t("comp.startTitle")}