Game client: download and update through the Manager

PLAY turns into UPDATE CLIENT when a tracked client is outdated; with no client linked
it offers choosing an existing folder or downloading from the community launcher servers
(resumable, hash-verified, free-space checked, progress and stop). Files the player changed
are kept on request or moved aside, never silently replaced. Existing clients can be adopted
from Settings. Fresh downloads get a realmlist for each installed locale.

Fixes zero-length files in the downloader (found by the live probe).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-10-01 07:52:58 +05:00
1 parent 7d447b490f
commit 615b3e938d
21 files changed
+1632 -27

No files matched your search

+39
View File
@@ -226,6 +226,39 @@ export interface ClientInfo {
other_addons: number;
}
export interface ClientStatus {
linked: boolean;
managed: boolean;
installed_version: string | null;
latest_version: string | null;
latest_bytes: number | null;
update_available: boolean;
}
export interface ClientPlan {
version: string;
items: { path: string; size: number; kind: "missing" | "changed" | "modified" }[];
download_bytes: number;
total_files: number;
up_to_date_files: number;
kept_files: number;
}
export interface ClientStep {
phase: "scan" | "download" | "finish";
done: number;
total: number;
bytes_per_sec: number;
file: string | null;
}
export interface ClientDownloadCheck {
needed_bytes: number;
free_bytes: number;
version: string;
dest: string;
}
export type FriendsMode = "local" | "lan" | "direct" | "private";
export interface FriendsStatus {
@@ -301,6 +334,12 @@ export const api = {
setClient: (id: string, path: string) => invoke<ClientInfo>("set_client", { id, path }),
setRealmlist: (id: string, host: string) => invoke<string[]>("client_realmlist", { id, host }),
installAddon: (id: string) => invoke<void>("client_install_addon", { id }),
clientStatus: (id: string) => invoke<ClientStatus>("client_status", { id }),
clientDownloadCheck: (parent: string) => invoke<ClientDownloadCheck>("client_download_check", { parent }),
clientPlan: (id: string) => invoke<ClientPlan>("client_plan", { id }),
clientSync: (id: string, keepModified: boolean) => invoke<void>("client_sync", { id, keepModified }),
clientDownload: (id: string, parent: string) => invoke<ClientInfo>("client_download", { id, parent }),
clientCancel: () => invoke<void>("client_cancel"),
play: (id: string) => invoke<DriverOutcome>("play", { id }),
friendsStatus: (id: string) => invoke<FriendsStatus>("friends_status", { id }),
friendsCheckInternet: () => invoke<InternetCheck>("friends_check_internet"),
+51
View File
@@ -0,0 +1,51 @@
import { useSyncExternalStore } from "react";
import { api, type ClientStatus } from "@/lib/api";
/**
* Game client status for the main screen: which client is linked and, for a client the Manager keeps up to date,
* whether a newer one has been published. Checked at start and every five minutes (one small request; no game file is read).
*/
interface State {
status: ClientStatus | null;
checking: boolean;
}
const EMPTY: State = { status: null, checking: false };
const states = new Map<string, State>();
const listeners = new Set<() => void>();
const CHECK_EVERY_MS = 5 * 60 * 1000;
const get = (id: string) => states.get(id) ?? EMPTY;
function set(id: string, next: Partial<State>) {
states.set(id, { ...get(id), ...next });
listeners.forEach((l) => l());
}
export async function checkClient(id: string): Promise<void> {
if (get(id).checking) return;
set(id, { checking: true });
try {
set(id, { status: await api.clientStatus(id) });
} catch {
// offline: keep what we knew
} finally {
set(id, { checking: false });
}
}
/** Check now and then every five minutes. Returns the function that stops it. */
export function startClientPolling(id: string): () => void {
void checkClient(id);
const t = setInterval(() => void checkClient(id), CHECK_EVERY_MS);
return () => clearInterval(t);
}
export function useClientStatus(id: string): State {
return useSyncExternalStore(
(l) => {
listeners.add(l);
return () => listeners.delete(l);
},
() => get(id),
);
}
+12
View File
@@ -5,6 +5,18 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
/** 1536 -> "1.5 KB"; 43.2e9 -> "40.2 GB" (binary units, as drive sizes are shown). */
export function formatBytes(n: number): string {
const units = ["B", "KB", "MB", "GB", "TB"];
let v = Math.max(0, n);
let i = 0;
while (v >= 1024 && i < units.length - 1) {
v /= 1024;
i++;
}
return `${i === 0 || v >= 100 ? Math.round(v) : v.toFixed(1)} ${units[i]}`;
}
export function formatUptime(secs: number | null | undefined): string {
if (secs == null) return "—";
const d = Math.floor(secs / 86400);