@@ -110,7 +110,7 @@ export class PomodoroTimer {
110110 // Generate initial progress dots
111111 this . generateProgressDots ( ) ;
112112 this . updateDisplay ( ) ;
113- this . updateProgressDots ( ) ;
113+ await this . updateProgressDots ( ) ;
114114 this . updateStopUndoButton ( ) ; // Initialize stop/undo button state
115115 this . updateSkipIcon ( ) ; // Initialize skip button icon
116116 this . updateSmartIndicator ( ) ; // Initialize smart pause indicator
@@ -190,6 +190,42 @@ export class PomodoroTimer {
190190
191191 // Start midnight monitoring for daily reset
192192 this . startMidnightMonitoring ( ) ;
193+
194+ // Setup event listeners for session synchronization
195+ this . setupSessionEventListeners ( ) ;
196+ }
197+
198+ setupSessionEventListeners ( ) {
199+ // Listen for session changes from SessionManager to keep dots synchronized
200+ window . addEventListener ( 'sessionAdded' , async ( event ) => {
201+ const { date } = event . detail ;
202+ const today = new Date ( ) . toDateString ( ) ;
203+
204+ // Only update dots if the session was added for today
205+ if ( date === today ) {
206+ await this . updateProgressDots ( ) ;
207+ }
208+ } ) ;
209+
210+ window . addEventListener ( 'sessionDeleted' , async ( event ) => {
211+ const { date } = event . detail ;
212+ const today = new Date ( ) . toDateString ( ) ;
213+
214+ // Only update dots if the session was deleted from today
215+ if ( date === today ) {
216+ await this . updateProgressDots ( ) ;
217+ }
218+ } ) ;
219+
220+ window . addEventListener ( 'sessionUpdated' , async ( event ) => {
221+ const { date } = event . detail ;
222+ const today = new Date ( ) . toDateString ( ) ;
223+
224+ // Only update dots if the session was updated for today
225+ if ( date === today ) {
226+ await this . updateProgressDots ( ) ;
227+ }
228+ } ) ;
193229 }
194230
195231 setupEventListeners ( ) {
@@ -1020,7 +1056,7 @@ export class PomodoroTimer {
10201056 if ( this . currentMode === 'focus' ) {
10211057 if ( ! this . sessionCompletedButNotSaved ) {
10221058 this . completedPomodoros ++ ;
1023- this . updateProgressDots ( ) ;
1059+ await this . updateProgressDots ( ) ;
10241060 const actualElapsedTime = this . currentSessionElapsedTime || ( this . durations . focus - this . timeRemaining ) ;
10251061 this . totalFocusTime += actualElapsedTime ;
10261062 this . lastCompletedSessionTime = actualElapsedTime ;
@@ -1113,7 +1149,7 @@ export class PomodoroTimer {
11131149
11141150 if ( this . currentMode === 'focus' ) {
11151151 this . completedPomodoros ++ ;
1116- this . updateProgressDots ( ) ;
1152+ await this . updateProgressDots ( ) ;
11171153
11181154 // Calculate actual elapsed time for focus sessions
11191155 const actualElapsedTime = this . currentSessionElapsedTime || ( this . durations . focus - this . timeRemaining ) ;
@@ -1273,7 +1309,7 @@ export class PomodoroTimer {
12731309 // Update completed sessions count for focus sessions
12741310 if ( this . currentMode === 'focus' ) {
12751311 this . completedPomodoros ++ ;
1276- this . updateProgressDots ( ) ;
1312+ await this . updateProgressDots ( ) ;
12771313
12781314 // Calculate actual elapsed time for focus sessions
12791315 const actualElapsedTime = this . currentSessionElapsedTime || this . durations . focus ;
@@ -1798,7 +1834,7 @@ export class PomodoroTimer {
17981834
17991835 // Update all displays
18001836 this . updateDisplay ( ) ;
1801- this . updateProgressDots ( ) ;
1837+ await this . updateProgressDots ( ) ;
18021838 this . updateButtons ( ) ;
18031839 await this . saveSessionData ( ) ;
18041840 this . updateTrayIcon ( ) ;
@@ -1826,7 +1862,7 @@ export class PomodoroTimer {
18261862 }
18271863
18281864 // Progress dots update
1829- updateProgressDots ( ) {
1865+ async updateProgressDots ( ) {
18301866 const dots = this . progressDots . querySelectorAll ( '.dot' ) ;
18311867
18321868 // Remove any existing overflow indicator
@@ -1835,20 +1871,23 @@ export class PomodoroTimer {
18351871 existingOverflow . remove ( ) ;
18361872 }
18371873
1838- // Update each dot based on completed pomodoros and current session
1874+ // Get actual completed sessions count from SessionManager
1875+ const actualCompletedSessions = await this . getCompletedSessionsToday ( ) ;
1876+
1877+ // Update each dot based on actual completed sessions and current session
18391878 dots . forEach ( ( dot , index ) => {
18401879 // Remove all classes first
18411880 dot . classList . remove ( 'completed' , 'current' ) ;
18421881
1843- if ( index < this . completedPomodoros ) {
1882+ if ( index < actualCompletedSessions ) {
18441883 dot . classList . add ( 'completed' ) ;
1845- } else if ( index === this . completedPomodoros && this . currentMode === 'focus' ) {
1884+ } else if ( index === actualCompletedSessions && this . currentMode === 'focus' ) {
18461885 dot . classList . add ( 'current' ) ;
18471886 }
18481887 } ) ;
18491888
1850- if ( this . completedPomodoros > this . totalSessions ) {
1851- const overflowCount = this . completedPomodoros - this . totalSessions ;
1889+ if ( actualCompletedSessions > this . totalSessions ) {
1890+ const overflowCount = actualCompletedSessions - this . totalSessions ;
18521891 const overflowIndicator = document . createElement ( 'div' ) ;
18531892 overflowIndicator . className = 'overflow-indicator' ;
18541893 overflowIndicator . textContent = `+${ overflowCount } ` ;
@@ -2103,6 +2142,21 @@ export class PomodoroTimer {
21032142 }
21042143 }
21052144
2145+ async getCompletedSessionsToday ( ) {
2146+ if ( ! window . sessionManager ) {
2147+ return this . completedPomodoros ; // Fallback to internal counter
2148+ }
2149+
2150+ try {
2151+ const today = new Date ( ) ; // Pass Date object instead of string
2152+ const todaySessions = await window . sessionManager . getSessionsForDate ( today ) ;
2153+ return todaySessions ? todaySessions . length : 0 ;
2154+ } catch ( error ) {
2155+ console . error ( 'Failed to get completed sessions from SessionManager:' , error ) ;
2156+ return this . completedPomodoros ; // Fallback to internal counter
2157+ }
2158+ }
2159+
21062160 async saveCompletedFocusSession ( ) {
21072161 if ( ! window . sessionManager ) {
21082162 console . log ( 'SessionManager not available, skipping individual session save' ) ;
@@ -2196,14 +2250,14 @@ export class PomodoroTimer {
21962250 this . completedPomodoros = data . completed_pomodoros || 0 ;
21972251 this . totalFocusTime = data . total_focus_time || 0 ;
21982252 this . currentSession = data . current_session || 1 ;
2199- this . updateProgressDots ( ) ;
2253+ await this . updateProgressDots ( ) ;
22002254 console . log ( '📊 Loaded existing session data for today' ) ;
22012255 } else {
22022256 // Reset to default values for new day, no data, or forced reset
22032257 this . completedPomodoros = 0 ;
22042258 this . totalFocusTime = 0 ;
22052259 this . currentSession = 1 ;
2206- this . updateProgressDots ( ) ;
2260+ await this . updateProgressDots ( ) ;
22072261 console . log ( '🌅 Reset session data for new day or forced reset' ) ;
22082262 }
22092263 } catch ( error ) {
@@ -2217,22 +2271,22 @@ export class PomodoroTimer {
22172271 this . completedPomodoros = data . completedPomodoros || 0 ;
22182272 this . totalFocusTime = data . totalFocusTime || 0 ;
22192273 this . currentSession = data . currentSession || 1 ;
2220- this . updateProgressDots ( ) ;
2274+ await this . updateProgressDots ( ) ;
22212275 console . log ( '📊 Loaded existing session data from localStorage' ) ;
22222276 } else {
22232277 // Reset to default values for new day, no data, or forced reset
22242278 this . completedPomodoros = 0 ;
22252279 this . totalFocusTime = 0 ;
22262280 this . currentSession = 1 ;
2227- this . updateProgressDots ( ) ;
2281+ await this . updateProgressDots ( ) ;
22282282 console . log ( '🌅 Reset session data from localStorage for new day or forced reset' ) ;
22292283 }
22302284 } else {
22312285 // No saved data at all, reset to defaults
22322286 this . completedPomodoros = 0 ;
22332287 this . totalFocusTime = 0 ;
22342288 this . currentSession = 1 ;
2235- this . updateProgressDots ( ) ;
2289+ await this . updateProgressDots ( ) ;
22362290 console . log ( '🌅 No saved data found, using defaults' ) ;
22372291 }
22382292 }
@@ -2383,7 +2437,7 @@ export class PomodoroTimer {
23832437
23842438 // Regenerate progress dots when total sessions change
23852439 this . generateProgressDots ( ) ;
2386- this . updateProgressDots ( ) ;
2440+ await this . updateProgressDots ( ) ;
23872441
23882442 // Update notification preferences
23892443 this . enableDesktopNotifications = settings . notifications . desktop_notifications ;
0 commit comments