mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-20 11:25:56 +00:00
Merge origin/master into feat/portable-characters
This commit is contained in:
commit
65ace578f7
60 files changed
+1563
-112
No files matched your search
+31
-2
@@ -78,6 +78,22 @@ export interface DriverOutcome {
|
||||
output: string;
|
||||
}
|
||||
|
||||
export interface DashboardStatus {
|
||||
installed: boolean;
|
||||
tag: string | null;
|
||||
squid_tag: string | null;
|
||||
matches: boolean;
|
||||
running: boolean;
|
||||
port: number;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface BackupLocation {
|
||||
path: string;
|
||||
default_path: string;
|
||||
is_default: boolean;
|
||||
}
|
||||
|
||||
export interface ServerSummary {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -217,7 +233,7 @@ export interface ModuleSetting {
|
||||
value: string;
|
||||
default: string | null;
|
||||
doc: string;
|
||||
field?: { key: string; type: string; title: string; description: string; group: string; group_title?: string | null; min?: number | null; max?: number | null } | null;
|
||||
field?: { key: string; type: string; title: string; description: string; group: string; group_title?: string | null; min?: number | null; max?: number | null; choices?: { value: string | number | boolean; label: string }[] | null } | null;
|
||||
}
|
||||
|
||||
export interface AllSetting {
|
||||
@@ -285,6 +301,10 @@ export interface UpdatePreview {
|
||||
migrations: number;
|
||||
pending_migrations?: number;
|
||||
download_bytes: number;
|
||||
/** False when pending database changes were not counted (stopped server during a background check, or an error). */
|
||||
database_checked?: boolean;
|
||||
/** Set when the database could not be inspected; the file comparison is still valid. */
|
||||
database_check_error?: string;
|
||||
}
|
||||
|
||||
export interface UpdateTxn {
|
||||
@@ -421,6 +441,14 @@ export const api = {
|
||||
save: (id: string, scope: Scope, changes: Record<string, JsonValue>) => invoke<SaveReport>("save_settings", { id, scope, changes }),
|
||||
presets: (scope: Scope) => invoke<PresetInfo[]>("list_presets", { scope }),
|
||||
backups: (id: string) => invoke<RecoveryPoint[]>("list_backups", { id }),
|
||||
dashboardStatus: (id: string) => invoke<DashboardStatus>("dashboard_status", { id }),
|
||||
dashboardInstall: (id: string) => invoke<DashboardStatus>("dashboard_install", { id }),
|
||||
dashboardOpen: (id: string) => invoke<void>("dashboard_open", { id }),
|
||||
dashboardStart: (id: string) => invoke<DashboardStatus>("dashboard_start", { id }),
|
||||
dashboardStop: (id: string) => invoke<DashboardStatus>("dashboard_stop", { id }),
|
||||
backupLocation: (id: string) => invoke<BackupLocation>("backup_location", { id }),
|
||||
/** `null` goes back to the default folder next to the server. */
|
||||
setBackupLocation: (id: string, path: string | null) => invoke<BackupLocation>("set_backup_location", { id, path }),
|
||||
createBackup: (id: string, kind: BackupKind, label?: string) => invoke<RecoveryPoint>("create_backup", { id, kind, label: label ?? null }),
|
||||
verifyBackup: (id: string, backupId: string) => invoke<{ ok: boolean; problems: string[] }>("verify_backup", { id, backupId }),
|
||||
deleteBackup: (id: string, backupId: string) => invoke<void>("delete_backup", { id, backupId }),
|
||||
@@ -449,7 +477,8 @@ export const api = {
|
||||
cancelInstall: () => invoke<void>("cancel_install"),
|
||||
createAccount: (id: string, username: string, password: string, administrator: boolean) =>
|
||||
invoke<void>("create_account", { id, username, password, administrator }),
|
||||
checkUpdate: (id: string, source?: string) => invoke<UpdatePreview>("check_update", { id, source: source ?? null }),
|
||||
/** `background`: the repeating check, which must not start the database of a stopped server. */
|
||||
checkUpdate: (id: string, source?: string, background?: boolean) => invoke<UpdatePreview>("check_update", { id, source: source ?? null, background: background ?? false }),
|
||||
pendingUpdate: (id: string) => invoke<UpdateTxn | null>("pending_update", { id }),
|
||||
applyUpdate: (id: string, resolutions: Record<string, "keep" | "replace">, source?: string) =>
|
||||
invoke<{ txn: UpdateTxn }>("apply_update", { id, source: source ?? null, resolutions }),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { startAfterUpdate } from "./updatePrefs";
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { api, asUiError, type ClientPlan, type ClientStep, type UiError } from "@/lib/api";
|
||||
@@ -85,6 +86,7 @@ export async function syncClient(id: string, keepModified: boolean): Promise<voi
|
||||
try {
|
||||
await api.clientSync(id, keepModified);
|
||||
set(id, { phase: "done", step: null });
|
||||
if (startAfterUpdate("client", id)) void api.play(id).catch(() => undefined);
|
||||
void refresh(id);
|
||||
setTimeout(() => {
|
||||
if (get(id).phase === "done") set(id, { phase: "idle" });
|
||||
|
||||
@@ -175,7 +175,11 @@ for (const [category, categoryNames] of Object.entries(auctionCategories)) {
|
||||
}
|
||||
export function moduleField(key: string, locale: Locale, metadata?: ModuleSetting["field"]): ModuleField | undefined {
|
||||
const translated = locale !== "en" ? fields.find(f => f.key === key) : undefined;
|
||||
if (metadata) return { title: translated ? text(translated.title, locale) : metadata.title, description: translated ? text(translated.description, locale) : metadata.description, type: metadata.type, category: metadata.group, advanced: false, min: metadata.min ?? undefined, max: metadata.max ?? undefined };
|
||||
if (metadata) {
|
||||
// A fixed list of values is edited as a drop-down; the values stay strings, as they are written to the config.
|
||||
const options = metadata.choices?.length ? metadata.choices.map(c => ({ value: String(c.value), label: c.label })) : undefined;
|
||||
return { title: translated ? text(translated.title, locale) : metadata.title, description: translated ? text(translated.description, locale) : metadata.description, type: options ? "enum" : metadata.type, category: metadata.group, advanced: false, min: metadata.min ?? undefined, max: metadata.max ?? undefined, ...(options ? { options } : {}) } as ModuleField;
|
||||
}
|
||||
const field = fields.find(f => f.key === key);
|
||||
if (field) return { ...field, title: text(field.title, locale), description: text(field.description, locale), category: "general", advanced: field.advanced ?? false, step: field.type === "range" ? 0.05 : undefined, options: field.options?.map(o => ({ value: o.value, label: text(o.label, locale) })) };
|
||||
const existing = [...bots.settings, ...server.settings].find(s => s.key === key);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useSyncExternalStore } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from "@/lib/api";
|
||||
import { isUpdateCurrent } from "./serverUpdateStatus";
|
||||
import { startAfterUpdate } from "./updatePrefs";
|
||||
|
||||
/**
|
||||
* Server update status for the main screen and the navigation: checked when the app starts and every five minutes,
|
||||
@@ -34,12 +35,12 @@ function set(id: string, next: Partial<ServerUpdateState>) {
|
||||
listeners.forEach((l) => l());
|
||||
}
|
||||
|
||||
export async function checkServerUpdate(id: string): Promise<void> {
|
||||
export async function checkServerUpdate(id: string, background = false): Promise<void> {
|
||||
const cur = get(id);
|
||||
if (cur.applying || cur.checking) return;
|
||||
set(id, { checking: true });
|
||||
try {
|
||||
const p = await api.checkUpdate(id);
|
||||
const p = await api.checkUpdate(id, undefined, background);
|
||||
set(id, { preview: p, available: !isUpdateCurrent(p), error: null });
|
||||
} catch (e) {
|
||||
// A cached offer is no longer safe after an update or failed recheck.
|
||||
@@ -51,8 +52,8 @@ export async function checkServerUpdate(id: string): Promise<void> {
|
||||
|
||||
/** Check now and then every five minutes. Returns the function that stops it. */
|
||||
export function startServerUpdatePolling(id: string): () => void {
|
||||
void checkServerUpdate(id);
|
||||
const t = setInterval(() => void checkServerUpdate(id), CHECK_EVERY_MS);
|
||||
void checkServerUpdate(id, true);
|
||||
const t = setInterval(() => void checkServerUpdate(id, true), CHECK_EVERY_MS);
|
||||
return () => clearInterval(t);
|
||||
}
|
||||
|
||||
@@ -85,6 +86,9 @@ export async function applyServerUpdate(id: string, opts?: { choices: Record<str
|
||||
const current = get(id);
|
||||
if (current.applying || current.stateError || (current.result && "pending" in current.result)) return false;
|
||||
if (!opts && (!p || p.conflicts.length > 0)) return false;
|
||||
// The update stops a running server and proves the new build by starting it; a server that was stopped stays stopped
|
||||
// unless the owner asked for it to start.
|
||||
const wasRunning = await api.status(id).then((s) => [s.observed.mysql, s.observed.auth, s.observed.world].some((x) => x.state === "running" || x.state === "starting")).catch(() => true);
|
||||
set(id, { applying: true, step: null, percent: 0, error: null, uiError: null, result: null });
|
||||
let un: (() => void) | undefined;
|
||||
try {
|
||||
@@ -95,6 +99,7 @@ export async function applyServerUpdate(id: string, opts?: { choices: Record<str
|
||||
try {
|
||||
const out = await api.applyUpdate(id, opts?.choices ?? {}, opts?.source);
|
||||
set(id, { result: out.txn.state === "committed" ? { committed: out.txn.to_version ?? "" } : { pending: out.txn } });
|
||||
if (out.txn.state === "committed" && !wasRunning && !startAfterUpdate("server", id)) await api.stop(id).catch(() => undefined);
|
||||
return true;
|
||||
} catch (e) {
|
||||
const ui = asUiError(e);
|
||||
|
||||
@@ -3,5 +3,5 @@ import type { UpdatePreview } from "./api";
|
||||
export function isUpdateCurrent(preview: UpdatePreview): boolean {
|
||||
return preview.from_version === preview.to_version
|
||||
&& preview.items.every((item) => item.action === "skip")
|
||||
&& (preview.pending_migrations ?? (preview.migrations === 0 ? 0 : undefined)) === 0;
|
||||
&& (preview.database_check_error !== undefined || preview.database_checked === false || (preview.pending_migrations ?? (preview.migrations === 0 ? 0 : undefined)) === 0);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useState } from "react";
|
||||
|
||||
/**
|
||||
* Whether a finished update starts things. Off by default for both: updating a stopped server leaves it stopped (a
|
||||
* server that was running is started again, as the update had to stop it) and a client update does not open the game.
|
||||
*/
|
||||
export type AfterUpdate = "server" | "client";
|
||||
|
||||
const key = (kind: AfterUpdate, id: string) => `coa-start-after-${kind}-update:${id}`;
|
||||
const fallback = (_kind: AfterUpdate) => false;
|
||||
|
||||
export function startAfterUpdate(kind: AfterUpdate, id: string): boolean {
|
||||
try {
|
||||
const value = localStorage.getItem(key(kind, id));
|
||||
return value === null ? fallback(kind) : value === "1";
|
||||
} catch {
|
||||
return fallback(kind);
|
||||
}
|
||||
}
|
||||
|
||||
export function setStartAfterUpdate(kind: AfterUpdate, id: string, on: boolean) {
|
||||
try { localStorage.setItem(key(kind, id), on ? "1" : "0"); } catch { /* storage unavailable: the default applies */ }
|
||||
}
|
||||
|
||||
export function useStartAfterUpdate(kind: AfterUpdate, id: string): [boolean, (on: boolean) => void] {
|
||||
const [on, setOn] = useState(() => startAfterUpdate(kind, id));
|
||||
return [on, (next) => { setStartAfterUpdate(kind, id, next); setOn(next); }];
|
||||
}
|
||||
Reference in new issue
Block a user