@@ -30,6 +30,8 @@ export class PomodoroTimer {
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
3232 this . sessionCompletedButNotSaved = false ; // Flag to track if session completed but not saved yet
33+ this . maxSessionTime = 120 * 60 * 1000 ; // Default 2 hours in milliseconds
34+ this . maxSessionTimeReached = false ; // Flag to track if max session time was reached
3335
3436 // Timer accuracy tracking (for background throttling fix)
3537 this . timerStartTime = null ; // When the timer was started (Date.now())
@@ -667,6 +669,9 @@ export class PomodoroTimer {
667669 }
668670 }
669671
672+ // Check if max session time has been reached
673+ this . checkMaxSessionTime ( ) ;
674+
670675 this . updateDisplay ( ) ;
671676
672677 // Warning when less than 2 minutes remaining
@@ -696,6 +701,35 @@ export class PomodoroTimer {
696701 }
697702 }
698703
704+ checkMaxSessionTime ( ) {
705+ // Only check during focus sessions and if a session is active
706+ if ( this . currentMode !== 'focus' || ! this . sessionStartTime || this . maxSessionTimeReached ) {
707+ return ;
708+ }
709+
710+ const now = Date . now ( ) ;
711+ const sessionElapsed = now - this . sessionStartTime ;
712+
713+ // Check if session has exceeded max time
714+ if ( sessionElapsed >= this . maxSessionTime ) {
715+ this . maxSessionTimeReached = true ;
716+ this . pauseTimer ( ) ;
717+
718+ // Show notification
719+ const maxTimeInMinutes = Math . floor ( this . maxSessionTime / ( 60 * 1000 ) ) ;
720+ NotificationUtils . showNotificationPing (
721+ `Session automatically paused after ${ maxTimeInMinutes } minutes. Take a break! 🛑` ,
722+ 'warning'
723+ ) ;
724+
725+ // Show desktop notification if enabled
726+ NotificationUtils . showDesktopNotification (
727+ 'Session Time Limit Reached' ,
728+ `Your session has been automatically paused after ${ maxTimeInMinutes } minutes. Consider taking a break!`
729+ ) ;
730+ }
731+ }
732+
699733 pauseTimer ( ) {
700734 if ( this . isRunning ) {
701735 this . isRunning = false ;
@@ -748,6 +782,7 @@ export class PomodoroTimer {
748782 this . sessionStartTime = null ;
749783 this . currentSessionElapsedTime = 0 ;
750784 this . sessionCompletedButNotSaved = false ; // Reset flag
785+ this . maxSessionTimeReached = false ; // Reset max session time flag
751786
752787 // Reset timer accuracy tracking
753788 this . timerStartTime = null ;
@@ -1022,6 +1057,7 @@ export class PomodoroTimer {
10221057 this . sessionStartTime = null ;
10231058 this . currentSessionElapsedTime = 0 ;
10241059 this . sessionCompletedButNotSaved = false ; // Reset flag
1060+ this . maxSessionTimeReached = false ; // Reset max session time flag
10251061
10261062 // Reset timer accuracy tracking
10271063 this . timerStartTime = null ;
@@ -1617,6 +1653,7 @@ export class PomodoroTimer {
16171653 this . currentSessionElapsedTime = 0 ;
16181654 this . lastCompletedSessionTime = 0 ;
16191655 this . sessionCompletedButNotSaved = false ; // Reset flag
1656+ this . maxSessionTimeReached = false ; // Reset max session time flag
16201657
16211658 // Reset timer accuracy tracking
16221659 this . timerStartTime = null ;
@@ -2148,6 +2185,9 @@ export class PomodoroTimer {
21482185 }
21492186
21502187 this . totalSessions = settings . timer . total_sessions ;
2188+
2189+ // Update max session time (convert from minutes to milliseconds)
2190+ this . maxSessionTime = ( settings . timer . max_session_time || 120 ) * 60 * 1000 ;
21512191
21522192 // If timer is not running, update current time remaining
21532193 if ( ! this . isRunning ) {
@@ -2231,6 +2271,7 @@ export class PomodoroTimer {
22312271 this . sessionStartTime = null ;
22322272 this . currentSessionElapsedTime = 0 ;
22332273 this . lastCompletedSessionTime = 0 ;
2274+ this . maxSessionTimeReached = false ; // Reset max session time flag
22342275
22352276 // Reset timer accuracy tracking
22362277 this . timerStartTime = null ;
0 commit comments