summaryrefslogtreecommitdiff
path: root/src-tauri/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src/state.rs')
-rw-r--r--src-tauri/src/state.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs
index 8f3d52b..c6b4d03 100644
--- a/src-tauri/src/state.rs
+++ b/src-tauri/src/state.rs
@@ -1,6 +1,6 @@
use std::sync::{Arc, Mutex};
use serde::{Deserialize, Serialize};
-use crate::storage::AppData;
+use crate::storage::{AppData, TimerSnapshot};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
@@ -10,7 +10,7 @@ pub enum TimerPhase {
LongBreak,
}
-#[derive(Debug, Clone, Serialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimerState {
pub phase: TimerPhase,
pub remaining_secs: u64,
@@ -39,4 +39,26 @@ impl TimerState {
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(),
+ }
+ }
}