@@ -568,15 +568,26 @@ func (app *App) notifyWithSound(ctx context.Context, pr PR, isIncoming bool, pla
568568
569569// checkForNewlyBlockedPRs sends notifications for blocked PRs.
570570func (app * App ) checkForNewlyBlockedPRs (ctx context.Context ) {
571- app .mu .RLock ()
572- incoming := app .incoming
573- outgoing := app .outgoing
571+ // Check for context cancellation early
572+ select {
573+ case <- ctx .Done ():
574+ log .Print ("[BLOCKED] Context cancelled, skipping newly blocked PR check" )
575+ return
576+ default :
577+ }
578+
579+ app .mu .Lock ()
580+ // Make deep copies to work with while holding the lock
581+ incoming := make ([]PR , len (app .incoming ))
582+ copy (incoming , app .incoming )
583+ outgoing := make ([]PR , len (app .outgoing ))
584+ copy (outgoing , app .outgoing )
574585 previousBlocked := app .previousBlockedPRs
575586 blockedTimes := app .blockedPRTimes
576587 autoBrowserEnabled := app .enableAutoBrowser
577588 startTime := app .startTime
578589 hideStaleIncoming := app .hideStaleIncoming
579- app .mu .RUnlock ()
590+ app .mu .Unlock ()
580591
581592 currentBlocked := make (map [string ]bool )
582593 newBlockedTimes := make (map [string ]time.Time )
@@ -597,6 +608,8 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
597608 // Newly blocked PR
598609 newBlockedTimes [incoming [i ].URL ] = now
599610 incoming [i ].FirstBlockedAt = now
611+ log .Printf ("[BLOCKED] Setting FirstBlockedAt for incoming PR: %s #%d at %v" ,
612+ incoming [i ].Repository , incoming [i ].Number , now )
600613
601614 // Skip sound and auto-open for stale PRs when hideStaleIncoming is enabled
602615 isStale := incoming [i ].UpdatedAt .Before (staleThreshold )
@@ -625,6 +638,8 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
625638 // Newly blocked PR
626639 newBlockedTimes [outgoing [i ].URL ] = now
627640 outgoing [i ].FirstBlockedAt = now
641+ log .Printf ("[BLOCKED] Setting FirstBlockedAt for outgoing PR: %s #%d at %v" ,
642+ outgoing [i ].Repository , outgoing [i ].Number , now )
628643
629644 // Skip sound and auto-open for stale PRs when hideStaleIncoming is enabled
630645 isStale := outgoing [i ].UpdatedAt .Before (staleThreshold )
@@ -645,11 +660,21 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
645660 }
646661 }
647662
663+ // Update state with a lock
648664 app .mu .Lock ()
649665 app .previousBlockedPRs = currentBlocked
650666 app .blockedPRTimes = newBlockedTimes
651667 // Update the PR lists with FirstBlockedAt times
652668 app .incoming = incoming
653669 app .outgoing = outgoing
670+ menuInitialized := app .menuInitialized
654671 app .mu .Unlock ()
672+
673+ // Update UI after releasing the lock
674+ // Only update if there are newly blocked PRs
675+ if menuInitialized && len (currentBlocked ) > len (previousBlocked ) {
676+ log .Print ("[BLOCKED] Updating UI for newly blocked PRs" )
677+ app .setTrayTitle ()
678+ app .updateMenu (ctx )
679+ }
655680}
0 commit comments