Reduce fetch count: config partagee + suppression doublons internet
- topbar-logo.js expose la config via event 'nebuleair-config-ready' - wifi.html ecoute l'event au lieu de re-fetcher get_config_sqlite - Supprime le doublon load_ethernet_info (get_internet fait deja tout) - Passe de ~9 requetes simultanees a ~5 au chargement Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,12 +9,15 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
let config = null;
|
||||
|
||||
// Fetch config once
|
||||
// Fetch config once and share globally
|
||||
fetch('launcher.php?type=get_config_sqlite')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
config = data;
|
||||
applyConfig(); // Apply immediately if elements are ready
|
||||
window._nebuleairConfig = data;
|
||||
applyConfig();
|
||||
// Notify other scripts that config is ready
|
||||
document.dispatchEvent(new CustomEvent('nebuleair-config-ready', { detail: data }));
|
||||
})
|
||||
.catch(error => console.error('Error loading config:', error));
|
||||
|
||||
|
||||
@@ -560,14 +560,11 @@ function get_internet(){
|
||||
|
||||
|
||||
|
||||
window.onload = function() {
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=get_config_sqlite',
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
success: function(data) {
|
||||
console.log("Getting SQLite config table (wifi page):");
|
||||
console.log(data);
|
||||
// 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):");
|
||||
console.log(data);
|
||||
|
||||
// WiFi connection status — toggle cards
|
||||
const WIFI_statusElement = document.getElementById("wifi-status");
|
||||
@@ -580,7 +577,7 @@ function get_internet(){
|
||||
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
|
||||
// Auto-load connection details (includes ethernet info)
|
||||
get_internet();
|
||||
} else if (data.WIFI_status === "hotspot") {
|
||||
WIFI_statusElement.textContent = "Hotspot";
|
||||
@@ -599,29 +596,8 @@ function get_internet(){
|
||||
document.getElementById('card-hotspot-info').style.display = 'none';
|
||||
document.getElementById('card-wifi-scan').style.display = '';
|
||||
}
|
||||
|
||||
// Always load ethernet info
|
||||
load_ethernet_info();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
|
||||
// Load RTC time
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=RTC_time',
|
||||
dataType: 'text',
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
const RTC_Element = document.getElementById("RTC_time");
|
||||
if (RTC_Element) RTC_Element.textContent = response;
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user