37 lines
916 B
Go
37 lines
916 B
Go
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)), 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
|
|
}
|