Files
Owlerlay/src-tauri/src/app_state.rs
s0wlz (Matthias Puchstein) 2a32025382 feat(countdown): add multi-countdown management with ID-based commands
- refactor backend service from single countdown to HashMap storage with generated IDs
- add create/list/delete commands and make start/pause/resume/reset/snapshot ID-aware
- introduce validation and new countdown errors (id/label/duration/state/action/max limit)
- update frontend countdown snapshot typing/mapping to match backend DTO changes
- add shared base Pico CSS overrides and import base styles
2026-02-27 15:57:17 +01:00

43 lines
1.2 KiB
Rust

use crate::countdown::service::CountdownService;
#[derive(Clone, Debug)]
pub struct ClockAnchor {
pub boot_instant: tokio::time::Instant,
pub boot_epoch_ms: u128,
}
impl ClockAnchor {
pub fn new() -> Self {
Self {
boot_instant: tokio::time::Instant::now(),
boot_epoch_ms: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis(),
}
}
pub fn instant_to_epoch_ms(&self, instant: tokio::time::Instant) -> u128 {
if let Some(delta) = instant.checked_duration_since(self.boot_instant) {
self.boot_epoch_ms + delta.as_millis()
} else {
let delta = self.boot_instant.duration_since(instant).as_millis();
self.boot_epoch_ms.saturating_sub(delta)
}
}
}
//TODO: implement the handling of multiple countdowns
#[derive(Debug)]
pub struct AppState {
pub clock_anchor: ClockAnchor,
pub countdown_service: CountdownService,
}
impl AppState {
pub fn new() -> Self {
Self {
clock_anchor: ClockAnchor::new(),
countdown_service: CountdownService::new(),
}
}
}