The full-system updater runs as a detached systemd service and can finish successfully even when the browser loses its status connection. In that case the update log and status file correctly report REBOOT_REQUIRED, but the Hub modal can remain on "Updating..." with its controls disabled. There were four independent ways for the frontend to get stuck: * update status fetches had no deadline, so a request that stayed pending never rejected and never advanced the existing failure counter; * setInterval started async polls without waiting for the previous poll, allowing slow requests to overlap and responses to arrive out of order; * each log chunk used textContent +=, replacing the complete and growing Nix build log every two seconds, which could stall browser rendering and was especially visible over RDP; and * page reload, tab resume, and RDP reconnect did not reattach the modal to the update status persisted by the backend. This produced a dangerous UX mismatch: the machine had a fully staged NixOS generation and was ready to reboot, while the Hub continued telling the user that the update was still running. Bound status requests with AbortController, prevent overlapping polls, and replace the endless spinner after sustained failures with an explicit "Update status unavailable" state and Retry Status action. Reconcile state immediately on focus, visibility, online, page startup, and before starting a new update. Use no-store requests and render verbose logs incrementally with a bounded visible tail while retaining the complete report in memory. Apply the same timeout and single-flight protection to rebuild polling. Record the exact generation produced by `nixos-rebuild boot`. The Hub now keeps REBOOT_REQUIRED visible until that generation matches /run/current-system, then clears the marker after reboot. For an update started by an older updater that did not write the marker, recover the staged generation from the final nixos-rebuild log line. The dashboard sidebar also distinguishes update-in-progress and restart-required states. Regression coverage verifies generation marker/log recovery, pre- versus post-reboot detection, request timeout wiring, single-flight polling, connection-loss UX, RDP/tab resume reconciliation, bounded log rendering, page-reload recovery, and JavaScript syntax. Validation: * python3 -m unittest discover -s tests -p 'test_*.py' -v (170 passed) * node --check app/sovran_systemsos_web/static/js/*.js * python3 -m py_compile for changed Python modules * git diff --check A Nix evaluation was not available in the development sandbox; the NixOS module should still be evaluated and built in CI or on a test machine before release.
124 lines
6.1 KiB
JavaScript
124 lines
6.1 KiB
JavaScript
"use strict";
|
|
|
|
// ── State ─────────────────────────────────────────────────────────
|
|
|
|
let _servicesCache = [];
|
|
let _categoryLabels = {};
|
|
let _updateLog = "";
|
|
let _updatePollTimer = null;
|
|
let _updatePollInFlight = false;
|
|
let _updateLogOffset = 0;
|
|
let _updateVisibleLogChars = 0;
|
|
let _serverWasDown = false;
|
|
let _updateFinished = false;
|
|
let _updateStatusUnavailable = false;
|
|
let _updatePollFailures = 0; // consecutive failed update-status polls
|
|
let _supportTimerInt = null;
|
|
let _supportEnabledAt = null;
|
|
let _supportStatus = null; // last fetched /api/support/status payload
|
|
let _walletUnlockTimerInt = null;
|
|
let _cachedExternalIp = null;
|
|
|
|
// Current role (set during init from /api/config)
|
|
let _currentRole = "server_plus_desktop";
|
|
|
|
// Feature Manager state
|
|
let _featuresData = null;
|
|
let _rebuildLog = "";
|
|
let _rebuildLogOffset = 0;
|
|
let _rebuildPollTimer = null;
|
|
let _rebuildPollInFlight = false;
|
|
let _rebuildFinished = false;
|
|
let _rebuildServerDown = false;
|
|
let _rebuildPollFailures = 0; // consecutive failed rebuild-status polls
|
|
let _pendingToggle = null; // {feature, extra} waiting for domain/confirm
|
|
let _rebuildFeatureName = "";
|
|
let _rebuildIsEnabling = true;
|
|
|
|
// ── DOM refs ──────────────────────────────────────────────────────
|
|
|
|
const $tilesArea = document.getElementById("tiles-area");
|
|
const $sidebarSupport = document.getElementById("sidebar-support");
|
|
const $sidebarFeatures = document.getElementById("sidebar-features");
|
|
// No longer needed — Update System moved to sidebar
|
|
// const $updateBtn = document.getElementById("btn-update");
|
|
// const $updateBadge = document.getElementById("update-badge");
|
|
const $internalIp = document.getElementById("ip-internal");
|
|
const $externalIp = document.getElementById("ip-external");
|
|
|
|
const $modal = document.getElementById("update-modal");
|
|
const $modalSpinner = document.getElementById("modal-spinner");
|
|
const $modalStatus = document.getElementById("modal-status");
|
|
const $modalLog = document.getElementById("modal-log");
|
|
const $btnReboot = document.getElementById("btn-reboot");
|
|
const $btnSave = document.getElementById("btn-save-report");
|
|
const $btnRetryUpdate = document.getElementById("btn-retry-update-status");
|
|
const $btnCloseModal = document.getElementById("btn-close-modal");
|
|
|
|
const $rebootOverlay = document.getElementById("reboot-overlay");
|
|
const $rebootMainCard = document.getElementById("reboot-main-card");
|
|
const $rebootErrorCard = document.getElementById("reboot-error-card");
|
|
const $rebootSubmessage = document.getElementById("reboot-submessage");
|
|
|
|
const $credsModal = document.getElementById("creds-modal");
|
|
const $credsTitle = document.getElementById("creds-modal-title");
|
|
const $credsBody = document.getElementById("creds-body");
|
|
const $credsCloseBtn = document.getElementById("creds-close-btn");
|
|
|
|
const $supportModal = document.getElementById("support-modal");
|
|
const $supportBody = document.getElementById("support-body");
|
|
const $supportCloseBtn = document.getElementById("support-close-btn");
|
|
|
|
const $logoutBtn = document.getElementById("btn-logout");
|
|
|
|
// Feature Manager — rebuild modal
|
|
const $rebuildModal = document.getElementById("rebuild-modal");
|
|
const $rebuildSpinner = document.getElementById("rebuild-spinner");
|
|
const $rebuildStatus = document.getElementById("rebuild-status");
|
|
const $rebuildLog = document.getElementById("rebuild-log");
|
|
const $rebuildReboot = document.getElementById("rebuild-reboot-btn");
|
|
const $rebuildSave = document.getElementById("rebuild-save-report");
|
|
const $rebuildClose = document.getElementById("rebuild-close-btn");
|
|
|
|
// Feature Manager — domain setup modal
|
|
const $domainSetupModal = document.getElementById("domain-setup-modal");
|
|
const $domainSetupTitle = document.getElementById("domain-setup-title");
|
|
const $domainSetupBody = document.getElementById("domain-setup-body");
|
|
const $domainSetupClose = document.getElementById("domain-setup-close-btn");
|
|
|
|
// Feature Manager — SSL email modal
|
|
const $sslEmailModal = document.getElementById("ssl-email-modal");
|
|
const $sslEmailInput = document.getElementById("ssl-email-input");
|
|
const $sslEmailSave = document.getElementById("ssl-email-save-btn");
|
|
const $sslEmailCancel = document.getElementById("ssl-email-cancel-btn");
|
|
const $sslEmailClose = document.getElementById("ssl-email-close-btn");
|
|
|
|
// Feature Manager — confirm modal
|
|
const $featureConfirmModal = document.getElementById("feature-confirm-modal");
|
|
const $featureConfirmMsg = document.getElementById("feature-confirm-message");
|
|
const $featureConfirmOk = document.getElementById("feature-confirm-ok-btn");
|
|
const $featureConfirmCancel = document.getElementById("feature-confirm-cancel-btn");
|
|
const $featureConfirmClose = document.getElementById("feature-confirm-close-btn");
|
|
|
|
// Port Requirements modal
|
|
const $portReqModal = document.getElementById("port-requirements-modal");
|
|
const $portReqBody = document.getElementById("port-req-body");
|
|
const $portReqClose = document.getElementById("port-req-close-btn");
|
|
|
|
// Upgrade modal (Node → Server+Desktop)
|
|
const $upgradeModal = document.getElementById("upgrade-modal");
|
|
const $upgradeConfirmBtn = document.getElementById("upgrade-confirm-btn");
|
|
const $upgradeCancelBtn = document.getElementById("upgrade-cancel-btn");
|
|
const $upgradeCloseBtn = document.getElementById("upgrade-close-btn");
|
|
|
|
// Restart confirm dialog
|
|
const $restartConfirmModal = document.getElementById("restart-confirm-modal");
|
|
const $restartConfirmOk = document.getElementById("restart-confirm-ok-btn");
|
|
const $restartConfirmCancel = document.getElementById("restart-confirm-cancel-btn");
|
|
const $restartConflictBox = document.getElementById("restart-conflict-box");
|
|
|
|
// Header reboot button
|
|
const $headerRebootBtn = document.getElementById("btn-header-reboot");
|
|
|
|
// System status banner
|
|
// (removed — health is now shown per-tile via the composite health field)
|