fix(progress): always report status transitions and poll for control signals

This commit is contained in:
Deivid Soto 2026-03-31 16:55:50 +02:00
parent 763e267bf8
commit 01d62ffa13
5 changed files with 122 additions and 26 deletions

View file

@ -6,6 +6,7 @@ import (
"log"
"os"
"runtime"
"sync/atomic"
"time"
)
@ -43,7 +44,8 @@ type Daemon struct {
// Watching tracks whether a user is viewing download progress in the web UI.
// When false, the progress reporter skips detailed updates (only sends final states).
Watching bool
// Accessed from heartbeat goroutine, flush goroutine, and WatchingFunc closure — must be atomic.
Watching atomic.Bool
// Exposed tickers for hot-reload
PollTicker *time.Ticker
@ -195,7 +197,7 @@ func (d *Daemon) heartbeat(ctx context.Context) {
}
// Update watching flag and state file
d.Watching = resp.Watching
d.Watching.Store(resp.Watching)
d.State.LastHeartbeat = time.Now()
if d.GetActiveCount != nil {
d.State.ActiveTasks = d.GetActiveCount()

View file

@ -109,6 +109,7 @@ type StatusResponse struct {
Paused bool `json:"paused,omitempty"`
DeleteFiles bool `json:"deleteFiles,omitempty"`
StreamRequested bool `json:"streamRequested,omitempty"`
Watching bool `json:"watching,omitempty"`
}
// BatchStatusRequest wraps multiple status updates in a single request.
@ -118,7 +119,8 @@ type BatchStatusRequest struct {
// BatchStatusResponse wraps per-task results from the batch endpoint.
type BatchStatusResponse struct {
Results []StatusResponse `json:"results"`
Results []StatusResponse `json:"results"`
Watching bool `json:"watching,omitempty"`
}
// HeartbeatResponse is returned by the server on heartbeat.