class ArchServerPanel extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.services = [ { name: 'Plex', port: 32400, status: 'unknown' }, { name: 'Nextcloud', port: 8080, status: 'unknown' }, { name: 'Pi-hole', port: 80, status: 'unknown' }, { name: 'SSH', port: 22, status: 'unknown' }, { name: 'Home Assistant', port: 8123, status: 'unknown' } ]; } connectedCallback() { this.render(); this.checkServices(); } render() { this.shadowRoot.innerHTML = `
Server Config
~/homelab/services
Services
Configuration
`; this.setupInteractions(); this.renderServices(); } setupInteractions() { const closeBtn = this.shadowRoot.getElementById('close-btn'); if (closeBtn) { closeBtn.addEventListener('click', () => { this.dispatchEvent(new CustomEvent('toggle-server-panel', { bubbles: true, composed: true })); }); } const saveBtn = this.shadowRoot.getElementById('save-config'); const urlInput = this.shadowRoot.getElementById('server-url'); // Load saved config const saved = localStorage.getItem('serverEndpoint'); if (saved && urlInput) urlInput.value = saved; if (saveBtn && urlInput) { saveBtn.addEventListener('click', () => { const url = urlInput.value; localStorage.setItem('serverEndpoint', url); // Show feedback saveBtn.textContent = 'Saved!'; setTimeout(() => { saveBtn.textContent = 'Save Configuration'; if (window.launcher) { window.launcher.serverEndpoint = url; window.launcher.checkServerStatus(); } }, 1000); }); } // Listen for server status updates window.addEventListener('server-status', (e) => { this.updateServerStatus(e.detail); }); } renderServices() { const container = this.shadowRoot.getElementById('services-list'); if (!container) return; container.innerHTML = ''; this.services.forEach(service => { const el = document.createElement('div'); el.className = 'service-item'; el.innerHTML = `
${service.name}
:${service.port}
checking
`; container.appendChild(el); }); } checkServices() { // Simulate checking services (in real use, these would be actual fetch requests) setTimeout(() => { this.services.forEach(service => { const statusEl = this.shadowRoot.getElementById(`status-${service.name}`); if (statusEl) { const isOnline = Math.random() > 0.3; // Simulate random status statusEl.className = `status ${isOnline ? 'online' : 'offline'}`; statusEl.innerHTML = `
${isOnline ? 'online' : 'offline'} `; } }); }, 1500); } updateServerStatus(status) { // Could update specific UI elements based on main server status console.log('Server panel received status:', status); } } customElements.define('arch-server-panel', ArchServerPanel);