Files
coa-server-manager/src/lib/updatePrefs.ts
T
ДмитрийandClaude Sonnet 5.5 838cc07e73 Add the SQUID dashboard tab and make a stopped server stay stopped after updating
The Dashboard tab (shown with SQUID Playerbots) downloads the dashboard release of the
bots' release series, starts it on a free local port and shows it in the window. After an
update, a server that was stopped stays stopped unless the owner asked for it to start.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-08 07:33:07 +05:00

29 lines
1.1 KiB
TypeScript

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); }];
}