04/23 Enhance app functionalities

This commit is contained in:
2026-04-23 16:54:24 -04:00
parent 64419a445a
commit f4eea48e4d
8 changed files with 427 additions and 45 deletions
+42 -11
View File
@@ -265,12 +265,18 @@ class UserDashboardView(ttk.Frame):
cached = self._health_cache.get(wid)
if cached:
status_str, ms = cached
dot_col = {"ok": COLOURS["success"],
"slow": COLOURS["warning"],
"down": COLOURS["danger"]}.get(status_str, COLOURS["text_dim"])
dot_tip = {"ok": f"Reachable ({ms}ms)",
"slow": f"Slow ({ms}ms)",
"down": "Unreachable"}.get(status_str, "Unknown")
dot_col = {
"ok": COLOURS["success"],
"slow": COLOURS["warning"],
"restricted": COLOURS["warning"],
"down": COLOURS["danger"],
}.get(status_str, COLOURS["text_dim"])
dot_tip = {
"ok": f"Reachable ({ms}ms)",
"slow": f"Slow ({ms}ms)",
"restricted": f"Reachable — access restricted ({ms}ms)",
"down": "Unreachable",
}.get(status_str, "Unknown")
else:
dot_col = COLOURS["text_dim"]
dot_tip = "Checking..."
@@ -424,8 +430,21 @@ class UserDashboardView(ttk.Frame):
# ─── Health Pre-check ─────────────────────────────────────────────────────
def _check_site_health(self, wid: int, url: str, dot_label: tk.Label):
"""Background thread: HEAD request to url; updates health_cache + dot colour."""
"""Background thread: HEAD request to url; updates health_cache + dot colour.
Status semantics:
ok — 2xx / 3xx response, <= 3 000 ms
slow — 2xx / 3xx response, > 3 000 ms
restricted — 4xx response (server reachable but denying HEAD access)
down — network error, timeout, or 5xx (server not responding)
4xx responses are intentionally treated as "restricted" (amber) rather
than "down" (red) because the server is clearly reachable — many sites
block unauthenticated HEAD requests with 401/403 even when fully
operational.
"""
import urllib.request
import urllib.error
import time
if not url.startswith(("http://", "https://")):
@@ -436,16 +455,28 @@ class UserDashboardView(ttk.Frame):
req.add_header("User-Agent", "WebsiteChecker/1.0 HealthProbe")
t0 = time.monotonic()
urllib.request.urlopen(req, timeout=6)
ms = int((time.monotonic() - t0) * 1000)
ms = int((time.monotonic() - t0) * 1000)
status = "slow" if ms > 3000 else "ok"
except urllib.error.HTTPError as e:
ms = int((time.monotonic() - t0) * 1000)
if 400 <= e.code < 500:
# Server responded — it is reachable but blocking this probe
status = "restricted"
else:
# 5xx: server error — treat as down
ms = 0
status = "down"
except Exception:
ms = 0
status = "down"
self._health_cache[wid] = (status, ms)
col = {"ok": COLOURS["success"],
"slow": COLOURS["warning"],
"down": COLOURS["danger"]}.get(status, COLOURS["text_dim"])
col = {
"ok": COLOURS["success"],
"slow": COLOURS["warning"],
"restricted": COLOURS["warning"],
"down": COLOURS["danger"],
}.get(status, COLOURS["text_dim"])
# Update the dot on the main thread
try: