fix(ui): resolve Cannot read properties of null (reading 'appendChild') in window-manager.js

- Lazy load workspace and taskbar containers to prevent crashes when WindowManager is instantiated in the head before the body DOM is ready
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-02-24 19:49:04 -03:00
parent 6d07aa4bdd
commit 09bb9ee55d

View file

@ -4,11 +4,16 @@ if (typeof window.WindowManager === 'undefined') {
this.openWindows = []; this.openWindows = [];
this.activeWindowId = null; this.activeWindowId = null;
this.zIndexCounter = 100; this.zIndexCounter = 100;
this.workspace = document.getElementById('desktop-content') || document.body; // Will fetch dynamically in open() since script runs before DOM is ready
this.taskbarApps = document.getElementById('taskbar-apps'); this.workspace = null;
this.taskbarApps = null;
} }
open(id, title, htmlContent) { open(id, title, htmlContent) {
// Lazy load the container elements to avoid head script loading issues
if (!this.workspace) this.workspace = document.getElementById('desktop-content') || document.body;
if (!this.taskbarApps) this.taskbarApps = document.getElementById('taskbar-apps');
// If window already exists, focus it // If window already exists, focus it
const existingWindow = this.openWindows.find(w => w.id === id); const existingWindow = this.openWindows.find(w => w.id === id);
if (existingWindow) { if (existingWindow) {