/** * pc-live | IC-Verwaltung App * Renders the ic-verwaltung UI inside a WindowManager window via iframe. * Messages are relayed: Lua TriggerEvent → pc-live SendNUIMessage → postMessage → iframe. */ const ICVerwaltungApp = (() => { const WIN_ID = 'app-ic-verwaltung'; const IFRAME_ID = 'ic-verwaltung-frame'; const IC_ORIGIN = 'https://cfx-nui-ic-verwaltung'; let _iframe = null; function open() { if (windows_has(WIN_ID)) { WindowManager.focus(WIN_ID); return; } const content = ` `; const winEl = WindowManager.create({ id: WIN_ID, title: 'IC-Verwaltung', icon: '🏛', width: 960, height: 620, content, }); // Intercept titlebar X so Lua is notified when user closes the window manually if (winEl) { const closeBtn = winEl.querySelector('.wc-close'); if (closeBtn) { closeBtn.addEventListener('click', () => { _iframe = null; fetchNui('closeIcVerwaltung', {}); }, { once: true }); } } _iframe = document.getElementById(IFRAME_ID); // Tell Lua to open ic-verwaltung in pcMode — relay will carry the open message fetchNui('openIcVerwaltung', {}); } // Called by desktop.js when action === 'ic_verwaltung_relay' function onRelay(msg) { // ic-verwaltung's close action → close the PC window instead of posting back if (msg && msg.action === 'close') { WindowManager.close(WIN_ID); _iframe = null; return; } if (!_iframe) { _iframe = document.getElementById(IFRAME_ID); } if (_iframe && _iframe.contentWindow) { _iframe.contentWindow.postMessage(msg, IC_ORIGIN); } } // Helper: check if a window id is already open (WindowManager has no .exists method) function windows_has(id) { return !!document.querySelector(`[data-wid="${id}"]`); } return { open, onRelay }; })();