This commit is contained in:
Aaro Varis
2026-02-19 10:40:10 +02:00
parent dbc246bf95
commit c317ff287c
16 changed files with 1923 additions and 114 deletions

5
.gitignore vendored
View File

@@ -1,4 +1,7 @@
# Created by venv; see https://docs.python.org/3/library/venv.html
bin/
include/
lib/
lib/
# Node.js
webapp/node_modules/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,113 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alarm Clock</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
}
.container {
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 40px;
text-align: center;
max-width: 400px;
width: 90%;
}
h1 { margin-bottom: 30px; font-size: 1.8rem; }
.time { font-size: 3rem; font-weight: 300; margin-bottom: 20px; }
.alarm-time { font-size: 1.5rem; color: #4fc3f7; margin-bottom: 30px; }
.alarm-active { color: #ff5252; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.controls { display: flex; flex-direction: column; gap: 15px; }
.time-input { display: flex; justify-content: center; gap: 10px; align-items: center; }
input[type="number"] {
width: 60px; padding: 10px; font-size: 1.2rem;
border: none; border-radius: 8px; text-align: center;
background: rgba(255,255,255,0.2); color: #fff;
}
input[type="number"]:focus { outline: 2px solid #4fc3f7; }
button {
padding: 12px 24px; font-size: 1rem; border: none;
border-radius: 8px; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: #4fc3f7; color: #1a1a2e; }
.btn-primary:hover { background: #29b6f6; }
.btn-danger { background: #ff5252; color: #fff; }
.btn-danger:hover { background: #ff1744; }
.status { margin-top: 20px; font-size: 0.9rem; color: #aaa; }
</style>
</head>
<body>
<div class="container">
<h1>Alarm Clock</h1>
<div class="time" id="currentTime">--:--:--</div>
<div class="alarm-time" id="alarmTime">Alarm: --:--</div>
<div class="controls">
<div class="time-input">
<input type="number" id="hour" min="0" max="23" placeholder="HH">
<span>:</span>
<input type="number" id="minute" min="0" max="59" placeholder="MM">
</div>
<button class="btn-primary" onclick="setAlarm()">Set Alarm</button>
<button class="btn-danger" id="dismissBtn" onclick="dismissAlarm()" style="display:none">Dismiss Alarm</button>
</div>
<div class="status" id="status"></div>
</div>
<script>
async function fetchStatus() {
try {
const res = await fetch('/api/status');
const data = await res.json();
document.getElementById('currentTime').textContent = data.current_time;
const alarmEl = document.getElementById('alarmTime');
alarmEl.textContent = 'Alarm: ' + (data.alarm_time || '--:--');
alarmEl.classList.toggle('alarm-active', data.alarm_active);
document.getElementById('dismissBtn').style.display = data.alarm_active ? 'block' : 'none';
} catch (e) {
document.getElementById('status').textContent = 'Connection error';
}
}
async function setAlarm() {
const hour = parseInt(document.getElementById('hour').value);
const minute = parseInt(document.getElementById('minute').value);
if (isNaN(hour) || isNaN(minute)) {
document.getElementById('status').textContent = 'Please enter valid hour and minute';
return;
}
try {
const res = await fetch('/api/alarm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ hour, minute })
});
const data = await res.json();
document.getElementById('status').textContent = data.success ? 'Alarm set!' : data.error;
fetchStatus();
} catch (e) {
document.getElementById('status').textContent = 'Failed to set alarm';
}
}
async function dismissAlarm() {
try {
await fetch('/api/dismiss', { method: 'POST' });
fetchStatus();
} catch (e) {
document.getElementById('status').textContent = 'Failed to dismiss alarm';
}
}
fetchStatus();
setInterval(fetchStatus, 1000);
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Alarm Clock</title>
<script type="module" crossorigin src="/assets/index-Bn0F14kH.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-Daco8gAy.css">
</head>
<body>
<div id="root"></div>
</body>

View File

@@ -17,6 +17,27 @@ def create_app(alarm_clock=None):
# Store alarm_clock reference
app.alarm_clock = alarm_clock
# API endpoints
@app.route('/api/status', methods=['GET'])
def get_status():
"""Get current alarm clock status."""
now = datetime.now(ZoneInfo(CITY.timezone))
response = {
'current_time': now.strftime('%H:%M:%S'),
'timezone': CITY.timezone,
'alarm_active': False,
'alarm_time': None,
'config_mode': 'normal'
}
if app.alarm_clock:
response['alarm_active'] = app.alarm_clock.alarm_active
response['alarm_time'] = app.alarm_clock.alarm_time.strftime('%H:%M')
response['config_mode'] = app.alarm_clock.config_mode
return jsonify(response)
# Serve static files from public folder
@app.route('/')
def serve_index():
@@ -24,6 +45,10 @@ def create_app(alarm_clock=None):
@app.route('/<path:filename>')
def serve_static(filename):
# Try to serve the file, fallback to index.html for SPA routing
file_path = path.join(public_folder, filename)
if path.isfile(file_path):
return send_from_directory(public_folder, filename)
return send_from_directory(public_folder, 'index.html')
return app

12
webapp/index.html Normal file
View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Alarm Clock</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

25
webapp/package.json Normal file
View File

@@ -0,0 +1,25 @@
{
"name": "alarm-clock-webapp",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15",
"typescript": "^5.6.3",
"vite": "^5.4.11"
}
}

1613
webapp/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

6
webapp/postcss.config.js Normal file
View File

@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

124
webapp/src/App.tsx Normal file
View File

@@ -0,0 +1,124 @@
import { useState, useEffect } from 'react'
interface Status {
current_time: string
timezone: string
alarm_active: boolean
alarm_time: string | null
config_mode: string
}
function App() {
const [status, setStatus] = useState<Status | null>(null)
const [hour, setHour] = useState('')
const [minute, setMinute] = useState('')
const [message, setMessage] = useState('')
const fetchStatus = async () => {
try {
const res = await fetch('/api/status')
const data = await res.json()
setStatus(data)
} catch {
setMessage('Connection error')
}
}
useEffect(() => {
fetchStatus()
const interval = setInterval(fetchStatus, 1000)
return () => clearInterval(interval)
}, [])
const setAlarm = async () => {
const h = parseInt(hour)
const m = parseInt(minute)
if (isNaN(h) || isNaN(m)) {
setMessage('Please enter valid hour and minute')
return
}
try {
const res = await fetch('/api/alarm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ hour: h, minute: m })
})
const data = await res.json()
setMessage(data.success ? 'Alarm set!' : data.error)
fetchStatus()
} catch {
setMessage('Failed to set alarm')
}
}
const dismissAlarm = async () => {
try {
await fetch('/api/dismiss', { method: 'POST' })
fetchStatus()
} catch {
setMessage('Failed to dismiss alarm')
}
}
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 to-slate-800 flex items-center justify-center p-4">
<div className="bg-white/10 backdrop-blur-lg rounded-3xl p-8 w-full max-w-md text-center shadow-2xl">
<h1 className="text-3xl font-bold text-white mb-8">Alarm Clock</h1>
<div className="text-6xl font-light text-white mb-4 font-mono">
{status?.current_time || '--:--:--'}
</div>
<div className={`text-2xl mb-8 ${status?.alarm_active ? 'text-red-400 animate-pulse' : 'text-cyan-400'}`}>
Alarm: {status?.alarm_time || '--:--'}
</div>
<div className="space-y-4">
<div className="flex justify-center items-center gap-3">
<input
type="number"
min={0}
max={23}
placeholder="HH"
value={hour}
onChange={(e) => setHour(e.target.value)}
className="w-20 px-4 py-3 text-xl text-center bg-white/20 text-white rounded-xl border-none outline-none focus:ring-2 focus:ring-cyan-400 placeholder-white/50"
/>
<span className="text-white text-2xl">:</span>
<input
type="number"
min={0}
max={59}
placeholder="MM"
value={minute}
onChange={(e) => setMinute(e.target.value)}
className="w-20 px-4 py-3 text-xl text-center bg-white/20 text-white rounded-xl border-none outline-none focus:ring-2 focus:ring-cyan-400 placeholder-white/50"
/>
</div>
<button
onClick={setAlarm}
className="w-full py-3 px-6 bg-cyan-500 hover:bg-cyan-400 text-slate-900 font-semibold rounded-xl transition-colors"
>
Set Alarm
</button>
{status?.alarm_active && (
<button
onClick={dismissAlarm}
className="w-full py-3 px-6 bg-red-500 hover:bg-red-400 text-white font-semibold rounded-xl transition-colors"
>
Dismiss Alarm
</button>
)}
</div>
{message && (
<div className="mt-6 text-sm text-gray-400">{message}</div>
)}
</div>
</div>
)
}
export default App

3
webapp/src/index.css Normal file
View File

@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

10
webapp/src/main.tsx Normal file
View File

@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

1
webapp/src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

11
webapp/tailwind.config.js Normal file
View File

@@ -0,0 +1,11 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}

20
webapp/tsconfig.json Normal file
View File

@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}

15
webapp/vite.config.ts Normal file
View File

@@ -0,0 +1,15 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
build: {
outDir: '../public',
emptyOutDir: true,
},
server: {
proxy: {
'/api': 'http://localhost:5000'
}
}
})