Fix: window.onload au lieu de event listener pour sequencer les requetes

window.onload attend que les ressources initiales soient chargees,
liberant les slots HTTP avant de lancer les AJAX (internet, scan).
Reutilise la config deja fetched par topbar-logo.js via window global.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
PaulVua
2026-03-17 18:42:56 +01:00
parent 87ddb76e39
commit 196176667f

View File

@@ -564,43 +564,46 @@ function get_internet(){
// Listen for config loaded by topbar-logo.js (avoids duplicate fetch) // Use window.onload to wait for all initial resources to finish loading
document.addEventListener('nebuleair-config-ready', function(e) { // This frees up HTTP connection slots before making AJAX calls
const data = e.detail; window.onload = function() {
console.log("Config received (wifi page):"); // 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); console.log(data);
// WiFi connection status — toggle cards const WIFI_statusElement = document.getElementById("wifi-status");
const WIFI_statusElement = document.getElementById("wifi-status"); console.log("WIFI is: " + data.WIFI_status);
console.log("WIFI is: " + data.WIFI_status);
if (data.WIFI_status === "connected") { if (data.WIFI_status === "connected") {
WIFI_statusElement.textContent = "Connected"; WIFI_statusElement.textContent = "Connected";
WIFI_statusElement.className = "badge text-bg-success"; WIFI_statusElement.className = "badge text-bg-success";
document.getElementById('btn-forget-wifi').style.display = 'inline-block'; document.getElementById('btn-forget-wifi').style.display = 'inline-block';
document.getElementById('card-connection-info').style.display = ''; document.getElementById('card-connection-info').style.display = '';
document.getElementById('card-hotspot-info').style.display = 'none'; document.getElementById('card-hotspot-info').style.display = 'none';
document.getElementById('card-wifi-scan').style.display = 'none'; document.getElementById('card-wifi-scan').style.display = 'none';
// Auto-load connection details (includes ethernet info) get_internet();
get_internet(); } else if (data.WIFI_status === "hotspot") {
} else if (data.WIFI_status === "hotspot") { WIFI_statusElement.textContent = "Hotspot";
WIFI_statusElement.textContent = "Hotspot"; WIFI_statusElement.className = "badge text-bg-warning";
WIFI_statusElement.className = "badge text-bg-warning"; document.getElementById('btn-forget-wifi').style.display = 'none';
document.getElementById('btn-forget-wifi').style.display = 'none'; document.getElementById('card-connection-info').style.display = 'none';
document.getElementById('card-connection-info').style.display = 'none'; document.getElementById('card-hotspot-info').style.display = '';
document.getElementById('card-hotspot-info').style.display = ''; document.getElementById('card-wifi-scan').style.display = '';
document.getElementById('card-wifi-scan').style.display = ''; wifi_scan();
// Auto-load cached scan results in hotspot mode } else {
wifi_scan(); WIFI_statusElement.textContent = "Unknown";
} else { WIFI_statusElement.className = "badge text-bg-secondary";
WIFI_statusElement.textContent = "Unknown"; document.getElementById('btn-forget-wifi').style.display = 'none';
WIFI_statusElement.className = "badge text-bg-secondary"; document.getElementById('card-connection-info').style.display = 'none';
document.getElementById('btn-forget-wifi').style.display = 'none'; document.getElementById('card-hotspot-info').style.display = 'none';
document.getElementById('card-connection-info').style.display = 'none'; document.getElementById('card-wifi-scan').style.display = '';
document.getElementById('card-hotspot-info').style.display = 'none'; }
document.getElementById('card-wifi-scan').style.display = ''; }
}
});
</script> </script>