Skip to content

Commit 9a48965

Browse files
committed
fix menubar incoming/outgoing race condition
1 parent 8db7f15 commit 9a48965

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

cmd/goose/github.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,13 @@ func (app *App) fetchTurnDataAsync(ctx context.Context, issues []*github.Issue,
634634
}
635635

636636
// Only check for newly blocked PRs if there were actual changes
637+
// This must happen before UI updates so FirstBlockedAt is set correctly
637638
if actualChanges > 0 {
638639
app.checkForNewlyBlockedPRs(ctx)
639640
}
640641

641642
// Update tray title and menu with final Turn data if menu is already initialized
643+
// This happens after checkForNewlyBlockedPRs so party poppers show correctly
642644
app.setTrayTitle()
643645
if app.menuInitialized {
644646
// Only trigger menu update if PR data actually changed

cmd/goose/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
597597
// Newly blocked PR
598598
newBlockedTimes[incoming[i].URL] = now
599599
incoming[i].FirstBlockedAt = now
600+
log.Printf("[BLOCKED] Setting FirstBlockedAt for incoming PR: %s #%d at %v",
601+
incoming[i].Repository, incoming[i].Number, now)
600602

601603
// Skip sound and auto-open for stale PRs when hideStaleIncoming is enabled
602604
isStale := incoming[i].UpdatedAt.Before(staleThreshold)
@@ -625,6 +627,8 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
625627
// Newly blocked PR
626628
newBlockedTimes[outgoing[i].URL] = now
627629
outgoing[i].FirstBlockedAt = now
630+
log.Printf("[BLOCKED] Setting FirstBlockedAt for outgoing PR: %s #%d at %v",
631+
outgoing[i].Repository, outgoing[i].Number, now)
628632

629633
// Skip sound and auto-open for stale PRs when hideStaleIncoming is enabled
630634
isStale := outgoing[i].UpdatedAt.Before(staleThreshold)
@@ -652,4 +656,11 @@ func (app *App) checkForNewlyBlockedPRs(ctx context.Context) {
652656
app.incoming = incoming
653657
app.outgoing = outgoing
654658
app.mu.Unlock()
659+
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 {
663+
app.setTrayTitle()
664+
app.updateMenu(ctx)
665+
}
655666
}

cmd/goose/ui.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,21 @@ func (app *App) setTrayTitle() {
142142
counts := app.countPRs()
143143

144144
// Set title based on PR state
145+
var title string
145146
switch {
146147
case counts.IncomingBlocked == 0 && counts.OutgoingBlocked == 0:
147-
systray.SetTitle("😊")
148+
title = "😊"
148149
case counts.IncomingBlocked > 0 && counts.OutgoingBlocked > 0:
149-
systray.SetTitle(fmt.Sprintf("🪿 %d 🎉 %d", counts.IncomingBlocked, counts.OutgoingBlocked))
150+
title = fmt.Sprintf("🪿 %d 🎉 %d", counts.IncomingBlocked, counts.OutgoingBlocked)
150151
case counts.IncomingBlocked > 0:
151-
systray.SetTitle(fmt.Sprintf("🪿 %d", counts.IncomingBlocked))
152+
title = fmt.Sprintf("🪿 %d", counts.IncomingBlocked)
152153
default:
153-
systray.SetTitle(fmt.Sprintf("🎉 %d", counts.OutgoingBlocked))
154+
title = fmt.Sprintf("🎉 %d", counts.OutgoingBlocked)
154155
}
156+
157+
log.Printf("[TRAY] Setting title: %s (incoming_blocked=%d, outgoing_blocked=%d)",
158+
title, counts.IncomingBlocked, counts.OutgoingBlocked)
159+
systray.SetTitle(title)
155160
}
156161

157162
// sortPRsBlockedFirst creates a sorted copy of PRs with blocked ones first.
@@ -208,8 +213,12 @@ func (app *App) addPRSection(ctx context.Context, prs []PR, sectionTitle string,
208213
// Use party popper for outgoing PRs, goose for incoming PRs
209214
if sectionTitle == "Outgoing" {
210215
title = fmt.Sprintf("🎉 %s", title)
216+
log.Printf("[MENU] Adding party popper to outgoing PR: %s (blocked %v ago)",
217+
sortedPRs[i].URL, time.Since(sortedPRs[i].FirstBlockedAt))
211218
} else {
212219
title = fmt.Sprintf("🪿 %s", title)
220+
log.Printf("[MENU] Adding goose to incoming PR: %s (blocked %v ago)",
221+
sortedPRs[i].URL, time.Since(sortedPRs[i].FirstBlockedAt))
213222
}
214223
} else {
215224
title = fmt.Sprintf("• %s", title)

0 commit comments

Comments
 (0)