Files
Owlerlay/src-tauri/src/app_state.rs
s0wlz (Matthias Puchstein) d0857d7028 [bugfix] fix countdown snapshot time calculations and unify tokio instants
- switch ClockAnchor to tokio::time::Instant for consistent async timing
- remove incorrect epoch-ms math in Countdown model and expose instant getters
- update CountdownService snapshot to use remaining_at(now) plus start/target instants
- add missing core extern declaration in lib.rs
2026-02-26 16:24:35 +01:00

38 lines
1002 B
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 {
instant.duration_since(self.boot_instant).as_millis() + self.boot_epoch_ms
}
}
//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::default(),
}
}
}