From 14bdcf71feeb4d999540cdf456ea7aff270e6fd8 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 15 Mar 2025 19:10:21 +0000 Subject: [PATCH 01/61] Remove debug code --- internal/glance/widget-dns-stats.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/glance/widget-dns-stats.go b/internal/glance/widget-dns-stats.go index 9c04fbe..12b471d 100644 --- a/internal/glance/widget-dns-stats.go +++ b/internal/glance/widget-dns-stats.go @@ -533,8 +533,6 @@ func fetchPiholeStats( DomainsBlocked: statsResponse.Gravity.DomainsBlocked, } - ItsUsedTrustMeBro(seriesResponse, topDomainsResponse) - if includeGraph && seriesErr == nil { if len(seriesResponse.History) != 145 { slog.Error( From 4c1165533c082039be9a64121931daf1b44ef877 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 15 Mar 2025 19:41:08 +0000 Subject: [PATCH 02/61] Define service strings as consts to avoid forgetting to change them in all places --- internal/glance/widget-dns-stats.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/glance/widget-dns-stats.go b/internal/glance/widget-dns-stats.go index 12b471d..b4e32c1 100644 --- a/internal/glance/widget-dns-stats.go +++ b/internal/glance/widget-dns-stats.go @@ -42,6 +42,12 @@ type dnsStatsWidget struct { Password string `yaml:"password"` } +const ( + dnsServiceAdguard = "adguard" + dnsServicePihole = "pihole" + dnsServicePiholeV6 = "pihole-v6" +) + func makeDNSWidgetTimeLabels(format string) [8]string { now := time.Now() var labels [dnsStatsBars]string @@ -60,11 +66,11 @@ func (widget *dnsStatsWidget) initialize() error { withCacheDuration(10 * time.Minute) switch widget.Service { - case "adguard": - case "pihole-v6": - case "pihole": + case dnsServiceAdguard: + case dnsServicePiholeV6: + case dnsServicePihole: default: - return errors.New("service must be one of: adguard, pihole-v6, pihole") + return fmt.Errorf("service must be one of: %s, %s, %s", dnsServiceAdguard, dnsServicePihole, dnsServicePiholeV6) } return nil @@ -75,11 +81,11 @@ func (widget *dnsStatsWidget) update(ctx context.Context) { var err error switch widget.Service { - case "adguard": + case dnsServiceAdguard: stats, err = fetchAdguardStats(widget.URL, widget.AllowInsecure, widget.Username, widget.Password, widget.HideGraph) - case "pihole": + case dnsServicePihole: stats, err = fetchPihole5Stats(widget.URL, widget.AllowInsecure, widget.Token, widget.HideGraph) - case "pihole6": + case dnsServicePiholeV6: var newSessionID string stats, newSessionID, err = fetchPiholeStats( widget.URL, From 047d13afd1edd16802c8cf6eab7047dc1ac54e04 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sun, 16 Mar 2025 01:24:56 +0000 Subject: [PATCH 03/61] Fix summary triangle showing on Safari --- internal/glance/static/main.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/glance/static/main.css b/internal/glance/static/main.css index f686c59..672fc24 100644 --- a/internal/glance/static/main.css +++ b/internal/glance/static/main.css @@ -552,6 +552,10 @@ kbd:active { z-index: 1; } +.summary::-webkit-details-marker { + display: none; +} + .details[open] .summary { margin-bottom: .8rem; } From fbcea127864a7b9e21e840540c1c3c9fa26967ee Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sun, 16 Mar 2025 01:25:13 +0000 Subject: [PATCH 04/61] Add more info to logged message --- internal/glance/widget-dns-stats.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/glance/widget-dns-stats.go b/internal/glance/widget-dns-stats.go index b4e32c1..eb42b5a 100644 --- a/internal/glance/widget-dns-stats.go +++ b/internal/glance/widget-dns-stats.go @@ -644,7 +644,10 @@ func fetchPiholeSessionID(instanceURL string, client *http.Client, password stri } if jsonResponse.Session.SID == "" { - return "", errors.New("authentication response returned empty session ID") + return "", fmt.Errorf( + "authentication response returned empty session ID, status code %d, message '%s'", + response.StatusCode, jsonResponse.Session.Message, + ) } return jsonResponse.Session.SID, nil From 1615c20e66b5097d2cd1a40bd9802b4e46f1c25a Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sun, 16 Mar 2025 01:32:35 +0000 Subject: [PATCH 05/61] Change custom api int64 types to int Some of Go's native template functions return int and having to juggle between int and int64 might get messy so we'll try to stick to having a single int type --- internal/glance/widget-custom-api.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go index c8e3773..197ba68 100644 --- a/internal/glance/widget-custom-api.go +++ b/internal/glance/widget-custom-api.go @@ -153,12 +153,12 @@ func (r *decoratedGJSONResult) String(key string) string { return r.Get(key).String() } -func (r *decoratedGJSONResult) Int(key string) int64 { +func (r *decoratedGJSONResult) Int(key string) int { if key == "" { - return r.Result.Int() + return int(r.Result.Int()) } - return r.Get(key).Int() + return int(r.Get(key).Int()) } func (r *decoratedGJSONResult) Float(key string) float64 { @@ -179,11 +179,11 @@ func (r *decoratedGJSONResult) Bool(key string) bool { var customAPITemplateFuncs = func() template.FuncMap { funcs := template.FuncMap{ - "toFloat": func(a int64) float64 { + "toFloat": func(a int) float64 { return float64(a) }, - "toInt": func(a float64) int64 { - return int64(a) + "toInt": func(a float64) int { + return int(a) }, "add": func(a, b float64) float64 { return a + b From 71112173b9df1f96fe159964d5d2238f9ecd37d3 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sun, 16 Mar 2025 23:15:19 +0000 Subject: [PATCH 06/61] Fix title link not opening in new tab --- internal/glance/templates/videos-vertical-list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/glance/templates/videos-vertical-list.html b/internal/glance/templates/videos-vertical-list.html index b7ea6b2..a735a74 100644 --- a/internal/glance/templates/videos-vertical-list.html +++ b/internal/glance/templates/videos-vertical-list.html @@ -6,7 +6,7 @@
  • - {{ .Title }} + {{ .Title }}