Skip to content

Commit 8a60b6d

Browse files
committed
fix: reset Pomodoro session data for new day and update theme loader formatting
1 parent cd7f887 commit 8a60b6d

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth",
4343
tauri-plugin-aptabase = "1.0.0"
4444
serde = { version = "1", features = ["derive"], default-features = false }
4545
serde_json = { version = "1", default-features = false }
46-
chrono = { version = "0.4", features = ["serde"], default-features = false }
46+
chrono = { version = "0.4", features = ["serde", "clock"], default-features = false }
4747
dotenv = "0.15"
4848
base64 = "0.21"
4949

src-tauri/src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,26 @@ async fn load_session_data(app: AppHandle) -> Result<Option<PomodoroSession>, St
416416
}
417417

418418
let content =
419-
fs::read_to_string(file_path).map_err(|e| format!("Failed to read session file: {}", e))?;
420-
let session: PomodoroSession =
419+
fs::read_to_string(&file_path).map_err(|e| format!("Failed to read session file: {}", e))?;
420+
let mut session: PomodoroSession =
421421
serde_json::from_str(&content).map_err(|e| format!("Failed to parse session: {}", e))?;
422422

423+
// Get today's date string
424+
let today = chrono::Local::now().format("%a %b %d %Y").to_string();
425+
426+
// If the saved session is not from today, reset the counters but keep the date updated
427+
if session.date != today {
428+
session.completed_pomodoros = 0;
429+
session.total_focus_time = 0;
430+
session.current_session = 1;
431+
session.date = today;
432+
433+
// Save the reset session back to file
434+
let json = serde_json::to_string_pretty(&session)
435+
.map_err(|e| format!("Failed to serialize reset session: {}", e))?;
436+
fs::write(file_path, json).map_err(|e| format!("Failed to write reset session file: {}", e))?;
437+
}
438+
423439
Ok(Some(session))
424440
}
425441

src/core/pomodoro-timer.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,25 +1933,48 @@ export class PomodoroTimer {
19331933
}
19341934

19351935
async loadSessionData() {
1936+
const today = new Date().toDateString();
1937+
19361938
try {
19371939
const data = await invoke('load_session_data');
1938-
if (data && data.date === new Date().toDateString()) {
1940+
if (data && data.date === today) {
1941+
// Load today's session data
19391942
this.completedPomodoros = data.completed_pomodoros || 0;
19401943
this.totalFocusTime = data.total_focus_time || 0;
19411944
this.currentSession = data.current_session || 1;
19421945
this.updateProgressDots();
1946+
} else {
1947+
// Reset to default values for new day or no data
1948+
this.completedPomodoros = 0;
1949+
this.totalFocusTime = 0;
1950+
this.currentSession = 1;
1951+
this.updateProgressDots();
19431952
}
19441953
} catch (error) {
19451954
console.error('Failed to load session data from Tauri, using localStorage:', error);
19461955
const saved = localStorage.getItem('pomodoro-session');
1956+
19471957
if (saved) {
19481958
const data = JSON.parse(saved);
1949-
if (data.date === new Date().toDateString()) {
1959+
if (data.date === today) {
1960+
// Load today's session data from localStorage
19501961
this.completedPomodoros = data.completedPomodoros || 0;
19511962
this.totalFocusTime = data.totalFocusTime || 0;
19521963
this.currentSession = data.currentSession || 1;
19531964
this.updateProgressDots();
1965+
} else {
1966+
// Reset to default values for new day or no data
1967+
this.completedPomodoros = 0;
1968+
this.totalFocusTime = 0;
1969+
this.currentSession = 1;
1970+
this.updateProgressDots();
19541971
}
1972+
} else {
1973+
// No saved data at all, reset to defaults
1974+
this.completedPomodoros = 0;
1975+
this.totalFocusTime = 0;
1976+
this.currentSession = 1;
1977+
this.updateProgressDots();
19551978
}
19561979
}
19571980
}

src/utils/theme-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ThemeLoader {
3939
// that gets updated by the build process or manually maintained
4040

4141
// This could be enhanced to use a build-time script that generates this list
42-
const knownThemes = [
42+
const knownThemes = [
4343
'espresso.css',
4444
'pipboy.css',
4545
'pommodore64.css'

0 commit comments

Comments
 (0)