From faa3828da8d85a46a4b2e173c821ad6539397854 Mon Sep 17 00:00:00 2001 From: Brad Barnett <127794626+bdbarnett@users.noreply.github.com> Date: Thu, 26 Nov 2026 00:05:14 -0600 Subject: [PATCH] remotedisplay: the page's title is the board's name --- lib/displaydev/remotedisplay.py | 23 +++++++++++++++++++++-- tests/test_remotedisplay.py | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/displaydev/remotedisplay.py b/lib/displaydev/remotedisplay.py index 9fd8351e..1ee58d8e 100644 --- a/lib/displaydev/remotedisplay.py +++ b/lib/displaydev/remotedisplay.py @@ -256,6 +256,7 @@ def __init__(self, display, port=80, period_ms=40, sweep_ms=2000, bind="0.0.0.0" self.url = "http://%s%s/" % (_own_address(), at) name = _own_name() self.name_url = "http://%s.local%s/" % (name, at) if name else None + self._page = _titled(PAGE, _board_name()) self._timer = every(period_ms, self.poll, name="remotedisplay") if self.name_url: print("Display at %s and %s" % (self.url, self.name_url)) @@ -630,8 +631,8 @@ def _serve(self, conn): if target in ("/", "/index.html"): conn.out = ( "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n" - "Cache-Control: no-cache\r\nConnection: close\r\nContent-Length: %d\r\n\r\n" % len(PAGE) - ).encode() + PAGE + "Cache-Control: no-cache\r\nConnection: close\r\nContent-Length: %d\r\n\r\n" % len(self._page) + ).encode() + self._page else: conn.out = b"HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nConnection: close\r\n\r\n" conn.done = True @@ -967,6 +968,24 @@ def _put_head(buf, off, x, y, w, h, enc, n): buf[off + 15] = n >> 24 +def _board_name(): + """The board's name from `boarddev`, for the page's title; None without it.""" + try: + import boarddev + + return boarddev.name() or None + except (ImportError, AttributeError, OSError, ValueError): + return None + + +def _titled(page, name): + """The page with the board's name as its title, so a browser tab says which board it shows.""" + if not name: + return page + safe = name.replace("&", "&").replace("<", "<").replace(">", ">") + return page.replace(b"