Announce finished and failed downloads in the background (M10)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 22:34:55 +02:00
co-authored by Claude Sonnet 5.5
parent a7765c5079
commit ebbb3cd178
7 changed files with 157 additions and 2 deletions
+16
View File
@@ -44,6 +44,10 @@ type App struct {
state map[string]serviceState // keyed by service name
probes []probe
screen tcell.Screen // remembered at the first draw, for the bell
sab *sabnzbd.Client
notifyDone bool // announce finished downloads
bell bool
covers bool // poster thumbnails enabled
coverStyle coverStyle
coverCache *coverCache
@@ -90,6 +94,8 @@ func New(cfg *config.Config) *App {
services: tview.NewTextView().SetDynamicColors(true).SetTextAlign(tview.AlignRight),
state: map[string]serviceState{},
notifyDone: cfg.UI.ShouldNotifyDownloads(),
bell: cfg.UI.Bell,
covers: cfg.UI.ShowCovers(),
coverStyle: coverStyleFor(cfg.UI.CoverStyle, os.Getenv),
coverCache: newCoverCache(),
@@ -99,6 +105,7 @@ func New(cfg *config.Config) *App {
sonarrClient := sonarr.NewClient(cfg.Sonarr.URL, cfg.Sonarr.APIKey)
a.logs = newLogView(a)
sabClient := sabnzbd.NewClient(cfg.SABnzbd.URL, cfg.SABnzbd.APIKey)
a.sab = sabClient
a.probes = []probe{
{"Radarr", func(ctx context.Context) (string, error) {
st, err := radarrClient.SystemStatus(ctx)
@@ -135,6 +142,10 @@ func New(cfg *config.Config) *App {
AddItem(a.pages, 0, 1, true).
AddItem(a.status, 1, 0, false)
a.app.SetBeforeDrawFunc(func(s tcell.Screen) bool {
a.screen = s
return false
})
a.app.SetRoot(&toastRoot{Flex: layout, app: a}, true).EnableMouse(false)
a.app.SetInputCapture(a.handleKey)
a.switchTo(0)
@@ -206,6 +217,11 @@ func (a *App) Run() error {
stop := make(chan struct{})
defer close(stop)
go a.watchServices(stop)
if a.notifyDone {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go a.watchDownloads(ctx, a.sab, a.bell)
}
return a.app.Run()
}