From: Karim Hamidou Date: Tue, 25 Jun 2024 03:58:26 +0000 (-0700) Subject: refresh prs on a schedule X-Git-Tag: 0.5~10 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4ed477159389bfa40b180a5a54f57420a0084713;p=prguy.git refresh prs on a schedule --- diff --git a/cmd/prguy/main.go b/cmd/prguy/main.go index 0b49572..6b1055a 100644 --- a/cmd/prguy/main.go +++ b/cmd/prguy/main.go @@ -30,8 +30,7 @@ func errorOut(title string, message string) { zenity.Error(message, zenity.Title(title), zenity.ErrorIcon) } -func setupMenu() { - ctx, cancel := context.WithCancel(context.Background()) +func setupMenu(ctx context.Context, cancel context.CancelFunc) { systray.SetTemplateIcon([]byte("🕴️"), []byte("🕴️")) systray.SetTitle("PR Guy") config := Config{} @@ -59,6 +58,8 @@ func setupMenu() { } else { cfg := Config{} cfg.load() + systray.ResetMenu() + prs, err := listUserPRs(cfg.OAuthToken) if err != nil { errorOut("Error fetching PRs", err.Error()) @@ -103,7 +104,22 @@ func setupMenu() { } func onReady() { - setupMenu() + go func() { + ticker := time.NewTicker(1 * time.Minute) + defer ticker.Stop() // Ensure the ticker is stopped when we're done with it + + ctx, cancel := context.WithCancel(context.Background()) + setupMenu(ctx, cancel) + for { + select { + case <-ticker.C: + // refresh the menu every 15 minutes + cancel() + ctx, cancel = context.WithCancel(context.Background()) + setupMenu(ctx, cancel) + } + } + }() } func startGithubDeviceAuth(cancel context.CancelFunc) {