diff --git a/public/overlay.css b/public/overlay.css deleted file mode 100644 index 79e76be..0000000 --- a/public/overlay.css +++ /dev/null @@ -1,12 +0,0 @@ -body { - background: transparent; - margin: 0; - padding: 0; -} - -#timer { - font-size: 16rem; - font-family: monospace; - color: white; - text-shadow: 2px 2px 4px black; -} diff --git a/src-tauri/src/server/routes.rs b/src-tauri/src/server/routes.rs index faf4b69..4bacd2d 100644 --- a/src-tauri/src/server/routes.rs +++ b/src-tauri/src/server/routes.rs @@ -1,13 +1,13 @@ use crate::app_state::AppState; use crate::countdown::commands::build_snapshot_dtos; use crate::countdown::events::AppEvent; -use axum::Json; use axum::extract::{Path, Query, State}; use axum::response::sse::KeepAlive; use axum::response::{ sse::{Event, Sse}, Html, }; +use axum::Json; use std::sync::Arc; use std::time::Duration; use tokio_stream::wrappers::BroadcastStream; @@ -22,13 +22,6 @@ pub async fn overlay_countdown( State(state): State>, Query(q): Query, ) -> Html { - let css_version = tokio::fs::metadata("public/overlay.css") - .await - .ok() - .and_then(|m| m.modified().ok()) - .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()) - .map(|d| d.as_secs()) - .unwrap_or(0); let config = state .overlay_configs .lock() @@ -46,7 +39,7 @@ pub async fn overlay_countdown( let mut env = minijinja::Environment::new(); env.add_template( "page", - include_str!("../../templates/overlay/countdown.html"), + include_str!("../../templates/overlay/countdown.html.j2"), ) .unwrap(); let html = env @@ -58,7 +51,6 @@ pub async fn overlay_countdown( icon => config.icon, text_color => config.text_color, bg_color => config.bg_color, - css_version => css_version, }) .unwrap(); Html(html) @@ -121,7 +113,10 @@ pub async fn list_icons() -> Json> { if let Ok(mut entries) = tokio::fs::read_dir("public/icons").await { while let Ok(Some(entry)) = entries.next_entry().await { let path = entry.path(); - if matches!(path.extension().and_then(|e| e.to_str()), Some("svg" | "png")) { + if matches!( + path.extension().and_then(|e| e.to_str()), + Some("svg" | "png") + ) { if let Some(filename) = path.file_name().and_then(|s| s.to_str()) { names.push(filename.to_string()); } diff --git a/src-tauri/templates/overlay/browsersource.html.j2 b/src-tauri/templates/overlay/browsersource.html.j2 new file mode 100644 index 0000000..61aad0d --- /dev/null +++ b/src-tauri/templates/overlay/browsersource.html.j2 @@ -0,0 +1,18 @@ + + + + + + {{ content }} + + + diff --git a/src-tauri/templates/overlay/countdown.html b/src-tauri/templates/overlay/countdown.html deleted file mode 100644 index 28a6847..0000000 --- a/src-tauri/templates/overlay/countdown.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - -
- {% if icon %}{% endif %} - {{ remaining }} -
- - - diff --git a/src-tauri/templates/overlay/countdown/countdown.html.j2 b/src-tauri/templates/overlay/countdown/countdown.html.j2 new file mode 100644 index 0000000..0baf701 --- /dev/null +++ b/src-tauri/templates/overlay/countdown/countdown.html.j2 @@ -0,0 +1,10 @@ +
+ {% for c in countdowns %} +
+ {% if c.icon %}{% endif %} + + {{ c.remaining }} + +
+ {% endfor %} +
diff --git a/src-tauri/templates/overlay/countdown/countdown.script.j2 b/src-tauri/templates/overlay/countdown/countdown.script.j2 new file mode 100644 index 0000000..81b7024 --- /dev/null +++ b/src-tauri/templates/overlay/countdown/countdown.script.j2 @@ -0,0 +1,14 @@ +const hideIdle = {{ hide_idle | lower }}; +const es = new EventSource('/sse/countdown/{{ id }}'); +es.addEventListener('tick', e => { + const {id, remaining} = JSON.parse(e.data); + document.getElementById('countdown-' + id).innerText = remaining; +}); +es.AddEventListener('state', e => { + const {id, state} = JSON.parse(e.data); + if (hideIdle) { + document.getElementById('countdown-' + id).style.display = state === 'idle' ? 'none' : ''; + } +} +es.addEventListener('reload', () => location.reload()); +es.onerror = () => setTimeout(() => location.reload(), 3000); diff --git a/src-tauri/templates/overlay/countdown/countdown.style.j2 b/src-tauri/templates/overlay/countdown/countdown.style.j2 new file mode 100644 index 0000000..2a4d6b1 --- /dev/null +++ b/src-tauri/templates/overlay/countdown/countdown.style.j2 @@ -0,0 +1,27 @@ +.countdown-list.vertical { + flex-direction: column; +} + +.countdown-list.horizontal { + flex-direction: row; +} + +.countdown-item { + display: flex; + align-items: center; + justify-content: center; + height: 100vh; +} + +.countdown-item.hidden { + display: none; +} + +#timer-{{ id }} { + font-size: {{ font_size }}rem; + font-family: monospace; + color: {{ text_color }}; + text-shadow: 2px 2px 4px black; +} + +#icon { width: { icon_size }; height: { icon_size }; vertical-align: middle; margin-right: 0.5rem; }