per-source polling, initial client state, webhook, preview, client tracking
- per-source poll intervals: spawn task per source with own interval,
manager re-checks sources every 30s for add/remove
- initial screen update on TCP connect: send layout + widget states
- client tracking: ClientRegistry port, GET /api/clients, dashboard list
- webhook adapter: POST /api/webhook/{source_id} feeds data into projection
- widget preview: GET /api/widgets/{id}/preview returns current state
- serve SPA from Axum: ServeDir + index.html fallback via KFRAME_SPA_DIR
- layout builder delete confirmation with AlertDialog
- form validation: required fields disable save button
- guide page at /guide
- fix architecture: ClientDto to api-types, ClientRegistry + WidgetStateReader
ports in domain, DataProjection has internal Mutex, no adapter cross-deps
- ESP32: full screen clear on layout change (stale pixel fix)
This commit is contained in:
@@ -1,43 +1,72 @@
|
||||
mod routes;
|
||||
|
||||
use axum::Router;
|
||||
use domain::{ConfigRepository, EventPublisher};
|
||||
use domain::{BroadcastPort, ClientRegistry, ConfigRepository, EventPublisher, WidgetStateReader};
|
||||
use std::sync::Arc;
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tower_http::services::{ServeDir, ServeFile};
|
||||
|
||||
pub struct AppState<C, E> {
|
||||
pub struct AppState<C, E, W, B, R> {
|
||||
pub config: Arc<C>,
|
||||
pub events: Arc<E>,
|
||||
pub widget_states: Arc<W>,
|
||||
pub broadcaster: Arc<B>,
|
||||
pub clients: Arc<R>,
|
||||
pub spa_dir: Option<String>,
|
||||
}
|
||||
|
||||
impl<C, E> Clone for AppState<C, E> {
|
||||
impl<C, E, W, B, R> Clone for AppState<C, E, W, B, R> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
config: self.config.clone(),
|
||||
events: self.events.clone(),
|
||||
widget_states: self.widget_states.clone(),
|
||||
broadcaster: self.broadcaster.clone(),
|
||||
clients: self.clients.clone(),
|
||||
spa_dir: self.spa_dir.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn router<C, E>(state: AppState<C, E>) -> Router
|
||||
pub fn router<C, E, W, B, R>(state: AppState<C, E, W, B, R>) -> Router
|
||||
where
|
||||
C: ConfigRepository + Send + Sync + 'static,
|
||||
C::Error: std::fmt::Debug + Send,
|
||||
E: EventPublisher + Send + Sync + 'static,
|
||||
E::Error: std::fmt::Debug + Send,
|
||||
W: WidgetStateReader + Send + Sync + 'static,
|
||||
B: BroadcastPort + Send + Sync + 'static,
|
||||
B::Error: std::fmt::Debug + Send,
|
||||
R: ClientRegistry + Send + Sync + 'static,
|
||||
{
|
||||
Router::new()
|
||||
let spa_dir = state.spa_dir.clone();
|
||||
|
||||
let app = Router::new()
|
||||
.nest("/api", routes::api_routes())
|
||||
.layer(CorsLayer::permissive())
|
||||
.with_state(state)
|
||||
.with_state(state);
|
||||
|
||||
if let Some(dir) = spa_dir {
|
||||
let index = format!("{dir}/index.html");
|
||||
app.fallback_service(ServeDir::new(&dir).fallback(ServeFile::new(index)))
|
||||
} else {
|
||||
app
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn serve<C, E>(addr: &str, state: AppState<C, E>) -> Result<(), std::io::Error>
|
||||
pub async fn serve<C, E, W, B, R>(
|
||||
addr: &str,
|
||||
state: AppState<C, E, W, B, R>,
|
||||
) -> Result<(), std::io::Error>
|
||||
where
|
||||
C: ConfigRepository + Send + Sync + 'static,
|
||||
C::Error: std::fmt::Debug + Send,
|
||||
E: EventPublisher + Send + Sync + 'static,
|
||||
E::Error: std::fmt::Debug + Send,
|
||||
W: WidgetStateReader + Send + Sync + 'static,
|
||||
B: BroadcastPort + Send + Sync + 'static,
|
||||
B::Error: std::fmt::Debug + Send,
|
||||
R: ClientRegistry + Send + Sync + 'static,
|
||||
{
|
||||
let app = router(state);
|
||||
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||
|
||||
Reference in New Issue
Block a user