]> khamidou — GitHub mirrors - prguy.git/commitdiff
refresh prs on a schedule
authorKarim Hamidou <karim@khamidou.com>
Tue, 25 Jun 2024 03:58:26 +0000 (20:58 -0700)
committerKarim Hamidou <karim@khamidou.com>
Tue, 25 Jun 2024 03:58:26 +0000 (20:58 -0700)
cmd/prguy/main.go

index 0b495724ab1a3b5705c101553fd8a94b3bf4525c..6b1055a73559b3dd6f322a7bf8af40217ad8d4fa 100644 (file)
@@ -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) {