Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions badge/apps/badge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ 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:
return any(ord(char) > 255 for char in text)
except (TypeError, AttributeError):
# Handle cases where text is not iterable or contains invalid characters
return True


def placeholder_if_none(text):
if text:
return text
Expand Down Expand Up @@ -306,6 +317,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)

Expand Down