Skip to content

The only downloader you need. 下载器的集大成者。

fix(user_agent_settings): UA combo 切换栈溢出

XiaoYouChR32d0de3bbc22
diff --git a/app/view/components/user_agent_settings.py b/app/view/components/user_agent_settings.py
index 5e23294e..d1e9e7ae 100644
--- a/app/view/components/user_agent_settings.py
+++ b/app/view/components/user_agent_settings.py
@@ -57,22 +57,26 @@ class UserAgentSettingCard(SettingCard):
cfg.activeUserAgent.valueChanged.connect(self._refreshComboBox)
def _refreshComboBox(self) -> None:
- # 不需要 blockSignals: clear() 触发的 currentIndexChanged(-1) 走 _onComboChanged
- # 时 itemData 是 None 直接跳过; setCurrentIndex 之后即便回写 cfg 也是同值, 不会
- # 再次触发 valueChanged 形成环
- self.comboBox.clear()
- active = cfg.activeUserAgent.value
- activeIndex = 0
- for i, preset in enumerate(cfg.userAgents.value):
- name = preset.get("name", "")
- value = preset.get("value", "")
- if not name or not value:
- continue
- self.comboBox.addItem(name, userData=value)
- if value == active:
- activeIndex = i
- if self.comboBox.count() > 0:
- self.comboBox.setCurrentIndex(activeIndex)
+ # combo 同时是 cfg 的输入源 (user 选 → cfg.set) 和镜像 (cfg 外部改 → refresh),
+ # 不 blockSignals 就会出现 cfg.set → valueChanged → refresh → setCurrentIndex
+ # → currentIndexChanged → cfg.set 的回环, 直接栈溢出
+ self.comboBox.blockSignals(True)
+ try:
+ self.comboBox.clear()
+ active = cfg.activeUserAgent.value
+ activeIndex = 0
+ for i, preset in enumerate(cfg.userAgents.value):
+ name = preset.get("name", "")
+ value = preset.get("value", "")
+ if not name or not value:
+ continue
+ self.comboBox.addItem(name, userData=value)
+ if value == active:
+ activeIndex = i
+ if self.comboBox.count() > 0:
+ self.comboBox.setCurrentIndex(activeIndex)
+ finally:
+ self.comboBox.blockSignals(False)
def _onComboChanged(self, index: int) -> None:
value = self.comboBox.itemData(index)