mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
feat(client): updating the game client shows a progress bar on its button, no window over the app
A choice about files the owner changed appears in place below the buttons. First-time client setup keeps its dialog. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dffb4811aa
commit
42dbdeae1f
8 files changed
+193
-4
No files matched your search
@@ -17,6 +17,7 @@ export {};
|
||||
worldserver:null,authserver:null,banner_revision:"3567e2f8e9d5",bot_config_keys:71,client:null,
|
||||
notes:["worldserver.exe differs from the one listed in RELEASE.json (release 2026-09-11); this looks like a customised build."],modifies_files:false};
|
||||
const svc=(n: string,p: number,st: string)=>({name:n,state:st,pid:st==="running"?100:null,port:p,port_ready:st==="running",conflict:null,uptime_secs:st==="running"?4206:null});
|
||||
{ const q = new URLSearchParams(location.search); const w0 = window as any; if (q.get("client")) w0.__client = q.get("client"); if (q.get("modified")) w0.__modified = true; }
|
||||
(window as any).__TAURI_INTERNALS__ = {
|
||||
transformCallback: (cb: unknown)=>cb, unregisterCallback(){}, convertFileSrc:(x: unknown)=>x,
|
||||
invoke: async (cmd: string, args?: any)=>{
|
||||
|
||||
@@ -773,6 +773,8 @@ const de: Partial<Record<keyof typeof en, string>> = {
|
||||
"set.searchAll": "Alle Einstellungen nach Name oder Beschreibung durchsuchen…",
|
||||
"set.search": "Einstellungen durchsuchen…",
|
||||
"upd.current": "Du bist auf dem neuesten Stand (Version {v}).",
|
||||
"client.job.checking": "Client wird geprüft…",
|
||||
"client.job.updating": "Client wird aktualisiert",
|
||||
};
|
||||
|
||||
export default de;
|
||||
@@ -773,6 +773,8 @@ const en = {
|
||||
"set.searchAll": "Search all settings by name or description…",
|
||||
"set.search": "Search settings…",
|
||||
"upd.current": "You are up to date (version {v}).",
|
||||
"client.job.checking": "Checking the client…",
|
||||
"client.job.updating": "Updating the client",
|
||||
} as const;
|
||||
|
||||
export default en;
|
||||
@@ -773,6 +773,8 @@ const es: Partial<Record<keyof typeof en, string>> = {
|
||||
"set.searchAll": "Buscar en todos los ajustes por nombre o descripción…",
|
||||
"set.search": "Buscar ajustes…",
|
||||
"upd.current": "Estás al día (versión {v}).",
|
||||
"client.job.checking": "Comprobando el cliente…",
|
||||
"client.job.updating": "Actualizando el cliente",
|
||||
};
|
||||
|
||||
export default es;
|
||||
@@ -773,6 +773,8 @@ const fr: Partial<Record<keyof typeof en, string>> = {
|
||||
"set.searchAll": "Rechercher dans tous les réglages par nom ou description…",
|
||||
"set.search": "Rechercher un réglage…",
|
||||
"upd.current": "Vous êtes à jour (version {v}).",
|
||||
"client.job.checking": "Vérification du client…",
|
||||
"client.job.updating": "Mise à jour du client",
|
||||
};
|
||||
|
||||
export default fr;
|
||||
@@ -773,6 +773,8 @@ const ru: Partial<Record<keyof typeof en, string>> = {
|
||||
"set.searchAll": "Поиск по всем настройкам: название или описание…",
|
||||
"set.search": "Поиск по настройкам…",
|
||||
"upd.current": "У вас последняя версия ({v}).",
|
||||
"client.job.checking": "Проверка клиента…",
|
||||
"client.job.updating": "Обновление клиента",
|
||||
};
|
||||
|
||||
export default ru;
|
||||
@@ -0,0 +1,114 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { api, asUiError, type ClientPlan, type ClientStep, type UiError } from "@/lib/api";
|
||||
import { checkClient } from "@/lib/clientUpdate";
|
||||
|
||||
/**
|
||||
* Updating the game client from the main screen, without a window over everything: the "Update client" button turns into
|
||||
* a progress bar (as in a game launcher). Only a choice that needs the owner's word (files they changed) is shown, in
|
||||
* place, below the buttons. The first-time linking of a client keeps its dialog (ClientDialog).
|
||||
*/
|
||||
export type ClientJobPhase = "idle" | "scanning" | "choose" | "working" | "done" | "current" | "stopped" | "failed";
|
||||
|
||||
export interface ClientJob {
|
||||
phase: ClientJobPhase;
|
||||
step: ClientStep | null;
|
||||
plan: ClientPlan | null;
|
||||
error: UiError | null;
|
||||
}
|
||||
|
||||
const IDLE: ClientJob = { phase: "idle", step: null, plan: null, error: null };
|
||||
const jobs = new Map<string, ClientJob>();
|
||||
const listeners = new Set<() => void>();
|
||||
const cancelled = new Set<string>();
|
||||
|
||||
const get = (id: string) => jobs.get(id) ?? IDLE;
|
||||
function set(id: string, next: Partial<ClientJob>) {
|
||||
jobs.set(id, { ...get(id), ...next });
|
||||
listeners.forEach((l) => l());
|
||||
}
|
||||
|
||||
let unlisten: (() => void) | null = null;
|
||||
async function followProgress(id: string) {
|
||||
if (unlisten) return;
|
||||
try {
|
||||
unlisten = await listen<ClientStep>("client-progress", (e) => {
|
||||
const phase = get(id).phase;
|
||||
if (phase === "scanning" || phase === "working") set(id, { step: e.payload });
|
||||
});
|
||||
} catch {
|
||||
/* no event bridge (a plain browser): the bar just stays at zero */
|
||||
}
|
||||
}
|
||||
|
||||
function fail(id: string, e: unknown) {
|
||||
if (cancelled.has(id)) set(id, { phase: "stopped", step: null });
|
||||
else set(id, { phase: "failed", step: null, error: asUiError(e) });
|
||||
}
|
||||
|
||||
async function refresh(id: string) {
|
||||
await checkClient(id);
|
||||
}
|
||||
|
||||
/** Look at what differs from the published client; update at once when nothing needs a decision. */
|
||||
export async function startClientUpdate(id: string): Promise<void> {
|
||||
const now = get(id).phase;
|
||||
if (now === "scanning" || now === "working") return;
|
||||
cancelled.delete(id);
|
||||
set(id, { phase: "scanning", step: null, plan: null, error: null });
|
||||
void followProgress(id);
|
||||
try {
|
||||
const plan = await api.clientPlan(id);
|
||||
if (plan.items.length === 0) {
|
||||
set(id, { phase: "current", plan, step: null });
|
||||
void refresh(id);
|
||||
setTimeout(() => {
|
||||
if (get(id).phase === "current") set(id, { phase: "idle" });
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
if (plan.items.some((i) => i.kind === "modified")) {
|
||||
set(id, { phase: "choose", plan, step: null });
|
||||
return;
|
||||
}
|
||||
await syncClient(id, true);
|
||||
} catch (e) {
|
||||
fail(id, e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Download what is missing or changed; `keepModified` keeps the files the owner changed. */
|
||||
export async function syncClient(id: string, keepModified: boolean): Promise<void> {
|
||||
cancelled.delete(id);
|
||||
set(id, { phase: "working", step: null, error: null });
|
||||
void followProgress(id);
|
||||
try {
|
||||
await api.clientSync(id, keepModified);
|
||||
set(id, { phase: "done", step: null });
|
||||
void refresh(id);
|
||||
setTimeout(() => {
|
||||
if (get(id).phase === "done") set(id, { phase: "idle" });
|
||||
}, 6000);
|
||||
} catch (e) {
|
||||
fail(id, e);
|
||||
}
|
||||
}
|
||||
|
||||
export function stopClientJob(id: string) {
|
||||
cancelled.add(id);
|
||||
void api.clientCancel().catch(() => undefined);
|
||||
}
|
||||
|
||||
export function dismissClientJob(id: string) {
|
||||
set(id, { phase: "idle", error: null, plan: null, step: null });
|
||||
}
|
||||
|
||||
export function useClientJob(id: string): ClientJob {
|
||||
return useSyncExternalStore(
|
||||
(l) => {
|
||||
listeners.add(l);
|
||||
return () => listeners.delete(l);
|
||||
},
|
||||
() => get(id),
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { dismissClientJob, startClientUpdate, stopClientJob, syncClient, useClientJob } from "@/lib/clientJob";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { Loader2, X } from "lucide-react";
|
||||
import { api, asUiError, type ClientInfo, type Human, type Performance, type Population, type ServerSummary, type ServiceStatus, type StatusView } from "@/lib/api";
|
||||
import { cn, formatUptime } from "@/lib/utils";
|
||||
import { cn, formatBytes, formatUptime } from "@/lib/utils";
|
||||
import { useHuman, useT } from "@/i18n";
|
||||
import { applyServerUpdate, useServerUpdate } from "@/lib/serverUpdate";
|
||||
import { checkClient, useClientStatus } from "@/lib/clientUpdate";
|
||||
@@ -74,6 +75,10 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates }:
|
||||
const [dialog, setDialog] = useState<ClientDialogMode | null>(null);
|
||||
const clientStatus = useClientStatus(server.id).status;
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const job = useClientJob(server.id);
|
||||
const jobBusy = job.phase === "scanning" || job.phase === "working";
|
||||
const jobPct = job.step && job.step.total > 0 ? Math.min(100, Math.floor((job.step.done / job.step.total) * 100)) : 0;
|
||||
const [keepMine, setKeepMine] = useState(true);
|
||||
const [perf, setPerf] = useState<Performance | null>(null);
|
||||
const upd = useServerUpdate(server.id);
|
||||
const needsDecision = (upd.preview?.conflicts.length ?? 0) > 0;
|
||||
@@ -91,6 +96,10 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates }:
|
||||
}, [server.id]);
|
||||
const alive = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (job.phase === "done" || job.phase === "current") void api.clientInfo(server.id).then(setClient).catch(() => undefined);
|
||||
}, [job.phase, server.id]);
|
||||
|
||||
const poll = useCallback(async () => {
|
||||
try {
|
||||
const s = await api.status(server.id);
|
||||
@@ -279,8 +288,35 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates }:
|
||||
)}
|
||||
<div className="ml-auto flex items-center gap-3">
|
||||
{client && <RealmlistMenu serverId={server.id} />}
|
||||
{client && clientStatus?.update_available ? (
|
||||
<Button variant="primary" size="xl" disabled={playing} onClick={() => setDialog("update")} className="min-w-40">
|
||||
{client && jobBusy ? (
|
||||
<div
|
||||
className="relative flex h-16 min-w-64 items-center overflow-hidden rounded-md border border-gold/50 bg-card-2"
|
||||
role="progressbar"
|
||||
aria-valuenow={jobPct}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-label={job.phase === "scanning" ? t("client.job.checking") : t("client.job.updating")}
|
||||
>
|
||||
<div className="absolute inset-y-0 left-0 bg-gold/35 transition-[width] duration-300" style={{ width: `${jobPct}%` }} />
|
||||
<div className="relative z-10 flex min-w-0 flex-1 flex-col px-5 leading-tight">
|
||||
<span className="text-sm font-semibold uppercase tracking-wide">{job.phase === "scanning" ? t("client.job.checking") : t("client.job.updating")}</span>
|
||||
<span className="truncate text-xs text-muted">
|
||||
{jobPct}%
|
||||
{job.step && job.step.phase === "download" && job.step.bytes_per_sec > 0 ? ` · ${t("client.dl.speed", { speed: formatBytes(job.step.bytes_per_sec) })}` : ""}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => stopClientJob(server.id)}
|
||||
title={t("client.dl.cancel")}
|
||||
aria-label={t("client.dl.cancel")}
|
||||
className="relative z-10 flex h-full w-12 cursor-pointer items-center justify-center text-muted hover:text-ink"
|
||||
>
|
||||
<X className="h-4 w-4" aria-hidden />
|
||||
</button>
|
||||
</div>
|
||||
) : client && (clientStatus?.update_available || job.phase === "choose") ? (
|
||||
<Button variant="primary" size="xl" disabled={playing || job.phase === "choose"} onClick={() => void startClientUpdate(server.id)} className="min-w-40">
|
||||
{t("btn.updateClient")}
|
||||
</Button>
|
||||
) : client ? (
|
||||
@@ -298,6 +334,34 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates }:
|
||||
{anyUp && !running && !transitioning && (
|
||||
<p className="mt-3 text-sm text-muted">{t("overview.partial")}</p>
|
||||
)}
|
||||
{job.phase === "choose" && job.plan && (
|
||||
<div className="mt-4 rounded-md border border-warn/40 bg-warn/5 p-3 text-sm">
|
||||
<p className="font-medium">{t("client.upd.modifiedTitle", { n: job.plan.items.filter((i) => i.kind === "modified").length })}</p>
|
||||
<p className="mt-1 text-muted">{t("client.upd.modifiedText")}</p>
|
||||
<label className="mt-3 flex cursor-pointer items-center gap-2">
|
||||
<input type="checkbox" checked={keepMine} onChange={(e) => setKeepMine(e.target.checked)} className="h-4 w-4 accent-[#c9a24a]" />
|
||||
<span>{t("client.upd.keep")}</span>
|
||||
</label>
|
||||
<div className="mt-3 flex gap-2">
|
||||
<Button size="sm" variant="primary" onClick={() => void syncClient(server.id, keepMine)}>{t("client.upd.start")}</Button>
|
||||
<Button size="sm" variant="ghost" onClick={() => dismissClientJob(server.id)}>{t("client.upd.later")}</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{job.phase === "done" && <p className="mt-3 text-sm text-ok" role="status">{t("client.upd.done")}</p>}
|
||||
{job.phase === "current" && <p className="mt-3 text-sm text-ok" role="status">{t("client.upd.upToDate", { v: job.plan?.version ?? "" })}</p>}
|
||||
{job.phase === "stopped" && (
|
||||
<p className="mt-3 flex items-center gap-3 text-sm text-muted" role="status">
|
||||
{t("client.dl.cancelled")}
|
||||
<Button size="sm" variant="ghost" onClick={() => void startClientUpdate(server.id)}>{t("client.dl.resume")}</Button>
|
||||
</p>
|
||||
)}
|
||||
{job.phase === "failed" && job.error && (
|
||||
<p className="mt-3 flex flex-wrap items-center gap-3 text-sm text-bad" role="alert">
|
||||
{job.error.human.code === "unknown" ? job.error.technical : human(job.error.human).message}
|
||||
<Button size="sm" variant="ghost" onClick={() => void startClientUpdate(server.id)}>{t("client.dl.retry")}</Button>
|
||||
</p>
|
||||
)}
|
||||
{upd.available && upd.preview && (
|
||||
<div className="mt-4 rounded-md border border-gold/40 bg-gold/5 p-3 text-sm">
|
||||
<p>{t("overview.updateAvail", { to: upd.preview.to_version, from: upd.preview.from_version ?? "?" })}</p>
|
||||
|
||||
Reference in new issue
Block a user