diff --git a/html/wifi.html b/html/wifi.html index fe471f5..450fa4d 100755 --- a/html/wifi.html +++ b/html/wifi.html @@ -564,43 +564,46 @@ function get_internet(){ - // Listen for config loaded by topbar-logo.js (avoids duplicate fetch) - document.addEventListener('nebuleair-config-ready', function(e) { - const data = e.detail; - console.log("Config received (wifi page):"); + // Use window.onload to wait for all initial resources to finish loading + // This frees up HTTP connection slots before making AJAX calls + window.onload = function() { + // Reuse config already fetched by topbar-logo.js, or fetch if not ready + const data = window._nebuleairConfig; + if (!data) { + console.warn("Config not ready yet, skipping wifi page init"); + return; + } + console.log("Config loaded (wifi page):"); console.log(data); - // WiFi connection status — toggle cards - const WIFI_statusElement = document.getElementById("wifi-status"); - console.log("WIFI is: " + data.WIFI_status); + const WIFI_statusElement = document.getElementById("wifi-status"); + console.log("WIFI is: " + data.WIFI_status); - if (data.WIFI_status === "connected") { - WIFI_statusElement.textContent = "Connected"; - WIFI_statusElement.className = "badge text-bg-success"; - document.getElementById('btn-forget-wifi').style.display = 'inline-block'; - document.getElementById('card-connection-info').style.display = ''; - document.getElementById('card-hotspot-info').style.display = 'none'; - document.getElementById('card-wifi-scan').style.display = 'none'; - // Auto-load connection details (includes ethernet info) - get_internet(); - } else if (data.WIFI_status === "hotspot") { - WIFI_statusElement.textContent = "Hotspot"; - WIFI_statusElement.className = "badge text-bg-warning"; - document.getElementById('btn-forget-wifi').style.display = 'none'; - document.getElementById('card-connection-info').style.display = 'none'; - document.getElementById('card-hotspot-info').style.display = ''; - document.getElementById('card-wifi-scan').style.display = ''; - // Auto-load cached scan results in hotspot mode - wifi_scan(); - } else { - WIFI_statusElement.textContent = "Unknown"; - WIFI_statusElement.className = "badge text-bg-secondary"; - document.getElementById('btn-forget-wifi').style.display = 'none'; - document.getElementById('card-connection-info').style.display = 'none'; - document.getElementById('card-hotspot-info').style.display = 'none'; - document.getElementById('card-wifi-scan').style.display = ''; - } - }); + if (data.WIFI_status === "connected") { + WIFI_statusElement.textContent = "Connected"; + WIFI_statusElement.className = "badge text-bg-success"; + document.getElementById('btn-forget-wifi').style.display = 'inline-block'; + document.getElementById('card-connection-info').style.display = ''; + document.getElementById('card-hotspot-info').style.display = 'none'; + document.getElementById('card-wifi-scan').style.display = 'none'; + get_internet(); + } else if (data.WIFI_status === "hotspot") { + WIFI_statusElement.textContent = "Hotspot"; + WIFI_statusElement.className = "badge text-bg-warning"; + document.getElementById('btn-forget-wifi').style.display = 'none'; + document.getElementById('card-connection-info').style.display = 'none'; + document.getElementById('card-hotspot-info').style.display = ''; + document.getElementById('card-wifi-scan').style.display = ''; + wifi_scan(); + } else { + WIFI_statusElement.textContent = "Unknown"; + WIFI_statusElement.className = "badge text-bg-secondary"; + document.getElementById('btn-forget-wifi').style.display = 'none'; + document.getElementById('card-connection-info').style.display = 'none'; + document.getElementById('card-hotspot-info').style.display = 'none'; + document.getElementById('card-wifi-scan').style.display = ''; + } + }