From f3bf0a66e274980925658767a192af21606ab5ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 22:59:40 +0000 Subject: [PATCH 1/4] Initial plan From 5b38db80ed420ed9cb4ffd775d965a87623f5c28 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 23:07:06 +0000 Subject: [PATCH 2/4] Add fallback to GitHub handle for names with unsupported characters Co-authored-by: gwincr11 <289882+gwincr11@users.noreply.github.com> --- badge/apps/badge/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/badge/apps/badge/__init__.py b/badge/apps/badge/__init__.py index 41215ab..a24a594 100755 --- a/badge/apps/badge/__init__.py +++ b/badge/apps/badge/__init__.py @@ -201,6 +201,19 @@ def fake_number(): return random.randint(10000, 99999) +def has_unsupported_chars(text): + """Check if text contains characters outside the ASCII/Latin-1 range (>255)""" + if not text: + return False + try: + for char in text: + if ord(char) > 255: + return True + return False + except: + return True + + def placeholder_if_none(text): if text: return text @@ -306,6 +319,9 @@ def draw(self, connected): screen.font = small_font screen.brush = phosphor name = placeholder_if_none(self.name) + # Use handle as fallback if name contains unsupported characters (e.g., Chinese) + if self.name and has_unsupported_chars(self.name): + name = self.handle if self.handle else name w, _ = screen.measure_text(name) screen.text(name, 80 - (w / 2), 16) From 32af5569df034acb8e7e0081d7e1ca415acc7a10 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 23:09:42 +0000 Subject: [PATCH 3/4] Improve has_unsupported_chars function based on code review Co-authored-by: gwincr11 <289882+gwincr11@users.noreply.github.com> --- badge/apps/badge/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/badge/apps/badge/__init__.py b/badge/apps/badge/__init__.py index a24a594..cc38d82 100755 --- a/badge/apps/badge/__init__.py +++ b/badge/apps/badge/__init__.py @@ -206,11 +206,8 @@ def has_unsupported_chars(text): if not text: return False try: - for char in text: - if ord(char) > 255: - return True - return False - except: + return any(ord(char) > 255 for char in text) + except Exception: return True From 9139ded3cf19520e63cd4f1bd469bc27b72cf7c7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 23:11:17 +0000 Subject: [PATCH 4/4] Use more specific exception handling in has_unsupported_chars Co-authored-by: gwincr11 <289882+gwincr11@users.noreply.github.com> --- badge/apps/badge/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/badge/apps/badge/__init__.py b/badge/apps/badge/__init__.py index cc38d82..33fd0da 100755 --- a/badge/apps/badge/__init__.py +++ b/badge/apps/badge/__init__.py @@ -207,7 +207,8 @@ def has_unsupported_chars(text): return False try: return any(ord(char) > 255 for char in text) - except Exception: + except (TypeError, AttributeError): + # Handle cases where text is not iterable or contains invalid characters return True