Add Pi-hole blocked percentage and date widgets

This commit is contained in:
2025-12-22 20:45:55 +01:00
parent 2315ac2ce7
commit 7b6a8bbaab
7 changed files with 111 additions and 7 deletions
+36
View File
@@ -0,0 +1,36 @@
package widgets
import (
"ArinDash/apis/pihole"
"ArinDash/util"
"context"
"time"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/terminal/terminalapi"
"github.com/mum4k/termdash/widgetapi"
"github.com/mum4k/termdash/widgets/donut"
)
type PiholeBlockedOptions struct {
}
func PiholeBlocked() PiholeBlockedOptions {
widgetOptions["PiholeBlockedOptions"] = createPiholeBlocked
return PiholeBlockedOptions{}
}
func createPiholeBlocked(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
widget := util.PanicOnErrorWithResult(donut.New(donut.CellOpts(cell.FgColor(cell.ColorRed), cell.Blink()), donut.HolePercent(20), donut.ShowTextProgress()))
ph := pihole.Connect()
go util.Periodic(ctx, 1*time.Minute, func() error {
summary := ph.Summary()
if err := widget.Percent(int(summary.Queries.PercentBlocked)); err != nil {
return nil
}
return nil
})
return widget
}