loadWindowVariables und variablesSlice entfernt und die daten ausgelagert und chaeckSession.ts erstellt

This commit is contained in:
Ismail Ali
2025-03-26 21:55:55 +01:00
parent c5e978e221
commit 0bec3fb148
4 changed files with 21 additions and 105 deletions

View File

@@ -1,86 +0,0 @@
// /utils/loadWindowVariables.ts
// ✅ Interface für `window`-Objekt zur TypeScript-Sicherheit
interface CustomWindow extends Window {
[key: string]: any;
}
// ✅ Hauptfunktion zum Laden von `window`-Variablen
export async function loadWindowVariables(): Promise<Record<string, any>> {
return new Promise((resolve, reject) => {
const requiredVars: string[] = [
"win_counter",
"win_flutter",
"win_kueOnline",
"win_kueID",
"win_kuePSTmMinus96V",
"win_kueAlarm1",
"win_kueAlarm2",
"win_kueIso",
"win_kueResidence",
"win_kueCableBreak",
"win_kueGroundFault",
"win_kueLimit1",
"win_kueLimit2Low",
"win_kueDelay1",
"win_kueLoopInterval",
"win_kueVersion",
"win_tdrAtten",
"win_tdrPulse",
"win_tdrSpeed",
"win_tdrAmp",
"win_tdrTrigger",
"win_tdrLocation",
"win_tdrActive",
"win_kueOverflow",
"win_tdrLast",
"win_appVersion",
];
const scripts: string[] = ["kueData.js"];
const loadScript = (src: string): Promise<void> => {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
const environment = process.env.NEXT_PUBLIC_NODE_ENV || "production";
script.src =
environment === "production"
? `/CPL?/CPL/SERVICE/${src}`
: `/CPLmockData/SERVICE/${src}`;
script.async = true;
script.onload = () => resolve();
script.onerror = () => reject(new Error(`Script load error: ${src}`));
document.head.appendChild(script);
});
};
// ✅ Lade alle Skripte nacheinander
scripts
.reduce(
(promise, script) => promise.then(() => loadScript(script)),
Promise.resolve()
)
.then(() => {
const win = window as unknown as CustomWindow;
// ✅ Erstelle ein Objekt mit allen geladenen Variablen
const variablesObj: Record<string, any> = requiredVars.reduce(
(acc, variable) => {
if (win[variable] !== undefined) {
acc[variable.replace("win_", "")] = win[variable];
}
return acc;
},
{}
);
// ✅ Redux mit Systemvariablen aktualisieren
resolve(variablesObj);
})
.catch((error) => {
console.error("Fehler beim Laden eines Skripts:", error);
reject(error);
});
});
}