Initial implementation of Sahsa Clock
Pygame framebuffer clock for Le Potato (ARM Debian) with aiohttp webhook server. Renders 12-hour clock directly to /dev/fb0 (no X11/Wayland). Supports full-screen message overlays pushed via a browser dashboard or Bearer-token API. Includes first-run setup wizard, session-based dashboard auth, bcrypt password storage, per-IP rate limiting, and systemd service unit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
130
dashboard/app.js
Normal file
130
dashboard/app.js
Normal file
@@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
const msgTextarea = document.getElementById('msg');
|
||||
const charNum = document.getElementById('char-num');
|
||||
const sendBtn = document.getElementById('send-btn');
|
||||
const clearBtn = document.getElementById('clear-btn');
|
||||
const statusDot = document.getElementById('status-dot');
|
||||
const statusText = document.getElementById('status-text');
|
||||
|
||||
// ── Character counter ────────────────────────────────────────────────────────
|
||||
|
||||
msgTextarea.addEventListener('input', () => {
|
||||
charNum.textContent = msgTextarea.value.length;
|
||||
});
|
||||
|
||||
// ── Duration helper ──────────────────────────────────────────────────────────
|
||||
|
||||
function getSelectedDuration() {
|
||||
const checked = document.querySelector('input[name="duration"]:checked');
|
||||
return checked ? parseInt(checked.value, 10) : 60;
|
||||
}
|
||||
|
||||
// ── Auth redirect helper ─────────────────────────────────────────────────────
|
||||
|
||||
function handleUnauth(status) {
|
||||
if (status === 401) {
|
||||
window.location.href = '/login';
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ── Send message ─────────────────────────────────────────────────────────────
|
||||
|
||||
async function sendMessage() {
|
||||
const text = msgTextarea.value.trim();
|
||||
if (!text) {
|
||||
msgTextarea.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
const duration = getSelectedDuration();
|
||||
const body = { text };
|
||||
if (duration === 0) {
|
||||
body.persist = true;
|
||||
} else {
|
||||
body.duration = duration;
|
||||
}
|
||||
|
||||
sendBtn.disabled = true;
|
||||
try {
|
||||
const res = await fetch('/dashboard/message', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (handleUnauth(res.status)) return;
|
||||
|
||||
if (res.ok) {
|
||||
msgTextarea.value = '';
|
||||
charNum.textContent = '0';
|
||||
await refreshStatus();
|
||||
} else {
|
||||
const err = await res.text();
|
||||
setStatus(false, `Error: ${err}`);
|
||||
}
|
||||
} catch {
|
||||
setStatus(false, 'Could not reach server.');
|
||||
} finally {
|
||||
sendBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Clear message ────────────────────────────────────────────────────────────
|
||||
|
||||
async function clearMessage() {
|
||||
try {
|
||||
const res = await fetch('/dashboard/message', { method: 'DELETE' });
|
||||
if (handleUnauth(res.status)) return;
|
||||
if (res.ok) {
|
||||
await refreshStatus();
|
||||
}
|
||||
} catch {
|
||||
setStatus(false, 'Could not reach server.');
|
||||
}
|
||||
}
|
||||
|
||||
// ── Status polling ───────────────────────────────────────────────────────────
|
||||
|
||||
function setStatus(active, message) {
|
||||
statusDot.className = 'status-dot' + (active ? ' active' : '');
|
||||
statusText.textContent = message;
|
||||
}
|
||||
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const res = await fetch('/dashboard/status');
|
||||
if (handleUnauth(res.status)) return;
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.active) {
|
||||
let detail = '';
|
||||
if (data.persistent) {
|
||||
detail = ' — until cleared';
|
||||
} else if (data.remaining_seconds !== null) {
|
||||
const secs = Math.round(data.remaining_seconds);
|
||||
const mins = Math.floor(secs / 60);
|
||||
detail = mins > 0
|
||||
? ` — ${mins}m ${secs % 60}s remaining`
|
||||
: ` — ${secs}s remaining`;
|
||||
}
|
||||
setStatus(true, `Showing: "${data.text}"${detail}`);
|
||||
} else {
|
||||
setStatus(false, 'Screen is showing the clock.');
|
||||
}
|
||||
} catch {
|
||||
setStatus(false, 'Could not reach server.');
|
||||
}
|
||||
}
|
||||
|
||||
// ── Wire up events ───────────────────────────────────────────────────────────
|
||||
|
||||
sendBtn.addEventListener('click', sendMessage);
|
||||
clearBtn.addEventListener('click', clearMessage);
|
||||
|
||||
// Initial status fetch, then poll every 5 seconds
|
||||
refreshStatus();
|
||||
setInterval(refreshStatus, 5000);
|
||||
73
dashboard/index.html
Normal file
73
dashboard/index.html
Normal file
@@ -0,0 +1,73 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Sahsa Clock</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<header>
|
||||
<h1>Sahsa Clock</h1>
|
||||
<form method="post" action="/logout">
|
||||
<button type="submit" class="btn-signout">Sign out</button>
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
<section class="card">
|
||||
<h2>Send Message</h2>
|
||||
|
||||
<div class="field">
|
||||
<label for="msg">Message</label>
|
||||
<textarea
|
||||
id="msg"
|
||||
rows="4"
|
||||
maxlength="300"
|
||||
placeholder="Type a message to display on the screen…"
|
||||
></textarea>
|
||||
<div class="char-count"><span id="char-num">0</span> / 300</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>Duration</label>
|
||||
<div class="duration-grid">
|
||||
<label class="dur-option">
|
||||
<input type="radio" name="duration" value="30">
|
||||
<span>30 sec</span>
|
||||
</label>
|
||||
<label class="dur-option">
|
||||
<input type="radio" name="duration" value="60" checked>
|
||||
<span>1 min</span>
|
||||
</label>
|
||||
<label class="dur-option">
|
||||
<input type="radio" name="duration" value="300">
|
||||
<span>5 min</span>
|
||||
</label>
|
||||
<label class="dur-option">
|
||||
<input type="radio" name="duration" value="0">
|
||||
<span>Until cleared</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-row">
|
||||
<button id="send-btn" class="btn btn-primary">Send to Screen</button>
|
||||
<button id="clear-btn" class="btn btn-secondary">Clear Screen</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="status-bar" id="status-bar">
|
||||
<div class="status-dot" id="status-dot"></div>
|
||||
<span id="status-text">Checking…</span>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script src="/static/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
206
dashboard/style.css
Normal file
206
dashboard/style.css
Normal file
@@ -0,0 +1,206 @@
|
||||
/* ── Reset & tokens ────────────────────────────────────────────────────────── */
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
:root {
|
||||
--bg: #0f0f0f;
|
||||
--surface: #1a1a1a;
|
||||
--surface2: #242424;
|
||||
--border: #333;
|
||||
--text: #f0f0f0;
|
||||
--muted: #888;
|
||||
--primary: #2563eb;
|
||||
--primary-h: #1d4ed8;
|
||||
--secondary-h: #2f2f2f;
|
||||
--danger: #dc2626;
|
||||
--success: #16a34a;
|
||||
--radius: 10px;
|
||||
}
|
||||
|
||||
html { font-size: 16px; }
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: system-ui, -apple-system, sans-serif;
|
||||
min-height: 100vh;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* ── Layout ────────────────────────────────────────────────────────────────── */
|
||||
.container {
|
||||
max-width: 640px;
|
||||
margin: 0 auto;
|
||||
padding: 1.25rem 1rem;
|
||||
}
|
||||
|
||||
/* ── Header ────────────────────────────────────────────────────────────────── */
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1.5rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
h1 { font-size: 1.4rem; font-weight: 700; }
|
||||
|
||||
.btn-signout {
|
||||
background: none;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--muted);
|
||||
padding: 0.4rem 0.9rem;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
transition: border-color 0.15s, color 0.15s;
|
||||
}
|
||||
.btn-signout:hover { border-color: #666; color: var(--text); }
|
||||
|
||||
/* ── Cards ─────────────────────────────────────────────────────────────────── */
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.07em;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
/* ── Form fields ───────────────────────────────────────────────────────────── */
|
||||
.field { margin-bottom: 1.25rem; }
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.45rem;
|
||||
color: var(--muted);
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
textarea {
|
||||
width: 100%;
|
||||
background: var(--surface2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
color: var(--text);
|
||||
padding: 0.75rem;
|
||||
font-size: 1rem;
|
||||
font-family: inherit;
|
||||
resize: vertical;
|
||||
line-height: 1.5;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
textarea:focus { outline: none; border-color: var(--primary); }
|
||||
|
||||
.char-count {
|
||||
text-align: right;
|
||||
color: var(--muted);
|
||||
font-size: 0.8rem;
|
||||
margin-top: 0.3rem;
|
||||
}
|
||||
|
||||
/* ── Duration picker ───────────────────────────────────────────────────────── */
|
||||
.duration-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
@media (min-width: 440px) {
|
||||
.duration-grid { grid-template-columns: repeat(4, 1fr); }
|
||||
}
|
||||
|
||||
.dur-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--surface2);
|
||||
border: 2px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 0.65rem 0.25rem;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
text-align: center;
|
||||
}
|
||||
.dur-option input[type=radio] { display: none; }
|
||||
.dur-option span { font-size: 0.95rem; font-weight: 500; }
|
||||
.dur-option:hover { border-color: #555; }
|
||||
.dur-option:has(input:checked) {
|
||||
border-color: var(--primary);
|
||||
background: #1e2d4a;
|
||||
color: #93c5fd;
|
||||
}
|
||||
|
||||
/* ── Action buttons ────────────────────────────────────────────────────────── */
|
||||
.action-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
@media (max-width: 360px) {
|
||||
.action-row { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 0.9rem 1rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
transition: background 0.15s;
|
||||
/* Minimum touch target */
|
||||
min-height: 48px;
|
||||
}
|
||||
|
||||
.btn-primary { background: var(--primary); color: #fff; }
|
||||
.btn-primary:hover { background: var(--primary-h); }
|
||||
.btn-primary:disabled { background: #374151; color: #6b7280; cursor: not-allowed; }
|
||||
|
||||
.btn-secondary {
|
||||
background: var(--surface2);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.btn-secondary:hover { background: var(--secondary-h); border-color: #555; }
|
||||
|
||||
/* ── Status bar ────────────────────────────────────────────────────────────── */
|
||||
.status-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem 1.25rem;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
background: var(--muted);
|
||||
transition: background 0.3s, box-shadow 0.3s;
|
||||
}
|
||||
.status-dot.active {
|
||||
background: var(--success);
|
||||
box-shadow: 0 0 7px var(--success);
|
||||
}
|
||||
|
||||
#status-text {
|
||||
font-size: 0.95rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
Reference in New Issue
Block a user