diff options
| author | Solstice <solstice@local> | 2026-06-09 00:13:03 -0700 |
|---|---|---|
| committer | Solstice <solstice@local> | 2026-06-09 00:13:03 -0700 |
| commit | 72626524c4a1c7d6642bc170520913273acb1a5c (patch) | |
| tree | deeaa45248c6c80f373c2d956cc51e0a4dc7f2cf /src-tauri/src/state.rs | |
| parent | 8cf1686e9e9ed20a1c256ccf9e510f4293aa1cf3 (diff) | |
feat: backend timer logic and data persistence
Diffstat (limited to 'src-tauri/src/state.rs')
| -rw-r--r-- | src-tauri/src/state.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs new file mode 100644 index 0000000..9cd3698 --- /dev/null +++ b/src-tauri/src/state.rs @@ -0,0 +1,45 @@ +use std::path::PathBuf; +use std::sync::{Arc, Mutex}; +use serde::{Deserialize, Serialize}; +use crate::storage::AppData; + +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum TimerPhase { + Work, + ShortBreak, + LongBreak, +} + +#[derive(Debug, Clone, Serialize)] +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<String>, +} + +/// Wrapper held in Tauri managed state — contains the Arc so commands can clone it. +pub struct TimerStateWrapper(pub Arc<Mutex<TimerState>>); + +/// Wrapper for AppData — contains the Arc and the data directory path. +pub struct AppDataWrapper { + pub data: Arc<Mutex<AppData>>, + #[allow(dead_code)] + pub data_dir: PathBuf, +} + +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, + } + } +} |
