mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-23 03:25:56 +00:00
Stabilize server lifecycle, client settings and release qualification
This commit is contained in:
1 parent
4d1a6e0b21
commit
30d2f56997
71 files changed
+2785
-168
No files matched your search
@@ -496,6 +496,7 @@ export const api = {
|
||||
forget: (id: string) => invoke<void>("forget_server", { id }),
|
||||
status: (id: string) => invoke<StatusView>("server_status", { id }),
|
||||
start: (id: string) => invoke<DriverOutcome>("start_server", { id }),
|
||||
forceStop: (id: string) => invoke<DriverOutcome>("force_stop_server", { id }),
|
||||
stop: (id: string) => invoke<DriverOutcome>("stop_server", { id }),
|
||||
settings: (id: string, scope: Scope) => invoke<SettingsView>("get_settings", { id, scope }),
|
||||
save: (id: string, scope: Scope, changes: Record<string, JsonValue>) => invoke<SaveReport>("save_settings", { id, scope, changes }),
|
||||
@@ -560,6 +561,8 @@ export const api = {
|
||||
performance: (id: string) => invoke<Performance | null>("get_performance", { id }),
|
||||
companionSizes: () => invoke<CompanionSizes>("companion_sizes"),
|
||||
addCompanions: (id: string, count: number) => invoke<{ spawned: string | null; created: number | null; baseline: number | null }>("add_companions", { id, count }),
|
||||
clientGraphics: (id: string) => invoke<{ dxvk_disabled: boolean; enhancements_disabled: boolean }>("client_graphics", { id }),
|
||||
clientSetGraphics: (id: string, name: string, disabled: boolean) => invoke<{ dxvk_disabled: boolean; enhancements_disabled: boolean }>("client_set_graphics", { id, name, disabled }),
|
||||
clientInfo: (id: string) => invoke<ClientInfo | null>("client_info", { id }),
|
||||
setClient: (id: string, path: string) => invoke<ClientInfo>("set_client", { id, path }),
|
||||
setRealmlist: (id: string, host: string) => invoke<string[]>("client_realmlist", { id, host }),
|
||||
|
||||
@@ -69,6 +69,8 @@ export interface BrowseParams {
|
||||
}
|
||||
|
||||
export const browse = {
|
||||
enabled: () => invoke<boolean>("browse_enabled"),
|
||||
setEnabled: (enabled: boolean) => invoke<void>("browse_set_enabled", { enabled }),
|
||||
list: (params: BrowseParams) => invoke<RealmPage>("browse_list", { params }),
|
||||
detail: (realmId: string) => invoke<RealmDetail>("browse_detail", { realmId }),
|
||||
modules: () => invoke<ModuleInfo[]>("module_catalog"),
|
||||
|
||||
+14
-2
@@ -1,3 +1,4 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { check, type Update } from "@tauri-apps/plugin-updater";
|
||||
@@ -93,9 +94,11 @@ export async function installNow(): Promise<void> {
|
||||
if (state.phase !== "ready") await downloadPending();
|
||||
if (state.phase !== "ready") return;
|
||||
set({ phase: "installing" });
|
||||
await invoke("manager_installing", { enabled: true });
|
||||
await update.install();
|
||||
await relaunch();
|
||||
} catch (e) {
|
||||
await invoke("manager_installing", { enabled: false }).catch(() => {});
|
||||
set({ phase: "error", error: String(e) });
|
||||
}
|
||||
}
|
||||
@@ -107,14 +110,23 @@ export function installOnClose(): () => void {
|
||||
const win = getCurrentWindow();
|
||||
void win
|
||||
.onCloseRequested(async (event) => {
|
||||
if (state.phase !== "ready" || !update || !autoUpdateEnabled()) return;
|
||||
event.preventDefault();
|
||||
if (state.phase !== "ready" || !update || !autoUpdateEnabled()) {
|
||||
await invoke("close_manager");
|
||||
return;
|
||||
}
|
||||
if (await invoke<boolean>("close_to_tray")) {
|
||||
await invoke("close_manager");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
set({ phase: "installing" });
|
||||
await invoke("manager_installing", { enabled: true });
|
||||
await update.install();
|
||||
} catch (e) {
|
||||
await invoke("manager_installing", { enabled: false }).catch(() => {});
|
||||
set({ phase: "error", error: String(e) });
|
||||
await win.destroy();
|
||||
await invoke("close_manager");
|
||||
}
|
||||
})
|
||||
.then((un) => {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
export class ServerLifecycle {
|
||||
private wasRunning = false;
|
||||
private maintenance = false;
|
||||
private stopRequested = false;
|
||||
private operationPending = false;
|
||||
|
||||
request(action: "starting" | "stopping" | "restarting") {
|
||||
this.stopRequested = action !== "starting";
|
||||
this.operationPending = true;
|
||||
}
|
||||
|
||||
complete(action: "starting" | "stopping" | "restarting") {
|
||||
this.operationPending = false;
|
||||
if (action !== "stopping") { this.stopRequested = false; this.wasRunning = false; }
|
||||
}
|
||||
|
||||
beginMaintenance() { this.maintenance = true; this.wasRunning = false; }
|
||||
endMaintenance() { this.maintenance = false; this.wasRunning = false; }
|
||||
|
||||
observe(running: boolean, busy: boolean, updating: boolean): boolean {
|
||||
if (this.maintenance) { this.wasRunning = false; return false; }
|
||||
if (running) { this.wasRunning = true; return false; }
|
||||
if (this.stopRequested || updating || this.operationPending) {
|
||||
this.wasRunning = false;
|
||||
if (!busy && !this.operationPending) this.stopRequested = false;
|
||||
return false;
|
||||
}
|
||||
if (this.wasRunning && !busy) { this.wasRunning = false; return true; }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const lifecycles = new Map<string, ServerLifecycle>();
|
||||
export function serverLifecycle(id: string) {
|
||||
let lifecycle = lifecycles.get(id);
|
||||
if (!lifecycle) { lifecycle = new ServerLifecycle(); lifecycles.set(id, lifecycle); }
|
||||
return lifecycle;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { serverLifecycle } from "@/lib/serverLifecycle";
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from "@/lib/api";
|
||||
@@ -30,6 +31,11 @@ const listeners = new Set<() => void>();
|
||||
export const CHECK_EVERY_MS = 5 * 60 * 1000;
|
||||
|
||||
const get = (id: string) => states.get(id) ?? EMPTY;
|
||||
export function serverUpdateBlocksRestart(id: string): boolean {
|
||||
const state = get(id);
|
||||
return state.applying || state.stateError !== null || !!(state.result && "pending" in state.result);
|
||||
}
|
||||
|
||||
function set(id: string, next: Partial<ServerUpdateState>) {
|
||||
states.set(id, { ...get(id), ...next });
|
||||
listeners.forEach((l) => l());
|
||||
@@ -89,6 +95,7 @@ export async function applyServerUpdate(id: string, opts?: { choices: Record<str
|
||||
// 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);
|
||||
serverLifecycle(id).beginMaintenance();
|
||||
set(id, { applying: true, step: null, percent: 0, error: null, uiError: null, result: null });
|
||||
let un: (() => void) | undefined;
|
||||
try {
|
||||
@@ -110,6 +117,7 @@ export async function applyServerUpdate(id: string, opts?: { choices: Record<str
|
||||
try {
|
||||
await refreshServerUpdateState(id);
|
||||
} catch { /* The state error remains visible and prevents another apply. */ }
|
||||
serverLifecycle(id).endMaintenance();
|
||||
set(id, { applying: false });
|
||||
void checkServerUpdate(id);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user