Skip to content

Commit 2479f57

Browse files
fix: handle missing ui.broadcast method in newer NiceGUI versions
- Added try-except to handle AttributeError when ui.broadcast is called - Fall back to timer-based sync when broadcast is not available - Added logging to track when fallback is used
1 parent d91afdd commit 2479f57

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/core/game_logic.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,13 @@ def close_game():
272272
ui.tooltip("Start New Game")
273273

274274
# Update stream page as well - this will trigger sync_board_state on connected clients
275-
ui.broadcast() # Broadcast changes to all connected clients
275+
# Note: ui.broadcast() was used in older versions of NiceGUI, but may not be available
276+
try:
277+
ui.broadcast() # Broadcast changes to all connected clients
278+
except AttributeError:
279+
# In newer versions of NiceGUI, broadcast might not be available
280+
# We rely on the timer-based sync instead
281+
logging.info("ui.broadcast not available, relying on timer-based sync")
276282

277283
# Notify that game has been closed
278284
ui.notify("Game has been closed", color="red", duration=3)
@@ -323,4 +329,9 @@ def reopen_game():
323329

324330
# Update stream page and all other connected clients
325331
# This will trigger sync_board_state on all clients including the stream view
326-
ui.broadcast()
332+
try:
333+
ui.broadcast() # Broadcast changes to all connected clients
334+
except AttributeError:
335+
# In newer versions of NiceGUI, broadcast might not be available
336+
# We rely on the timer-based sync instead
337+
logging.info("ui.broadcast not available, relying on timer-based sync")

0 commit comments

Comments
 (0)