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"; import { api, asUiError, type ClientInfo, type Human, type Performance, type Population, type ServerSummary, type ServiceStatus, type StatusView } from "@/lib/api"; import { cn, formatBytes, formatUptime } from "@/lib/utils"; import { useHuman, useT } from "@/i18n"; import { applyServerUpdate, useServerUpdate } from "@/lib/serverUpdate"; import { checkClient, useClientStatus } from "@/lib/clientUpdate"; import { ClientDialog, type ClientDialogMode } from "@/screens/ClientDialog"; import { RealmlistMenu } from "@/screens/RealmlistMenu"; import { RealmPicker } from "@/screens/RealmPicker"; import { CrashHistoryModal } from "@/screens/CrashHistoryModal"; import { ListingChip } from "@/screens/PublishCard"; import { PublishRealmDialog } from "@/screens/PublishDialog"; import { useRegistryStatus } from "@/lib/registry"; import { usePublishRealms, type PublishRealm } from "@/lib/publishRealms"; import { useAutoRestart } from "@/lib/autoRestartPrefs"; import { SplitButton } from "@/components/ui/split-button"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; type Action = "starting" | "stopping" | "restarting" | null; type Failure = { human: Human; technical: string }; /** World loop speed from the server's own timing report, with a simple smooth / busy / lagging verdict. */ function TickRate({ perf }: { perf: Performance }) { const t = useT(); const level = perf.mean_ms <= 50 ? "good" : perf.mean_ms <= 100 ? "busy" : "lag"; const tone = { good: "text-ok bg-ok/15", busy: "text-warn bg-warn/15", lag: "text-bad bg-bad/15" }[level]; const bar = { good: "bg-ok", busy: "bg-warn", lag: "bg-bad" }[level]; const fill = Math.max(4, Math.min(100, Math.round(100 - perf.mean_ms))); return (
{t("overview.tickDetail", { mean: perf.mean_ms, p95: perf.p95_ms, max: perf.max_ms })}
{t("overview.checking")}
; if (!status.path_exists) { return ({t("overview.missingText", { path: server.path })}
{server.path}
{t("overview.reportHint")}{" "}
)}{startBots === null ? t("overview.startBotsOff") : t("overview.startBots", { n: startBots })}
)} {perf &&{t("overview.partial")}
)} {job.phase === "choose" && job.plan && ({t("client.upd.modifiedTitle", { n: job.plan.items.filter((i) => i.kind === "modified").length })}
{t("client.upd.modifiedText")}
{t("client.upd.done")}
} {job.phase === "current" &&{t("client.upd.upToDate", { v: job.plan?.version ?? "" })}
} {job.phase === "stopped" && ({t("client.dl.cancelled")}
)} {job.phase === "failed" && job.error && ({job.error.human.code === "unknown" ? job.error.technical : human(job.error.human).message}
)} {upd.result && "committed" in upd.result && !!upd.result.preexistingCharacters &&{t("upd.preexistingCharacters", { n: upd.result.preexistingCharacters })}
} {upd.available && upd.preview && ({t("overview.updateAvail", { to: upd.preview.to_version, from: upd.preview.from_version ?? "?" })}
{upd.preview.latest_version &&{t("upd.intermediate", { to: upd.preview.to_version, latest: upd.preview.latest_version })}
} {needsDecision &&{t("overview.updateConflicts")}
} {upd.applying && ({t("overview.updatingNote")}
{t("realm.bothRunning")}
{t("realm.bothRunning")}
{t("overview.portTitle")}
{t("overview.portText", { port: conflict.port, exe: conflict.exe ? ` (${conflict.exe})` : "" })}
{human(visibleFailure.human).title}
{human(visibleFailure.human).message}
{anyUp && (stopFailed || /still stopping|could not be stopped|Stop the server before updating/i.test(visibleFailure.technical)) && }
{visibleFailure.technical || t("common.noOutput")}
)}