Fix reboot button and overlay bugs on local machine and LAN
Agent-Logs-Url: https://github.com/naturallaw777/staging_alpha/sessions/c8d3bf30-c3ea-40e7-8da0-b4baa28eaf36 Co-authored-by: naturallaw777 <99053422+naturallaw777@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e33f4b570a
commit
a6dc3fd647
@@ -6,6 +6,9 @@ const POLL_INTERVAL_SERVICES = 5000;
|
||||
const POLL_INTERVAL_UPDATES = 1800000;
|
||||
const UPDATE_POLL_INTERVAL = 2000;
|
||||
const REBOOT_CHECK_INTERVAL = 5000;
|
||||
const REBOOT_FETCH_TIMEOUT = 12000;
|
||||
const REBOOT_REQUEST_TIMEOUT = 4000;
|
||||
const REBOOT_INITIAL_DELAY = 25000;
|
||||
const SUPPORT_TIMER_INTERVAL = 1000;
|
||||
|
||||
const CATEGORY_ORDER = [
|
||||
|
||||
@@ -157,14 +157,14 @@ function openSecurityModal() {
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
rebootBtn.addEventListener("click", async function() {
|
||||
rebootBtn.addEventListener("click", function() {
|
||||
rebootBtn.disabled = true;
|
||||
rebootBtn.textContent = "Rebooting\u2026";
|
||||
try {
|
||||
await apiFetch("/api/reboot", { method: "POST" });
|
||||
} catch (_) {}
|
||||
if ($rebootOverlay) $rebootOverlay.classList.add("visible");
|
||||
setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL);
|
||||
setTimeout(waitForServerReboot, REBOOT_INITIAL_DELAY);
|
||||
var rebootCtrl = new AbortController();
|
||||
setTimeout(function() { rebootCtrl.abort(); }, REBOOT_REQUEST_TIMEOUT);
|
||||
fetch("/api/reboot", { method: "POST", signal: rebootCtrl.signal }).catch(function() {});
|
||||
}, { once: true });
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -174,26 +174,28 @@ function doReboot() {
|
||||
if ($rebootOverlay) $rebootOverlay.classList.add("visible");
|
||||
_rebootStartTime = Date.now();
|
||||
_serverWentDown = false;
|
||||
apiFetch("/api/reboot", { method: "POST" }).catch(function() {});
|
||||
// Wait 15 seconds before the first check — give the system time to actually shut down
|
||||
setTimeout(waitForServerReboot, 15000);
|
||||
var rebootCtrl = new AbortController();
|
||||
setTimeout(function() { rebootCtrl.abort(); }, REBOOT_REQUEST_TIMEOUT);
|
||||
fetch("/api/reboot", { method: "POST", signal: rebootCtrl.signal }).catch(function() {});
|
||||
// Wait before the first check — NixOS shutdown after an update can take 20-40s
|
||||
setTimeout(waitForServerReboot, REBOOT_INITIAL_DELAY);
|
||||
}
|
||||
|
||||
function waitForServerReboot() {
|
||||
var controller = new AbortController();
|
||||
var timeoutId = setTimeout(function() { controller.abort(); }, REBOOT_CHECK_INTERVAL);
|
||||
var timeoutId = setTimeout(function() { controller.abort(); }, REBOOT_FETCH_TIMEOUT);
|
||||
|
||||
fetch("/api/config", { cache: "no-store", signal: controller.signal })
|
||||
fetch("/api/config", { cache: "no-store", signal: controller.signal, headers: { "Connection": "close" } })
|
||||
.then(function(res) {
|
||||
clearTimeout(timeoutId);
|
||||
if (res.ok && _serverWentDown) {
|
||||
// Server is back after having been down — reboot is complete
|
||||
window.location.reload();
|
||||
} else if (res.ok && !_serverWentDown && (Date.now() - _rebootStartTime) < 30000) {
|
||||
} else if (res.ok && !_serverWentDown && (Date.now() - _rebootStartTime) < 90000) {
|
||||
// Server still responding but hasn't gone down yet — keep waiting
|
||||
setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL);
|
||||
} else if (res.ok) {
|
||||
// Been over 30 seconds and server is responding — just reload
|
||||
// Been over 90 seconds and server is responding — just reload
|
||||
window.location.reload();
|
||||
} else {
|
||||
_serverWentDown = true;
|
||||
|
||||
Reference in New Issue
Block a user