use std::sync::{Arc, Mutex}; use serde::{Deserialize, Serialize}; use crate::storage::{AppData, TimerSnapshot}; #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum TimerPhase { Work, ShortBreak, LongBreak, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TimerState { pub phase: TimerPhase, pub remaining_secs: u64, pub total_secs: u64, pub running: bool, pub session_count: u32, pub current_task_id: Option, } /// Wrapper held in Tauri managed state — contains the Arc so commands can clone it. pub struct TimerStateWrapper(pub Arc>); /// Wrapper for AppData — contains the Arc. pub struct AppDataWrapper { pub data: Arc>, } impl TimerState { pub fn new(work_duration_secs: u64) -> Self { Self { phase: TimerPhase::Work, remaining_secs: work_duration_secs, total_secs: work_duration_secs, running: false, session_count: 0, current_task_id: None, } } pub fn from_snapshot(snapshot: TimerSnapshot) -> Self { Self { phase: snapshot.phase, remaining_secs: snapshot.remaining_secs, total_secs: snapshot.total_secs, running: snapshot.running, session_count: snapshot.session_count, current_task_id: snapshot.current_task_id, } } pub fn snapshot(&self) -> TimerSnapshot { TimerSnapshot { phase: self.phase, remaining_secs: self.remaining_secs, total_secs: self.total_secs, running: self.running, session_count: self.session_count, current_task_id: self.current_task_id.clone(), } } }