@@ -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 )
@@ -649,17 +660,20 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
649660 }
650661 }
651662
663+ // Update state with a lock
652664 app .mu .Lock ()
653665 app .previousBlockedPRs = currentBlocked
654666 app .blockedPRTimes = newBlockedTimes
655667 // Update the PR lists with FirstBlockedAt times
656668 app .incoming = incoming
657669 app .outgoing = outgoing
670+ menuInitialized := app .menuInitialized
658671 app .mu .Unlock ()
659672
660- // Update tray title and menu when called from main.go (not from github.go)
661- // This ensures party popper shows for newly blocked PRs
662- if app .menuInitialized {
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" )
663677 app .setTrayTitle ()
664678 app .updateMenu (ctx )
665679 }
0 commit comments