@@ -29,6 +29,7 @@ export class PomodoroTimer {
2929 this . sessionStartTime = null ; // When the current session was started
3030 this . currentSessionElapsedTime = 0 ; // Actual elapsed time for current session (in seconds)
3131 this . lastCompletedSessionTime = 0 ; // Time of the last completed session for undo functionality
32+ this . sessionCompletedButNotSaved = false ; // Flag to track if session completed but not saved yet
3233
3334 // Timer accuracy tracking (for background throttling fix)
3435 this . timerStartTime = null ; // When the timer was started (Date.now())
@@ -533,6 +534,7 @@ export class PomodoroTimer {
533534 if ( ! this . sessionStartTime ) {
534535 this . sessionStartTime = Date . now ( ) ;
535536 this . currentSessionElapsedTime = 0 ;
537+ this . sessionCompletedButNotSaved = false ; // Reset flag for new session
536538 }
537539
538540 // Initialize timer accuracy tracking
@@ -653,6 +655,7 @@ export class PomodoroTimer {
653655 // Reset session tracking
654656 this . sessionStartTime = null ;
655657 this . currentSessionElapsedTime = 0 ;
658+ this . sessionCompletedButNotSaved = false ; // Reset flag
656659
657660 // Reset timer accuracy tracking
658661 this . timerStartTime = null ;
@@ -681,18 +684,28 @@ export class PomodoroTimer {
681684 }
682685 this . stopSmartPauseCountdown ( ) ;
683686
687+ // Track if we need to save session data
688+ let shouldSaveSession = false ;
689+
684690 // Skip to next mode
685691 if ( this . currentMode === 'focus' ) {
686692 // Skip focus session - count as completed and go to break
687- this . completedPomodoros ++ ;
688- this . updateProgressDots ( ) ;
693+ if ( ! this . sessionCompletedButNotSaved ) {
694+ // If session wasn't completed yet (not in overtime), count it as completed
695+ this . completedPomodoros ++ ;
696+ this . updateProgressDots ( ) ;
689697
690- // Calculate elapsed time for skipped focus session (partial or full duration)
691- const actualElapsedTime = this . currentSessionElapsedTime || ( this . durations . focus - this . timeRemaining ) ;
692- this . totalFocusTime += actualElapsedTime ;
698+ // Calculate elapsed time for skipped focus session (partial or full duration)
699+ const actualElapsedTime = this . currentSessionElapsedTime || ( this . durations . focus - this . timeRemaining ) ;
700+ this . totalFocusTime += actualElapsedTime ;
693701
694- // Store the actual elapsed time for undo functionality
695- this . lastCompletedSessionTime = actualElapsedTime ;
702+ // Store the actual elapsed time for undo functionality
703+ this . lastCompletedSessionTime = actualElapsedTime ;
704+ }
705+
706+ // We need to save session data when skipping a focus session
707+ shouldSaveSession = true ;
708+ this . sessionCompletedButNotSaved = false ;
696709
697710 // Determine next mode
698711 if ( this . completedPomodoros % 4 === 0 ) {
@@ -713,6 +726,12 @@ export class PomodoroTimer {
713726 this . updateDisplay ( ) ;
714727 this . updateButtons ( ) ;
715728
729+ // Save session data if needed
730+ if ( shouldSaveSession ) {
731+ this . saveSessionData ( ) ;
732+ this . updateWeeklyStats ( ) ;
733+ }
734+
716735 // Show skip notification
717736 const messages = {
718737 focus : 'Focus session skipped. Time for a break! 😌' ,
@@ -799,6 +818,7 @@ export class PomodoroTimer {
799818 // Reset session tracking for next session
800819 this . sessionStartTime = null ;
801820 this . currentSessionElapsedTime = 0 ;
821+ this . sessionCompletedButNotSaved = false ; // Reset flag
802822
803823 // Reset timer accuracy tracking
804824 this . timerStartTime = null ;
@@ -890,11 +910,18 @@ export class PomodoroTimer {
890910 }
891911 this . currentTask = '' ;
892912 }
913+
914+ // Mark session as completed but not saved yet (will be saved when user skips)
915+ this . sessionCompletedButNotSaved = true ;
893916 }
894917
895- // Save session data
896- await this . saveSessionData ( ) ;
897- await this . updateWeeklyStats ( ) ;
918+ // For continuous sessions, don't save the session data here
919+ // It will be saved when the user skips the session
920+ if ( ! this . allowContinuousSessions ) {
921+ // Save session data only for traditional mode
922+ await this . saveSessionData ( ) ;
923+ await this . updateWeeklyStats ( ) ;
924+ }
898925
899926 // Show notification
900927 this . showNotification ( ) ;
@@ -1317,6 +1344,7 @@ export class PomodoroTimer {
13171344 this . sessionStartTime = null ;
13181345 this . currentSessionElapsedTime = 0 ;
13191346 this . lastCompletedSessionTime = 0 ;
1347+ this . sessionCompletedButNotSaved = false ; // Reset flag
13201348
13211349 // Reset timer accuracy tracking
13221350 this . timerStartTime = null ;
0 commit comments