feat: Optimierte Datenladegeschwindigkeit durch initialen Direktaufruf in loadWindowVariables
- Erstaufruf von loadWindowVariables.js außerhalb des Intervalls hinzugefügt, um Variablen schneller zu laden. - Intervall zur Variablenüberprüfung nur gestartet, wenn beim Erstaufruf noch Variablen fehlen. - Verbessert die Ladezeit und stellt sicher, dass alle benötigten Variablen frühzeitig verfügbar sind.
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
export async function loadWindowVariables() {
|
||||
return new Promise((resolve, reject) => {
|
||||
//console.log("Running loadWindowVariables..."); // Log each run
|
||||
|
||||
const requiredVars = [
|
||||
"last20Messages",
|
||||
"deviceName",
|
||||
@@ -62,28 +60,42 @@ export async function loadWindowVariables() {
|
||||
|
||||
const scripts = ["de.js", "kueData.js", "Start.js", "System.js"];
|
||||
|
||||
// Load all required scripts
|
||||
// Erster Aufruf zum Laden aller Skripte
|
||||
Promise.all(scripts.map(loadScript))
|
||||
.then(() => {
|
||||
// console.log("Scripts loaded. Checking for variables...");
|
||||
// Einmaliger direkter Check, ob alle Variablen vorhanden sind
|
||||
const missingVarsInitial = requiredVars.filter(
|
||||
(variable) => window[variable] === undefined
|
||||
);
|
||||
|
||||
// Interval to check if all required variables are loaded
|
||||
const checkInterval = setInterval(() => {
|
||||
const missingVars = requiredVars.filter(
|
||||
(variable) => window[variable] === undefined
|
||||
if (missingVarsInitial.length === 0) {
|
||||
// Alle Variablen sind geladen, keine weiteren Checks notwendig
|
||||
console.log("Alle Systemvariablen beim ersten Aufruf geladen.");
|
||||
resolve();
|
||||
} else {
|
||||
console.log(
|
||||
"Noch fehlende Variablen beim ersten Aufruf:",
|
||||
missingVarsInitial
|
||||
);
|
||||
|
||||
if (missingVars.length === 0) {
|
||||
//console.log("All system variables are now loaded.");
|
||||
clearInterval(checkInterval);
|
||||
resolve();
|
||||
} else {
|
||||
console.log("Waiting for missing variables:", missingVars);
|
||||
}
|
||||
}, 5000); // Check every 5 seconds
|
||||
// Falls Variablen fehlen, starte das Intervall
|
||||
const checkInterval = setInterval(() => {
|
||||
const missingVars = requiredVars.filter(
|
||||
(variable) => window[variable] === undefined
|
||||
);
|
||||
|
||||
if (missingVars.length === 0) {
|
||||
clearInterval(checkInterval);
|
||||
console.log("Alle fehlenden Systemvariablen sind jetzt geladen.");
|
||||
resolve();
|
||||
} else {
|
||||
console.log("Noch fehlende Variablen:", missingVars);
|
||||
}
|
||||
}, 5000); // Überprüfung alle 5 Sekunden
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error loading a script:", error);
|
||||
console.error("Fehler beim Laden eines Skripts:", error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user