loadWindowVariables und variablesSlice entfernt und die daten ausgelagert und chaeckSession.ts erstellt
This commit is contained in:
14
utils/checkSession.ts
Normal file
14
utils/checkSession.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// utils/checkSession.ts
|
||||
|
||||
export async function checkSession(): Promise<boolean> {
|
||||
try {
|
||||
// Beispiel: prüfe ob ein erwartetes globales Fenster-Objekt noch existiert
|
||||
const expectedGlobalVar = "win_kueID"; // oder "win_deviceName", je nach System
|
||||
|
||||
if (typeof window === "undefined") return false;
|
||||
|
||||
return window[expectedGlobalVar] !== undefined;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user