fix(dashboard): shared-gateway restart toast keyed on the restart action's exit, matching Desktop

This commit is contained in:
teknium1
2026-09-12 08:59:37 -07:00
committed by Teknium
parent 6a66a5d481
commit e440bf3547
+23 -7
View File
@@ -302,7 +302,7 @@ export default function SystemPage() {
const sharedGateway = sharedGatewayProfiles(status); const sharedGateway = sharedGatewayProfiles(status);
const [sharedRestartOpen, setSharedRestartOpen] = useState(false); const [sharedRestartOpen, setSharedRestartOpen] = useState(false);
const [servedNotice, setServedNotice] = useState<string | null>(null); const [servedNotice, setServedNotice] = useState<string | null>(null);
const runGateway = async (verb: "start" | "stop" | "restart") => { const runGateway = async (verb: "start" | "stop" | "restart"): Promise<boolean> => {
setServedNotice(null); setServedNotice(null);
try { try {
if (verb === "start") { if (verb === "start") {
@@ -317,13 +317,15 @@ export default function SystemPage() {
} }
showToast(`Gateway ${verb} started`, "success"); showToast(`Gateway ${verb} started`, "success");
setTimeout(loadAll, 3000); setTimeout(loadAll, 3000);
return true;
} catch (e) { } catch (e) {
const refusal = servedProfileRefusal(e); const refusal = servedProfileRefusal(e);
if (refusal) { if (refusal) {
setServedNotice(refusal); setServedNotice(refusal);
return; return false;
} }
showToast(`Gateway ${verb} failed: ${e}`, "error"); showToast(`Gateway ${verb} failed: ${e}`, "error");
return false;
} }
}; };
const requestRestart = () => { const requestRestart = () => {
@@ -333,6 +335,23 @@ export default function SystemPage() {
} }
void runGateway("restart"); void runGateway("restart");
}; };
// Same completion rule as the Desktop: the restart child exiting 0, or still running when the
// bounded poll ends (in a no-service install it BECOMES the gateway and never exits), is
// success — then the "(N bots)" toast; a non-zero exit is the action log's failure to show.
const restartShared = async () => {
const bots = sharedGateway?.length ?? 0;
const started = await runGateway("restart");
if (!started) return;
for (let attempt = 0; attempt < 18; attempt += 1) {
await new Promise((r) => setTimeout(r, 1200));
const st = await api.getActionStatus("gateway-restart", 1).catch(() => null);
if (st && !st.running) {
if (st.exit_code != null && st.exit_code !== 0) return;
break;
}
}
showToast(sharedGatewayRestartedMessage(bots), "success");
};
const migrateToMultiplex = async () => { const migrateToMultiplex = async () => {
try { try {
@@ -445,9 +464,6 @@ export default function SystemPage() {
const handleActionComplete = useCallback( const handleActionComplete = useCallback(
(action: string, exitCode: number | null) => { (action: string, exitCode: number | null) => {
if (action === "gateway-restart" && exitCode === 0 && sharedGateway) {
showToast(sharedGatewayRestartedMessage(sharedGateway.length), "success");
}
if (action === "backup" && pendingBackupArchive) { if (action === "backup" && pendingBackupArchive) {
if (exitCode === 0) { if (exitCode === 0) {
setDownloadableBackupArchive(pendingBackupArchive); setDownloadableBackupArchive(pendingBackupArchive);
@@ -457,7 +473,7 @@ export default function SystemPage() {
} }
} }
}, },
[pendingBackupArchive, sharedGateway, showToast], [pendingBackupArchive, showToast],
); );
const downloadBackup = async () => { const downloadBackup = async () => {
@@ -706,7 +722,7 @@ export default function SystemPage() {
onCancel={() => setSharedRestartOpen(false)} onCancel={() => setSharedRestartOpen(false)}
onConfirm={() => { onConfirm={() => {
setSharedRestartOpen(false); setSharedRestartOpen(false);
void runGateway("restart"); void restartShared();
}} }}
title="Restart the shared gateway?" title="Restart the shared gateway?"
description={sharedGatewayRestartDescription(sharedGateway ?? [])} description={sharedGatewayRestartDescription(sharedGateway ?? [])}