MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / startAutoRefresh

Method startAutoRefresh

internal/ui/components/auto_refresh.go:36–129  ·  view source on GitHub ↗

startAutoRefresh starts the auto-refresh timer.

()

Source from the content-addressed store, hash-verified

34
35// startAutoRefresh starts the auto-refresh timer.
36func (a *App) startAutoRefresh() {
37 // Don't start if auto-refresh is not enabled
38 if !a.autoRefreshEnabled {
39 return
40 }
41
42 if a.autoRefreshRunning {
43 return // Already running
44 }
45
46 a.autoRefreshRunning = true
47 a.autoRefreshCountdown = 10
48 a.footer.UpdateAutoRefreshCountdown(a.autoRefreshCountdown)
49 a.autoRefreshCountdownStop = make(chan bool, 1)
50
51 // Start countdown goroutine using a proper ticker instead of busy-wait + sleep
52 go func() {
53 uiLogger := models.GetUILogger()
54 countdownTicker := time.NewTicker(1 * time.Second)
55 defer countdownTicker.Stop()
56
57 for {
58 select {
59 case <-a.autoRefreshCountdownStop:
60 return
61 case <-a.ctx.Done():
62 return
63 case <-countdownTicker.C:
64 if !a.autoRefreshEnabled {
65 return
66 }
67
68 if a.footer.IsLoading() {
69 continue // Pause countdown while loading
70 }
71
72 a.autoRefreshCountdown--
73 if a.autoRefreshCountdown < 0 {
74 a.autoRefreshCountdown = 0
75 }
76
77 // Trigger refresh when countdown reaches 0
78 if a.autoRefreshCountdown == 0 {
79 // Only refresh if not currently loading, no pending operations,
80 // and no other refresh (manual/fast/enrichment) is in progress.
81 if !a.header.IsLoading() && !models.GlobalState.HasPendingOperations() && !a.isRefreshActive() {
82 uiLogger.Debug("Auto-refresh triggered by countdown")
83
84 go a.autoRefreshDataWithFooter()
85 } else {
86 if a.isRefreshActive() {
87 uiLogger.Debug("Auto-refresh skipped - refresh already in progress")
88 } else if a.header.IsLoading() {
89 uiLogger.Debug("Auto-refresh skipped - header loading operation in progress")
90 } else {
91 uiLogger.Debug("Auto-refresh skipped - pending VM/node operations in progress")
92 }
93 // Reset countdown to try again in 10 seconds

Callers 2

RunMethod · 0.95
toggleAutoRefreshMethod · 0.95

Calls 10

isRefreshActiveMethod · 0.95
GetUILoggerFunction · 0.92
HasPendingOperationsMethod · 0.80
QueueUpdateDrawMethod · 0.80
IsLoadingMethod · 0.65
DebugMethod · 0.65
TickSpinnerMethod · 0.65
StopMethod · 0.45

Tested by

no test coverage detected