refactor: Lade alle window-basierten .js-Dateien dynamisch und umgebungsabhängig

- Alle Services (ae.js, de.js, da.js, kueData.js, Start.js, System.js, opcua.js) laden ihre Scripte abhängig von der Umgebung
- Vermeidet unnötige globale Script-Ladung über loadWindowVariables.ts
- Reduziert Netzwerklast und verbessert Modularität und Performance
This commit is contained in:
ISA
2025-03-26 14:13:18 +01:00
parent db67ba0709
commit 9e282c9ae5
12 changed files with 244 additions and 101 deletions

View File

@@ -1,9 +1,25 @@
// ✅ 1. Service: /services/fetchOpcUaSettings.ts
export const fetchOpcUaSettings = async () => {
try {
const win = window as any;
if (typeof window === "undefined") return null;
if (!win) return null;
// ✅ opcua.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
const scriptSrc =
process.env.NODE_ENV === "production"
? "/CPL?/CPL/SERVICE/opcua.js"
: "/CPLmockData/SERVICE/opcua.js";
await new Promise<void>((resolve, reject) => {
const script = document.createElement("script");
script.src = scriptSrc;
script.async = true;
script.onload = () => resolve();
script.onerror = () => reject("❌ Fehler beim Laden von opcua.js");
document.body.appendChild(script);
});
const win = window as any;
const data = {
zustand: win.win_opcUaZustand || "Offline",