04/22 Upgraded code commit

This commit is contained in:
2026-04-22 12:22:26 -04:00
parent 7548dfc9bf
commit c0e965f10b
9 changed files with 714 additions and 19 deletions
+70
View File
@@ -21,6 +21,11 @@ logger = logging.getLogger("app")
IDLE_TIMEOUT_MS = 30 * 60 * 1000 # 30 minutes in milliseconds
IDLE_WARNING_MS = 60 * 1000 # warn 1 minute before timeout
# ─── Version Configuration ────────────────────────────────────────────────────
APP_VERSION = "1.0.0"
VERSION_CHECK_URL = "https://api.github.com/repos/your-org/website-checker/releases/latest"
VERSION_CHECK_ENABLED = False # set True and update URL when publishing releases
class App(tk.Tk):
def __init__(self):
@@ -88,6 +93,11 @@ class App(tk.Tk):
if user.get("role") == "admin":
from utils.scheduler import start as _sched_start
_sched_start()
# Non-blocking version check (admin only)
if user.get("role") == "admin" and VERSION_CHECK_ENABLED:
import threading
threading.Thread(target=self._check_for_updates,
daemon=True).start()
def _centre(self):
self.update_idletasks()
@@ -388,6 +398,66 @@ class App(tk.Tk):
)
self._logout()
# ─── Version Check ────────────────────────────────────────────────────────
def _check_for_updates(self):
"""
Background thread: fetch the latest release tag from GitHub and
show a dismissible banner if a newer version is available.
Set VERSION_CHECK_ENABLED=True and update VERSION_CHECK_URL to activate.
"""
try:
import urllib.request
import json
req = urllib.request.Request(
VERSION_CHECK_URL,
headers={"User-Agent": "WebsiteChecker/" + APP_VERSION},
)
with urllib.request.urlopen(req, timeout=6) as resp:
data = json.loads(resp.read())
latest_tag = data.get("tag_name", "").lstrip("v")
release_url = data.get("html_url", "")
if latest_tag and latest_tag != APP_VERSION:
logger.info(f"New version available: {latest_tag} (current: {APP_VERSION})")
self.after(0, lambda: self._show_update_banner(latest_tag, release_url))
except Exception as e:
logger.debug(f"Version check failed (non-critical): {e}")
def _show_update_banner(self, latest_version: str, release_url: str):
"""Show a non-intrusive dismissible update notification at the top."""
if not self.current_user:
return
try:
banner = tk.Frame(self.content, bg=COLOURS["accent"], pady=6)
banner.pack(fill="x", side="top", before=self.content.winfo_children()[0])
tk.Label(banner,
text=f" Update available: v{latest_version} "
f"(you have v{APP_VERSION})",
bg=COLOURS["accent"], fg=COLOURS["white"],
font=FONT_SMALL).pack(side="left", padx=(8, 0))
if release_url:
import webbrowser
tk.Button(
banner, text="View Release",
command=lambda: webbrowser.open(release_url),
bg=COLOURS["white"], fg=COLOURS["accent"],
relief="flat", font=FONT_SMALL, cursor="hand2",
padx=8, pady=2,
).pack(side="left", padx=8)
tk.Button(
banner, text="✕ Dismiss",
command=banner.destroy,
bg=COLOURS["accent"], fg=COLOURS["white"],
relief="flat", font=FONT_SMALL, cursor="hand2",
padx=8,
).pack(side="right", padx=8)
except Exception:
pass # UI may not be ready — silently skip
# ─── Change Password ──────────────────────────────────────────────────────
def _show_change_password(self):