Fix relay URL update using Qt signals for thread safety
QTimer.singleShot doesn't work properly from non-Qt threads. Use Qt signals instead which are thread-safe and properly marshal calls to the main thread. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -121,6 +121,10 @@ class MainWindow(QMainWindow):
|
||||
"""Main application window."""
|
||||
|
||||
macros_changed = Signal()
|
||||
# Signals for thread-safe relay status updates
|
||||
relay_session_received = Signal(str)
|
||||
relay_connected_signal = Signal()
|
||||
relay_disconnected_signal = Signal()
|
||||
|
||||
def __init__(self, app_dir: str):
|
||||
super().__init__()
|
||||
@@ -160,6 +164,9 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# Connect signals
|
||||
self.macros_changed.connect(self.refresh_macros)
|
||||
self.relay_session_received.connect(self._handle_relay_session)
|
||||
self.relay_connected_signal.connect(lambda: self._update_relay_status(True))
|
||||
self.relay_disconnected_signal.connect(lambda: self._update_relay_status(False))
|
||||
|
||||
# Load initial data
|
||||
self.refresh_tabs()
|
||||
@@ -659,18 +666,23 @@ class MainWindow(QMainWindow):
|
||||
self.status_bar.showMessage("Relay disconnected", 2000)
|
||||
|
||||
def on_relay_connected(self):
|
||||
"""Handle relay connection established."""
|
||||
QTimer.singleShot(0, lambda: self._update_relay_status(True))
|
||||
"""Handle relay connection established (called from background thread)."""
|
||||
self.relay_connected_signal.emit()
|
||||
|
||||
def on_relay_disconnected(self):
|
||||
"""Handle relay disconnection."""
|
||||
QTimer.singleShot(0, lambda: self._update_relay_status(False))
|
||||
"""Handle relay disconnection (called from background thread)."""
|
||||
self.relay_disconnected_signal.emit()
|
||||
|
||||
def on_relay_session_id(self, session_id: str):
|
||||
"""Handle receiving session ID from relay."""
|
||||
"""Handle receiving session ID from relay (called from background thread)."""
|
||||
print(f"[DEBUG] on_relay_session_id called with: {session_id}")
|
||||
self.relay_session_received.emit(session_id)
|
||||
|
||||
def _handle_relay_session(self, session_id: str):
|
||||
"""Handle relay session on main thread."""
|
||||
print(f"[DEBUG] _handle_relay_session on main thread: {session_id}")
|
||||
self.settings_manager.set_relay_session_id(session_id)
|
||||
QTimer.singleShot(0, self.update_ip_label)
|
||||
self.update_ip_label()
|
||||
|
||||
def _update_relay_status(self, connected: bool):
|
||||
"""Update UI for relay status (called on main thread)."""
|
||||
|
||||
Reference in New Issue
Block a user