feat(01-01): create device registry, show store, FastAPI app, API routes, and frontend shell
- DeviceRegistry with load/save/add/remove/instantiate and _DEVICE_CLASSES dict
- ShowStore with save/load/list_ids using aiofiles for async I/O
- FastAPI app with lifespan hook (startup: load registry/store, shutdown: save registry)
- API routes: GET/POST /api/devices/, DELETE /api/devices/{id}, GET/POST /api/shows/, GET /api/shows/{id}
- WebSocket stub at /ws with ConnectionManager and ack echo
- Frontend shell: DAW layout with header, sidebar (DEVICES + ANIMATIONS), TIMELINE, TRANSPORT
- Terminal aesthetic: dark theme, cyan accents, monospace fonts, no drop shadows
- .gitignore for runtime data (devices.json, shows/, __pycache__, .venv)
This commit is contained in:
88
lightsync/frontend/app.js
Normal file
88
lightsync/frontend/app.js
Normal file
@@ -0,0 +1,88 @@
|
||||
// LightSync frontend — Phase 1 shell
|
||||
// WebSocket stub + device list loader
|
||||
// Phase 2 expands audio, transport, and WS protocol
|
||||
|
||||
const WS_URL = `ws://${location.host}/ws`;
|
||||
|
||||
class LightSyncClient {
|
||||
constructor() {
|
||||
this.ws = null;
|
||||
this.reconnectDelay = 2000;
|
||||
this._reconnectTimer = null;
|
||||
}
|
||||
|
||||
connect() {
|
||||
if (this._reconnectTimer) {
|
||||
clearTimeout(this._reconnectTimer);
|
||||
this._reconnectTimer = null;
|
||||
}
|
||||
|
||||
this.ws = new WebSocket(WS_URL);
|
||||
|
||||
this.ws.onopen = () => {
|
||||
document.getElementById("status-dot").className = "status-dot connected";
|
||||
document.getElementById("status-text").textContent = "CONNECTED";
|
||||
};
|
||||
|
||||
this.ws.onclose = () => {
|
||||
document.getElementById("status-dot").className = "status-dot";
|
||||
document.getElementById("status-text").textContent = "OFFLINE";
|
||||
this._reconnectTimer = setTimeout(() => this.connect(), this.reconnectDelay);
|
||||
};
|
||||
|
||||
this.ws.onerror = () => {
|
||||
document.getElementById("status-dot").className = "status-dot error";
|
||||
};
|
||||
|
||||
this.ws.onmessage = (event) => {
|
||||
const msg = JSON.parse(event.data);
|
||||
this.handleMessage(msg);
|
||||
};
|
||||
}
|
||||
|
||||
handleMessage(msg) {
|
||||
// Phase 2 will dispatch on msg.type
|
||||
console.debug("[ws]", msg);
|
||||
}
|
||||
|
||||
send(msg) {
|
||||
if (this.ws?.readyState === WebSocket.OPEN) {
|
||||
this.ws.send(JSON.stringify(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const client = new LightSyncClient();
|
||||
client.connect();
|
||||
|
||||
// Load device list on startup
|
||||
async function loadDevices() {
|
||||
try {
|
||||
const res = await fetch("/api/devices/");
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const devices = await res.json();
|
||||
const list = document.getElementById("device-list");
|
||||
if (devices.length === 0) {
|
||||
list.innerHTML = '<span class="text-dim">no devices registered</span>';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = devices.map(d =>
|
||||
`<div class="device-row">
|
||||
<span class="text-accent">${escapeHtml(d.name)}</span>
|
||||
<span class="text-dim">${escapeHtml(d.strip_type)} / ${d.led_count} LEDs / ${escapeHtml(d.ip)}:${d.port}</span>
|
||||
</div>`
|
||||
).join("");
|
||||
} catch (err) {
|
||||
const list = document.getElementById("device-list");
|
||||
list.innerHTML = `<span class="text-dim">error loading devices</span>`;
|
||||
console.error("[devices]", err);
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
const div = document.createElement("div");
|
||||
div.appendChild(document.createTextNode(String(str)));
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
loadDevices();
|
||||
46
lightsync/frontend/index.html
Normal file
46
lightsync/frontend/index.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LIGHTSYNC</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<!-- JetBrains Mono via Google Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div class="app-shell">
|
||||
|
||||
<header class="header">
|
||||
<span class="header-title">■ LIGHTSYNC</span>
|
||||
<div class="status-dot" id="status-dot"></div>
|
||||
<span id="status-text" class="text-dim">OFFLINE</span>
|
||||
<span id="show-name" class="text-dim">— no show loaded —</span>
|
||||
</header>
|
||||
|
||||
<aside class="sidebar">
|
||||
<div class="panel" style="flex: 1; min-height: 0;">
|
||||
<div class="panel-header">DEVICES</div>
|
||||
<div class="panel-content" id="device-list">
|
||||
<span class="text-dim">loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel" style="flex: 0 0 120px;">
|
||||
<div class="panel-header">ANIMATIONS</div>
|
||||
<div class="panel-content text-dim">[ PHASE 3+ ]</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main class="main-area">
|
||||
<span>[ TIMELINE — PHASE 2+ ]</span>
|
||||
</main>
|
||||
|
||||
<footer class="transport-bar">
|
||||
<span>[ TRANSPORT — PHASE 2+ ]</span>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
<script src="/app.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
169
lightsync/frontend/style.css
Normal file
169
lightsync/frontend/style.css
Normal file
@@ -0,0 +1,169 @@
|
||||
:root {
|
||||
--bg-primary: #0a0a0a;
|
||||
--bg-panel: #0f0f0f;
|
||||
--bg-panel-dark: #080808;
|
||||
--border-dim: #1a4a4a;
|
||||
--border-bright: #00ffff;
|
||||
--text-primary: #cccccc;
|
||||
--text-dim: #555555;
|
||||
--text-accent: #00ffff;
|
||||
--text-warning: #ff6600;
|
||||
--font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
|
||||
--font-size: 13px;
|
||||
--panel-gap: 1px;
|
||||
}
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size);
|
||||
line-height: 1.4;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* DAW layout — header / (sidebar + main) / transport */
|
||||
.app-shell {
|
||||
display: grid;
|
||||
grid-template-rows: 40px 1fr 48px;
|
||||
grid-template-columns: 280px 1fr;
|
||||
grid-template-areas:
|
||||
"header header"
|
||||
"sidebar main"
|
||||
"transport transport";
|
||||
height: 100vh;
|
||||
gap: var(--panel-gap);
|
||||
}
|
||||
|
||||
.header {
|
||||
grid-area: header;
|
||||
background: var(--bg-panel-dark);
|
||||
border-bottom: 1px solid var(--border-dim);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.header-title {
|
||||
color: var(--text-accent);
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
grid-area: sidebar;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-right: 1px solid var(--border-dim);
|
||||
overflow: hidden;
|
||||
gap: var(--panel-gap);
|
||||
}
|
||||
|
||||
.panel {
|
||||
border: 1px solid var(--border-dim);
|
||||
background: var(--bg-panel);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
background: var(--bg-panel-dark);
|
||||
border-bottom: 1px solid var(--border-dim);
|
||||
padding: 6px 12px;
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.12em;
|
||||
color: var(--text-accent);
|
||||
text-transform: uppercase;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.panel-content {
|
||||
flex: 1;
|
||||
padding: 8px 12px;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* Scrollbar — terminal feel */
|
||||
::-webkit-scrollbar { width: 4px; }
|
||||
::-webkit-scrollbar-track { background: var(--bg-primary); }
|
||||
::-webkit-scrollbar-thumb { background: var(--border-dim); }
|
||||
|
||||
.main-area {
|
||||
grid-area: main;
|
||||
background: var(--bg-panel-dark);
|
||||
border: 1px solid var(--border-dim);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-dim);
|
||||
font-size: 14px;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
.transport-bar {
|
||||
grid-area: transport;
|
||||
background: var(--bg-panel-dark);
|
||||
border-top: 1px solid var(--border-dim);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
color: var(--text-dim);
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
/* Status dot */
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--text-dim);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.status-dot.connected { background: #00ff88; }
|
||||
.status-dot.error { background: #ff3333; }
|
||||
|
||||
/* Text helpers */
|
||||
.text-dim { color: var(--text-dim); }
|
||||
.text-accent { color: var(--text-accent); }
|
||||
|
||||
/* Device list rows */
|
||||
.device-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 6px 0;
|
||||
border-bottom: 1px solid var(--bg-panel-dark);
|
||||
gap: 2px;
|
||||
}
|
||||
.device-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
/* Form elements */
|
||||
input, select, button {
|
||||
background: var(--bg-panel);
|
||||
border: 1px solid var(--border-dim);
|
||||
color: var(--text-primary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size);
|
||||
padding: 4px 8px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: var(--border-bright);
|
||||
color: var(--text-accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
Reference in New Issue
Block a user