feat: 实现 Client 在线更新与安全回退 (#93)

This commit is contained in:
chengma
2026-08-10 12:32:39 +08:00
parent c24fac964e
commit 6d6829e374
14 changed files with 1609 additions and 18 deletions
+58 -1
View File
@@ -1,6 +1,6 @@
"""设置页的界面结构。
本文件只负责显示设备信息和提供界面更新入口。按钮事件统一由
本文件只负责显示设备和软件更新信息,并提供界面更新入口。按钮事件统一由
``settings_ui_event.py`` 绑定;ADB、SQLite 和硬件信息读取不得放在这里。
改动本文件前必读 ``client/AGENTS.md``。页面 ``objectName`` 固定为
@@ -32,6 +32,8 @@ from qfluentwidgets import (
TitleLabel,
)
from .version import __version__
@dataclass(frozen=True)
class AndroidDeviceRow:
@@ -207,6 +209,7 @@ class SettingsPage(QWidget):
settings_repository=None,
admin_gateway=None,
android_device_service=None,
update_service=None,
):
super().__init__(parent)
self.setObjectName("settingsPage")
@@ -220,6 +223,7 @@ class SettingsPage(QWidget):
settings_repository=settings_repository,
admin_gateway=admin_gateway,
android_device_service=android_device_service,
update_service=update_service,
)
def _build_ui(self) -> None:
@@ -289,6 +293,23 @@ class SettingsPage(QWidget):
self.pddAppStatusLabel.setWordWrap(True)
self.androidDeviceCard = self._build_android_device_card()
self.currentVersionLabel = CaptionLabel(__version__, self)
self.currentVersionLabel.setAccessibleName("当前软件版本")
self.updateManifestUrlInput = LineEdit(self)
self.updateManifestUrlInput.setPlaceholderText(
"https://updates.example.com/autobuy——manifest.json"
)
self.updateManifestUrlInput.setClearButtonEnabled(True)
self.updateManifestUrlInput.setAccessibleName("在线更新清单地址")
self.updateCheckButton = PushButton(FIF.UPDATE, "检查更新", self)
self.updateCheckButton.setAccessibleName("检查并下载软件更新")
self.updateStatusLabel = CaptionLabel(
"尚未检查;请填写 HTTPS 更新清单地址", self
)
self.updateStatusLabel.setAccessibleName("软件更新状态")
self.updateStatusLabel.setWordWrap(True)
self.softwareUpdateCard = self._build_software_update_card()
content = QWidget(self)
content.setObjectName("settingsContent")
contentLayout = QVBoxLayout(content)
@@ -297,6 +318,7 @@ class SettingsPage(QWidget):
contentLayout.addWidget(TitleLabel("设置", content))
contentLayout.addWidget(self.currentDeviceCard)
contentLayout.addWidget(self.androidDeviceCard)
contentLayout.addWidget(self.softwareUpdateCard)
contentLayout.addStretch(1)
scrollArea = ScrollArea(self)
@@ -383,6 +405,36 @@ class SettingsPage(QWidget):
layout.addWidget(self.deviceTable, 1)
return card
def _build_software_update_card(self) -> CardWidget:
card = CardWidget(self)
card.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
layout = QVBoxLayout(card)
layout.setContentsMargins(24, 20, 24, 22)
layout.setSpacing(12)
titleLayout = QHBoxLayout()
titleLayout.setSpacing(12)
titleLayout.addWidget(SubtitleLabel("软件更新", card))
titleLayout.addStretch(1)
titleLayout.addWidget(self.updateStatusLabel, 1)
layout.addLayout(titleLayout)
form = QFormLayout()
form.setHorizontalSpacing(16)
form.setVerticalSpacing(12)
versionLabel = CaptionLabel("当前版本", card)
manifestLabel = CaptionLabel("清单地址", card)
manifestLabel.setBuddy(self.updateManifestUrlInput)
form.addRow(versionLabel, self.currentVersionLabel)
form.addRow(manifestLabel, self.updateManifestUrlInput)
layout.addLayout(form)
commandLayout = QHBoxLayout()
commandLayout.addStretch(1)
commandLayout.addWidget(self.updateCheckButton)
layout.addLayout(commandLayout)
return card
def set_client_info(self, device_id: str, device_name: str) -> None:
"""显示后续设备身份服务提供的当前客户端信息。"""
@@ -405,6 +457,11 @@ class SettingsPage(QWidget):
self.pddAppStatusLabel.setText(message)
def set_update_status(self, message: str) -> None:
"""显示在线更新的检查、下载或恢复提示。"""
self.updateStatusLabel.setText(message)
def set_saved_android_device(self, serial: str) -> None:
"""显示已经保存并实际用于自动化的 Android 设备。"""