/** * EcoOS Overview View * Shows services status, CPU, memory, system info, and controls */ import { html, DeesElement, customElement, property, css, type TemplateResult, } from '@design.estate/dees-element'; import { sharedStyles, formatBytes, formatUptime } from '../styles/shared.js'; import type { IStatus, IServiceStatus } from '../../ts_interfaces/status.js'; @customElement('ecoos-overview') export class EcoosOverview extends DeesElement { @property({ type: Object }) public accessor status: IStatus | null = null; @property({ type: Boolean }) public accessor loading: boolean = false; public static styles = [ sharedStyles, css` :host { display: block; padding: 20px; } .service-status { display: flex; align-items: center; padding: 8px 0; } .controls-section { margin-top: 16px; } .control-status { margin-top: 8px; font-size: 12px; color: var(--ecoos-text-dim); } `, ]; render(): TemplateResult { if (!this.status) { return html`
Loading...
`; } const { systemInfo, sway, chromium, swayStatus, chromiumStatus } = this.status; return html`
Services
Sway Compositor
Chromium Browser
CPU
Model
${systemInfo?.cpu?.model || '-'}
Cores
${systemInfo?.cpu?.cores || '-'}
Usage
${systemInfo?.cpu?.usage || 0}%
Memory
Used / Total
${formatBytes(systemInfo?.memory?.used || 0)} / ${formatBytes(systemInfo?.memory?.total || 0)}
System
Hostname
${systemInfo?.hostname || '-'}
Uptime
${formatUptime(systemInfo?.uptime || 0)}
GPU
${systemInfo?.gpu?.length ? systemInfo.gpu.map(g => g.name).join(', ') : 'None detected'}
Controls
`; } private getStatusClass(status: IServiceStatus): string { switch (status?.state) { case 'running': return 'running'; case 'starting': return 'starting'; default: return 'stopped'; } } private async restartChromium(): Promise { this.loading = true; try { const response = await fetch('/api/restart-chromium', { method: 'POST' }); const result = await response.json(); this.showControlStatus(result.message, !result.success); } catch (error) { this.showControlStatus(`Error: ${error}`, true); } finally { this.loading = false; } } private async rebootSystem(): Promise { if (!confirm('Are you sure you want to reboot the system?')) return; this.loading = true; try { const response = await fetch('/api/reboot', { method: 'POST' }); const result = await response.json(); this.showControlStatus(result.message, !result.success); } catch (error) { this.showControlStatus(`Error: ${error}`, true); } finally { this.loading = false; } } private showControlStatus(message: string, isError: boolean): void { const el = this.shadowRoot?.getElementById('control-status'); if (el) { el.textContent = message; el.style.color = isError ? 'var(--ecoos-error)' : 'var(--ecoos-success)'; } } }