gui: fix connection history retaining stale counter-based ID
_push_lru ran right after connect, before MON-VER resolves the device name, so history entries kept the placeholder ID forever. Dedupe LRU entries by connection endpoint (host/port, serial port, or file path) instead of by receiver_id, and re-push once the device name is known so the corrected entry replaces the placeholder instead of duplicating it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XM4FNUjhu9x8df5Dp1hHvd
This commit is contained in:
@@ -356,3 +356,5 @@ class ConnectionTab(QWidget):
|
||||
if row.get_receiver_id() == rid:
|
||||
row.set_version_info(device_id, sw_version)
|
||||
break
|
||||
if device_id:
|
||||
self._refresh_history_combo()
|
||||
|
||||
+13
-2
@@ -77,6 +77,13 @@ class ConnectionConfig:
|
||||
return f"{self.receiver_id} [{self.serial_port} @ {self.baud_rate}]"
|
||||
return f"{self.receiver_id} [file: {os.path.basename(self.file_path)}]"
|
||||
|
||||
def endpoint_key(self):
|
||||
if self.conn_type == 'tcp':
|
||||
return ('tcp', self.host, self.port)
|
||||
if self.conn_type == 'serial':
|
||||
return ('serial', self.serial_port, self.baud_rate)
|
||||
return ('file', self.file_path)
|
||||
|
||||
def to_dict(self):
|
||||
return dataclasses.asdict(self)
|
||||
|
||||
@@ -135,8 +142,8 @@ class ReceiverManager(QObject):
|
||||
pass
|
||||
|
||||
def _push_lru(self, config: ConnectionConfig):
|
||||
key = config.display_str()
|
||||
self._lru = [c for c in self._lru if c.display_str() != key]
|
||||
key = config.endpoint_key()
|
||||
self._lru = [c for c in self._lru if c.endpoint_key() != key]
|
||||
self._lru.insert(0, config)
|
||||
self._lru = self._lru[:LRU_MAX]
|
||||
self._save_lru()
|
||||
@@ -333,3 +340,7 @@ class ReceiverManager(QObject):
|
||||
if state:
|
||||
state.device_id = device_id
|
||||
state.sw_version = sw_version
|
||||
config = self._configs.get(rid)
|
||||
if config and device_id:
|
||||
config.receiver_id = device_id
|
||||
self._push_lru(config)
|
||||
|
||||
Reference in New Issue
Block a user