feat(update): add forced upgrade progress flow

This commit is contained in:
chengma
2026-07-13 12:12:58 +08:00
parent bab2609a85
commit 04124060fc
11 changed files with 437 additions and 101 deletions
+7 -35
View File
@@ -4,7 +4,6 @@ from __future__ import annotations
import os
import sys
import webbrowser
from .. import appconfig, chrome, diagnostics, update_check
from ..version import APP_NAME, display_name
@@ -38,6 +37,7 @@ if QT_IMPORT_ERROR is None:
from .tabs.image_studio import ImageStudioPreviewDialog, ImageStudioTab
from .tabs.settings import SettingsTab
from .main_window import MainWindow
from .update_dialog import ForcedUpdateDialog, UpdatePreparationWorker
else:
class MainWindow(QMainWindow):
def __init__(self):
@@ -74,42 +74,14 @@ def _write_update_check_diagnostic(message, *, result=None, exc=None):
pass
def _forced_update_details(result):
online_version = result.latest_version or result.min_supported_version or "未知"
lines = [
f"当前版本:{result.current_version}",
f"线上版本:{online_version}",
]
if result.min_supported_version:
lines.append(f"最低支持版本:{result.min_supported_version}")
if result.message:
lines.append(f"升级说明:{result.message}")
if result.download_url:
lines.append("请下载新版,关闭程序后覆盖程序文件和 _internal/,保留 data/ 目录。")
else:
lines.append("版本接口未提供下载地址,请联系管理员获取新版后再使用。")
return "\n".join(lines)
def _show_forced_update_dialog(result, *, parent=None, opener=None) -> bool:
opener = opener or webbrowser.open
box = QMessageBox(parent)
box.setIcon(QMessageBox.Warning)
box.setWindowTitle("必须升级")
box.setText("当前版本已不能继续使用,请先升级到新版。")
box.setInformativeText(_forced_update_details(result))
download_button = box.addButton("下载新版", QMessageBox.AcceptRole)
exit_button = box.addButton("退出程序", QMessageBox.RejectRole)
if not result.download_url and hasattr(download_button, "setEnabled"):
download_button.setEnabled(False)
box.setDefaultButton(download_button if result.download_url else exit_button)
box.exec()
if box.clickedButton() is download_button and result.download_url:
opener(result.download_url)
def _show_forced_update_dialog(result, *, parent=None, dialog_factory=None) -> bool:
dialog_class = dialog_factory or ForcedUpdateDialog
dialog = dialog_class(result, parent=parent)
dialog.exec()
return False
def _run_startup_update_gate(*, checker=None, opener=None) -> bool:
def _run_startup_update_gate(*, checker=None, dialog_factory=None) -> bool:
try:
result = (checker or update_check.check_for_update)()
except Exception as exc:
@@ -119,7 +91,7 @@ def _run_startup_update_gate(*, checker=None, opener=None) -> bool:
if result.error:
_write_update_check_diagnostic("启动版本检查失败,已允许继续使用", result=result)
if result.forced:
return _show_forced_update_dialog(result, opener=opener)
return _show_forced_update_dialog(result, dialog_factory=dialog_factory)
return True