import { useState, useRef, useCallback, useEffect } from "react"; import { useQuery } from "@tanstack/react-query"; import { motion, AnimatePresence } from "framer-motion"; import { useLocation } from "wouter"; import { useAuth } from "@/lib/auth"; import { getIcon } from "@/lib/iconMap"; import { Terminal, FileText, IdCard, Music, Settings, Globe, X, Minus, Square, Maximize2, Volume2, Wifi, Battery, ChevronUp, FolderOpen, Award, MessageCircle, Send, ExternalLink, User, LogOut, BarChart3, Loader2, Layers, Presentation, Bell, Image, Monitor, Play, Pause, ChevronRight, Network, Activity, Code2, Radio, Newspaper, Gamepad2, Users, Trophy, Calculator, StickyNote, Cpu, Camera, Eye, Shield, Zap, Skull, Lock, Unlock, Server, Database, TrendingUp, ArrowUp, ArrowDown, Hash, Key, HardDrive, FolderSearch, AlertTriangle } from "lucide-react"; interface WindowState { id: string; title: string; icon: React.ReactNode; component: string; x: number; y: number; width: number; height: number; minimized: boolean; maximized: boolean; zIndex: number; accentColor?: string; desktopId: number; iframeUrl?: string; } interface Toast { id: string; message: string; type: 'info' | 'success' | 'warning' | 'error'; } interface ThemeSettings { mode: 'dark' | 'light' | 'system'; accentColor: string; transparency: number; } interface DesktopLayout { name: string; windows: Array<{ appId: string; x: number; y: number; width: number; height: number }>; desktop: number; } const ACCENT_COLORS = [ { id: 'cyan', name: 'Cyan', color: '#06b6d4', ring: 'ring-cyan-400/50', shadow: 'shadow-cyan-500/20', bg: 'bg-cyan-500' }, { id: 'purple', name: 'Purple', color: '#a855f7', ring: 'ring-purple-400/50', shadow: 'shadow-purple-500/20', bg: 'bg-purple-500' }, { id: 'green', name: 'Green', color: '#22c55e', ring: 'ring-green-400/50', shadow: 'shadow-green-500/20', bg: 'bg-green-500' }, { id: 'orange', name: 'Orange', color: '#f97316', ring: 'ring-orange-400/50', shadow: 'shadow-orange-500/20', bg: 'bg-orange-500' }, { id: 'pink', name: 'Pink', color: '#ec4899', ring: 'ring-pink-400/50', shadow: 'shadow-pink-500/20', bg: 'bg-pink-500' }, { id: 'red', name: 'Red', color: '#ef4444', ring: 'ring-red-400/50', shadow: 'shadow-red-500/20', bg: 'bg-red-500' }, ]; type ClearanceMode = 'foundation' | 'corp'; interface ClearanceTheme { id: ClearanceMode; name: string; title: string; subtitle: string; primary: string; secondary: string; accent: string; accentSecondary: string; wallpaper: string; borderStyle: string; fontStyle: string; } const DAILY_TIPS = [ { title: "Quick Launch", tip: "Press Ctrl+Space to open Spotlight search and quickly find apps." }, { title: "Virtual Desktops", tip: "Use the numbered buttons (1-4) in the taskbar to switch between virtual desktops." }, { title: "Window Management", tip: "Double-click a window title bar to maximize/restore it." }, { title: "Keyboard Shortcuts", tip: "Ctrl+T opens Terminal, Ctrl+S opens Settings, Ctrl+F opens Files." }, { title: "Theme Switching", tip: "Click the Start menu and use 'Switch Clearance' to change between Foundation and Corp modes." }, { title: "Sound Settings", tip: "Toggle system sounds in Settings to enable audio feedback for actions." }, { title: "Dock Apps", tip: "Your most-used apps are pinned to the quick-launch dock for easy access." }, { title: "Right-Click Menu", tip: "Right-click on the desktop to access quick options like refresh and settings." }, { title: "Calculator", tip: "Need quick math? Open Calculator from the app menu or dock." }, { title: "Notifications", tip: "Click the bell icon in the taskbar to view system notifications." }, ]; const PINNED_APPS = ['terminal', 'networkneighborhood', 'calculator', 'settings']; const CLEARANCE_THEMES: Record = { foundation: { id: 'foundation', name: 'The Foundation', title: 'FOUNDATION', subtitle: 'The Architect\'s Domain', primary: '#DC2626', secondary: '#D4AF37', accent: '#DC2626', accentSecondary: '#D4AF37', wallpaper: 'radial-gradient(ellipse at 30% 20%, #4a1515 0%, #1a0505 40%, #0a0202 100%)', borderStyle: 'border-yellow-600/40', fontStyle: 'font-mono', }, corp: { id: 'corp', name: 'The Corp', title: 'CORPORATION', subtitle: 'Executive Operations', primary: '#0F172A', secondary: '#C0C0C0', accent: '#3B82F6', accentSecondary: '#C0C0C0', wallpaper: 'radial-gradient(ellipse at 70% 80%, #1e3a5f 0%, #0f172a 40%, #050a14 100%)', borderStyle: 'border-slate-400/30', fontStyle: 'font-sans', }, }; interface DesktopApp { id: string; title: string; icon: React.ReactNode; component: string; defaultWidth: number; defaultHeight: number; } interface ContextMenuState { x: number; y: number; type: 'desktop' | 'icon'; appId?: string; } const WALLPAPERS = [ { id: 'default', name: 'Cyber Grid', bg: 'linear-gradient(to bottom right, #0f172a, #1e1b4b, #0f172a)', secret: false }, { id: 'matrix', name: 'Matrix', bg: 'linear-gradient(to bottom, #001100, #002200, #001100)', secret: false }, { id: 'sunset', name: 'Neon Sunset', bg: 'linear-gradient(to bottom, #1a0533, #4a1942, #0f172a)', secret: false }, { id: 'ocean', name: 'Deep Ocean', bg: 'linear-gradient(to bottom, #0a1628, #0d3b66, #0a1628)', secret: false }, { id: 'vaporwave', name: 'โšก Vaporwave', bg: 'linear-gradient(135deg, #ff71ce, #01cdfe, #05ffa1, #b967ff)', secret: true }, { id: 'bloodmoon', name: '๐Ÿ”ฅ Blood Moon', bg: 'linear-gradient(to bottom, #1a0000, #4a0000, #1a0000)', secret: true }, { id: 'galaxy', name: '๐ŸŒŒ Galaxy', bg: 'radial-gradient(ellipse at center, #1b2735 0%, #090a0f 100%)', secret: true }, ]; const KONAMI_CODE = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a']; export default function AeThexOS() { const [isBooting, setIsBooting] = useState(true); const [bootProgress, setBootProgress] = useState(0); const [bootStep, setBootStep] = useState(''); const [windows, setWindows] = useState([]); const [activeWindowId, setActiveWindowId] = useState(null); const [maxZIndex, setMaxZIndex] = useState(1); const [showStartMenu, setShowStartMenu] = useState(false); const [time, setTime] = useState(new Date()); const [contextMenu, setContextMenu] = useState(null); const [wallpaper, setWallpaper] = useState(WALLPAPERS[0]); const [soundEnabled, setSoundEnabled] = useState(false); const [showScreensaver, setShowScreensaver] = useState(false); const [notifications, setNotifications] = useState([]); const [showNotifications, setShowNotifications] = useState(false); const [secretsUnlocked, setSecretsUnlocked] = useState(false); const [konamiProgress, setKonamiProgress] = useState([]); const [toasts, setToasts] = useState([]); const [showSpotlight, setShowSpotlight] = useState(false); const [spotlightQuery, setSpotlightQuery] = useState(''); const [currentDesktop, setCurrentDesktop] = useState(0); const [showOnboarding, setShowOnboarding] = useState(false); const [onboardingStep, setOnboardingStep] = useState(0); const [desktopIcons, setDesktopIcons] = useState([]); const [theme, setTheme] = useState(() => { const saved = localStorage.getItem('aethex-theme'); return saved ? JSON.parse(saved) : { mode: 'dark', accentColor: 'cyan', transparency: 80 }; }); const [savedLayouts, setSavedLayouts] = useState(() => { const saved = localStorage.getItem('aethex-layouts'); return saved ? JSON.parse(saved) : []; }); const [clearanceMode, setClearanceMode] = useState(() => { const saved = localStorage.getItem('aethex-clearance'); return (saved as ClearanceMode) || 'foundation'; }); const [isSwitchingClearance, setIsSwitchingClearance] = useState(false); const [showDailyTip, setShowDailyTip] = useState(false); const [dailyTip, setDailyTip] = useState(DAILY_TIPS[0]); const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 }); const audioContextRef = useRef(null); const clearanceTheme = CLEARANCE_THEMES[clearanceMode]; const desktopRef = useRef(null); const idleTimer = useRef(null); const spotlightRef = useRef(null); const { user, isAuthenticated, logout } = useAuth(); const [, setLocation] = useLocation(); const [activeTrayPanel, setActiveTrayPanel] = useState<'wifi' | 'volume' | 'battery' | 'notifications' | 'upgrade' | null>(null); const [volume, setVolume] = useState(75); const [isMuted, setIsMuted] = useState(false); const [batteryInfo, setBatteryInfo] = useState<{ level: number; charging: boolean } | null>(null); useEffect(() => { if ('getBattery' in navigator) { (navigator as any).getBattery().then((battery: any) => { setBatteryInfo({ level: Math.round(battery.level * 100), charging: battery.charging }); battery.addEventListener('levelchange', () => { setBatteryInfo(prev => prev ? { ...prev, level: Math.round(battery.level * 100) } : null); }); battery.addEventListener('chargingchange', () => { setBatteryInfo(prev => prev ? { ...prev, charging: battery.charging } : null); }); }); } }, []); const { data: weatherData, isFetching: weatherFetching } = useQuery({ queryKey: ['weather'], queryFn: async () => { const res = await fetch('https://api.open-meteo.com/v1/forecast?latitude=40.7128&longitude=-74.0060¤t_weather=true&temperature_unit=fahrenheit'); return res.json(); }, refetchInterval: 600000, staleTime: 300000, }); const addToast = useCallback((message: string, type: Toast['type'] = 'info') => { const id = Date.now().toString(); setToasts(prev => [...prev, { id, message, type }]); setTimeout(() => setToasts(prev => prev.filter(t => t.id !== id)), 4000); }, []); useEffect(() => { localStorage.setItem('aethex-theme', JSON.stringify(theme)); }, [theme]); useEffect(() => { localStorage.setItem('aethex-layouts', JSON.stringify(savedLayouts)); }, [savedLayouts]); useEffect(() => { localStorage.setItem('aethex-clearance', clearanceMode); }, [clearanceMode]); useEffect(() => { const handleMouseMove = (e: MouseEvent) => { setMousePosition({ x: e.clientX, y: e.clientY }); }; window.addEventListener('mousemove', handleMouseMove); return () => window.removeEventListener('mousemove', handleMouseMove); }, []); const [showLoginPrompt, setShowLoginPrompt] = useState(false); const [isDesktopLocked, setIsDesktopLocked] = useState(true); useEffect(() => { const bootSequence = async () => { const steps = [ { text: 'BIOS CHECK... OK', progress: 5 }, { text: 'Initializing AeThex OS...', progress: 10 }, { text: 'Loading kernel modules...', progress: 20 }, { text: 'Mounting file systems...', progress: 30 }, { text: 'INITIATING AETHEX PASSPORT...', progress: 40 }, { text: 'DETECTING CROSS-PLATFORM IDENTITY...', progress: 55 }, { text: 'Starting Aegis security layer...', progress: 65 }, { text: 'STATUS: NEUTRAL LAYER ACTIVE.', progress: 75 }, { text: 'Connecting to Nexus network...', progress: 85 }, { text: 'IDENTITY SYSTEM READY.', progress: 100 }, ]; for (const step of steps) { setBootStep(step.text); setBootProgress(step.progress); await new Promise(r => setTimeout(r, 350)); } await new Promise(r => setTimeout(r, 400)); setShowLoginPrompt(true); }; bootSequence(); }, []); useEffect(() => { const timer = setInterval(() => setTime(new Date()), 1000); return () => clearInterval(timer); }, []); useEffect(() => { const fetchNotifications = async () => { try { const res = await fetch('/api/os/notifications'); const data = await res.json(); if (Array.isArray(data)) { setNotifications(data.map((n: any) => n.message)); } } catch {} }; fetchNotifications(); const interval = setInterval(fetchNotifications, 60000); return () => clearInterval(interval); }, []); useEffect(() => { const resetIdle = () => { if (showScreensaver) setShowScreensaver(false); if (idleTimer.current) clearTimeout(idleTimer.current); idleTimer.current = setTimeout(() => setShowScreensaver(true), 5 * 60 * 1000); }; window.addEventListener('mousemove', resetIdle); window.addEventListener('keydown', resetIdle); resetIdle(); return () => { window.removeEventListener('mousemove', resetIdle); window.removeEventListener('keydown', resetIdle); if (idleTimer.current) clearTimeout(idleTimer.current); }; }, [showScreensaver]); useEffect(() => { const handleKonami = (e: KeyboardEvent) => { setKonamiProgress(prev => { const newProgress = [...prev, e.key].slice(-10); if (newProgress.length === 10 && newProgress.every((k, i) => k === KONAMI_CODE[i])) { setSecretsUnlocked(true); setNotifications(prev => ['๐ŸŽฎ SECRETS UNLOCKED! Check Settings for new wallpapers.', ...prev]); return []; } return newProgress; }); }; const handleTerminalUnlock = () => { setSecretsUnlocked(true); setNotifications(prev => ['๐Ÿ”“ Terminal unlock activated! Check Settings.', ...prev]); }; window.addEventListener('keydown', handleKonami); window.addEventListener('aethex-unlock-secrets', handleTerminalUnlock); return () => { window.removeEventListener('keydown', handleKonami); window.removeEventListener('aethex-unlock-secrets', handleTerminalUnlock); }; }, []); useEffect(() => { if (showSpotlight && spotlightRef.current) { spotlightRef.current.focus(); } }, [showSpotlight]); useEffect(() => { const saved = localStorage.getItem('aethex-window-positions'); if (saved) { try { const positions = JSON.parse(saved); setWindows(prev => prev.map(w => { const savedPos = positions[w.id]; return savedPos ? { ...w, ...savedPos } : w; })); } catch {} } const hasVisited = localStorage.getItem('aethex-visited'); if (!hasVisited) { setShowOnboarding(true); localStorage.setItem('aethex-visited', 'true'); } }, []); useEffect(() => { if (windows.length > 0) { const positions: Record = {}; windows.forEach(w => { positions[w.id] = { x: w.x, y: w.y, width: w.width, height: w.height }; }); localStorage.setItem('aethex-window-positions', JSON.stringify(positions)); } }, [windows]); const foundationApps: DesktopApp[] = [ { id: "networkneighborhood", title: "Network Neighborhood", icon: , component: "networkneighborhood", defaultWidth: 500, defaultHeight: 450 }, { id: "mission", title: "README.TXT", icon: , component: "mission", defaultWidth: 500, defaultHeight: 500 }, { id: "foundry", title: "FOUNDRY.EXE", icon: , component: "foundry", defaultWidth: 450, defaultHeight: 500 }, { id: "intel", title: "INTEL", icon: , component: "intel", defaultWidth: 550, defaultHeight: 450 }, { id: "drives", title: "My Computer", icon: , component: "drives", defaultWidth: 450, defaultHeight: 400 }, { id: "chat", title: "AeThex AI", icon: , component: "chat", defaultWidth: 400, defaultHeight: 500 }, { id: "terminal", title: "Terminal", icon: , component: "terminal", defaultWidth: 750, defaultHeight: 500 }, { id: "metrics", title: "System Status", icon: , component: "metrics", defaultWidth: 750, defaultHeight: 550 }, { id: "passport", title: "LOGIN", icon: , component: "passport", defaultWidth: 500, defaultHeight: 600 }, { id: "devtools", title: "Dev Tools", icon: , component: "devtools", defaultWidth: 450, defaultHeight: 400 }, { id: "music", title: "Radio AeThex", icon: , component: "music", defaultWidth: 400, defaultHeight: 350 }, { id: "codeeditor", title: "The Lab", icon: , component: "codeeditor", defaultWidth: 700, defaultHeight: 500 }, { id: "arcade", title: "Arcade", icon: , component: "arcade", defaultWidth: 420, defaultHeight: 520 }, { id: "calculator", title: "Calculator", icon: , component: "calculator", defaultWidth: 320, defaultHeight: 450 }, { id: "settings", title: "Settings", icon: , component: "settings", defaultWidth: 550, defaultHeight: 500 }, ]; const corpApps: DesktopApp[] = [ { id: "networkneighborhood", title: "Network Neighborhood", icon: , component: "networkneighborhood", defaultWidth: 500, defaultHeight: 450 }, { id: "mission", title: "README.TXT", icon: , component: "mission", defaultWidth: 500, defaultHeight: 500 }, { id: "foundry", title: "FOUNDRY.EXE", icon: , component: "foundry", defaultWidth: 450, defaultHeight: 500 }, { id: "intel", title: "INTEL", icon: , component: "intel", defaultWidth: 550, defaultHeight: 450 }, { id: "drives", title: "My Computer", icon: , component: "drives", defaultWidth: 450, defaultHeight: 400 }, { id: "devtools", title: "Dev Tools", icon: , component: "devtools", defaultWidth: 450, defaultHeight: 400 }, { id: "metrics", title: "System Status", icon: , component: "metrics", defaultWidth: 750, defaultHeight: 550 }, { id: "passport", title: "LOGIN", icon: , component: "passport", defaultWidth: 500, defaultHeight: 600 }, { id: "network", title: "Global Ops", icon: , component: "network", defaultWidth: 700, defaultHeight: 550 }, { id: "files", title: "Asset Library", icon: , component: "files", defaultWidth: 700, defaultHeight: 500 }, { id: "pitch", title: "Contracts", icon: , component: "pitch", defaultWidth: 500, defaultHeight: 400 }, { id: "sysmonitor", title: "Infrastructure", icon: , component: "sysmonitor", defaultWidth: 450, defaultHeight: 400 }, { id: "leaderboard", title: "Performance", icon: , component: "leaderboard", defaultWidth: 500, defaultHeight: 550 }, { id: "calculator", title: "Calculator", icon: , component: "calculator", defaultWidth: 320, defaultHeight: 450 }, { id: "settings", title: "Settings", icon: , component: "settings", defaultWidth: 550, defaultHeight: 500 }, ]; const apps = clearanceMode === 'foundation' ? foundationApps : corpApps; const playSound = useCallback((type: 'open' | 'close' | 'minimize' | 'click' | 'notification' | 'switch') => { if (!soundEnabled) return; try { if (!audioContextRef.current) { audioContextRef.current = new AudioContext(); } const ctx = audioContextRef.current; const oscillator = ctx.createOscillator(); const gainNode = ctx.createGain(); oscillator.connect(gainNode); gainNode.connect(ctx.destination); const sounds: Record = { open: { freq: 523, duration: 0.1, type: 'sine' }, close: { freq: 392, duration: 0.1, type: 'sine' }, minimize: { freq: 330, duration: 0.08, type: 'sine' }, click: { freq: 800, duration: 0.03, type: 'square' }, notification: { freq: 880, duration: 0.15, type: 'sine' }, switch: { freq: 440, duration: 0.2, type: 'sawtooth' }, }; const sound = sounds[type] || sounds.click; oscillator.type = sound.type; oscillator.frequency.setValueAtTime(sound.freq, ctx.currentTime); gainNode.gain.setValueAtTime(0.1, ctx.currentTime); gainNode.gain.exponentialRampToValueAtTime(0.01, ctx.currentTime + sound.duration); oscillator.start(ctx.currentTime); oscillator.stop(ctx.currentTime + sound.duration); } catch (e) { console.log('Audio not available'); } }, [soundEnabled]); const switchClearance = useCallback(() => { const newMode: ClearanceMode = clearanceMode === 'foundation' ? 'corp' : 'foundation'; setIsSwitchingClearance(true); setShowStartMenu(false); playSound('switch'); setTimeout(() => { setClearanceMode(newMode); setIsSwitchingClearance(false); addToast(`Switched to ${CLEARANCE_THEMES[newMode].name}`, 'success'); }, 600); }, [clearanceMode, addToast, playSound]); const openApp = useCallback((app: DesktopApp) => { const appToOpen = (isDesktopLocked && app.id !== 'passport') ? apps.find(a => a.id === 'passport') || app : app; playSound('open'); const existingWindow = windows.find(w => w.id === appToOpen.id); if (existingWindow) { setWindows(prev => prev.map(w => w.id === appToOpen.id ? { ...w, minimized: false, zIndex: maxZIndex + 1, desktopId: currentDesktop } : w )); setMaxZIndex(prev => prev + 1); setActiveWindowId(appToOpen.id); return; } const offsetX = (windows.length % 5) * 40 + 100; const offsetY = (windows.length % 5) * 40 + 50; const newWindow: WindowState = { id: appToOpen.id, title: appToOpen.title, icon: appToOpen.icon, component: appToOpen.component, x: offsetX, y: offsetY, width: appToOpen.defaultWidth, height: appToOpen.defaultHeight, minimized: false, maximized: false, zIndex: maxZIndex + 1, desktopId: currentDesktop }; setWindows(prev => [...prev, newWindow]); setMaxZIndex(prev => prev + 1); setActiveWindowId(appToOpen.id); setShowStartMenu(false); }, [windows, maxZIndex, playSound, currentDesktop, isDesktopLocked, apps]); const closeWindow = useCallback((id: string) => { playSound('close'); setWindows(prev => prev.filter(w => w.id !== id)); if (activeWindowId === id) setActiveWindowId(null); }, [activeWindowId, playSound]); const minimizeWindow = useCallback((id: string) => { playSound('minimize'); setWindows(prev => prev.map(w => w.id === id ? { ...w, minimized: true } : w)); }, [playSound]); const toggleMaximize = useCallback((id: string) => { setWindows(prev => prev.map(w => w.id === id ? { ...w, maximized: !w.maximized } : w)); }, []); const focusWindow = useCallback((id: string) => { setWindows(prev => prev.map(w => w.id === id ? { ...w, zIndex: maxZIndex + 1 } : w)); setMaxZIndex(prev => prev + 1); setActiveWindowId(id); }, [maxZIndex]); const handleDesktopClick = (e: React.MouseEvent) => { setShowStartMenu(false); setContextMenu(null); }; const handleDesktopContextMenu = (e: React.MouseEvent) => { e.preventDefault(); setContextMenu({ x: e.clientX, y: e.clientY, type: 'desktop' }); }; const handleIconContextMenu = (e: React.MouseEvent, appId: string) => { e.preventDefault(); e.stopPropagation(); setContextMenu({ x: e.clientX, y: e.clientY, type: 'icon', appId }); }; const handleWindowSnap = useCallback((id: string, x: number, y: number, width: number, height: number) => { const screenWidth = window.innerWidth; const screenHeight = window.innerHeight - 48; if (x <= 10) { setWindows(prev => prev.map(w => w.id === id ? { ...w, x: 0, y: 0, width: screenWidth / 2, height: screenHeight } : w)); return true; } if (x + width >= screenWidth - 10) { setWindows(prev => prev.map(w => w.id === id ? { ...w, x: screenWidth / 2, y: 0, width: screenWidth / 2, height: screenHeight } : w)); return true; } if (y <= 10) { setWindows(prev => prev.map(w => w.id === id ? { ...w, x: 0, y: 0, width: screenWidth, height: screenHeight, maximized: true } : w)); return true; } return false; }, []); const handleLogout = async () => { await logout(); setLocation("/"); }; useEffect(() => { const handleGlobalKeys = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === ' ') { e.preventDefault(); setShowSpotlight(prev => !prev); setSpotlightQuery(''); } if (e.key === 'Escape') { setShowSpotlight(false); setShowStartMenu(false); setContextMenu(null); } if ((e.metaKey || e.ctrlKey) && !e.shiftKey) { const shortcuts: Record = { 't': 'terminal', 'n': 'notes', 'e': 'codeeditor', 'p': 'passport', 'm': 'metrics' }; if (shortcuts[e.key]) { e.preventDefault(); const app = apps.find(a => a.id === shortcuts[e.key]); if (app) openApp(app); } } if ((e.metaKey || e.ctrlKey) && e.key >= '1' && e.key <= '4') { e.preventDefault(); setCurrentDesktop(parseInt(e.key) - 1); addToast(`Switched to Desktop ${e.key}`, 'info'); } }; window.addEventListener('keydown', handleGlobalKeys); return () => window.removeEventListener('keydown', handleGlobalKeys); }, [apps, openApp, addToast]); const renderAppContent = (component: string) => { switch (component) { case 'terminal': return ; case 'passport': return ; case 'files': return ; case 'network': return ; case 'metrics': return ; case 'codeeditor': return ; case 'newsfeed': return ; case 'arcade': return ; case 'profiles': return ; case 'leaderboard': return ; case 'calculator': return ; case 'notes': return ; case 'sysmonitor': return ; case 'webcam': return ; case 'achievements': return ; case 'chat': return ; case 'music': return ; case 'pitch': return setLocation('/pitch')} />; case 'networkneighborhood': return ; case 'foundry': return ; case 'devtools': return ; case 'mission': return ; case 'intel': return ; case 'drives': return ; case 'iframe': return null; case 'settings': return { const layout: DesktopLayout = { name, windows: windows.map(w => ({ appId: w.component, x: w.x, y: w.y, width: w.width, height: w.height })), desktop: currentDesktop, }; setSavedLayouts(prev => [...prev.filter(l => l.name !== name), layout]); addToast(`Layout "${name}" saved`, 'success'); }} onLoadLayout={(layout) => { setWindows([]); setTimeout(() => { layout.windows.forEach((w, i) => { const app = apps.find(a => a.component === w.appId); if (app) { const windowId = `${app.id}-${Date.now()}-${i}`; setWindows(prev => [...prev, { id: windowId, title: app.title, icon: app.icon, component: app.component, x: w.x, y: w.y, width: w.width, height: w.height, minimized: false, maximized: false, zIndex: i + 1, desktopId: layout.desktop }]); } }); setCurrentDesktop(layout.desktop); addToast(`Layout "${layout.name}" loaded`, 'success'); }, 100); }} onDeleteLayout={(name) => { setSavedLayouts(prev => prev.filter(l => l.name !== name)); addToast(`Layout "${name}" deleted`, 'info'); }} />; default: return null; } }; const handleGuestContinue = () => { setShowLoginPrompt(false); setIsBooting(false); setIsDesktopLocked(false); const randomTip = DAILY_TIPS[Math.floor(Math.random() * DAILY_TIPS.length)]; setDailyTip(randomTip); setTimeout(() => setShowDailyTip(true), 1000); }; const handleLoginFromBoot = () => { setShowLoginPrompt(false); setIsBooting(false); // Keep desktop locked until login succeeds const randomTip = DAILY_TIPS[Math.floor(Math.random() * DAILY_TIPS.length)]; setDailyTip(randomTip); setTimeout(() => { setShowDailyTip(true); const passportApp = apps.find(a => a.id === 'passport'); if (passportApp) openApp(passportApp); }, 500); }; const unlockDesktop = () => { setIsDesktopLocked(false); }; const openIframeWindow = (url: string, title: string) => { // Most external sites block iframe embedding - open in new tab instead window.open(url, '_blank', 'noopener,noreferrer'); }; if (isBooting) { return (
A
{bootStep}
AeThex OS v1.0.0
{showLoginPrompt && (
โœ“ CROSS-PLATFORM IDENTITY READY
)}
); } if (showScreensaver) { return (
setShowScreensaver(false)} >
AeThex
Click to wake
); } const parallaxX = (mousePosition.x / window.innerWidth - 0.5) * 10; const parallaxY = (mousePosition.y / window.innerHeight - 0.5) * 10; return (
{apps.slice(0, 9).map((app) => ( openApp(app)} onContextMenu={(e) => handleIconContextMenu(e, app.id)} /> ))}
{isDesktopLocked && windows.length === 0 && (

Desktop Locked

Sign in with your Passport to continue

)} {windows.filter(w => !w.minimized && w.desktopId === currentDesktop).map((window) => ( closeWindow(window.id)} onMinimize={() => minimizeWindow(window.id)} onMaximize={() => toggleMaximize(window.id)} onFocus={() => focusWindow(window.id)} onMove={(x, y) => setWindows(prev => prev.map(w => w.id === window.id ? { ...w, x, y } : w))} onResize={(width, height) => setWindows(prev => prev.map(w => w.id === window.id ? { ...w, width, height } : w))} onSnap={(x, y) => handleWindowSnap(window.id, x, y, window.width, window.height)} content={window.component === 'iframe' && window.iframeUrl ? (