feat(update): add startup health rollback fuse
This commit is contained in:
+29
-2
@@ -4,9 +4,10 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from dataclasses import replace
|
||||
|
||||
from .. import appconfig, chrome, diagnostics, update_check
|
||||
from ..version import APP_NAME, display_name
|
||||
from .. import appconfig, chrome, diagnostics, update_check, update_health
|
||||
from ..version import APP_NAME, APP_VERSION, display_name
|
||||
from . import widgets as _widgets
|
||||
from .widgets import *
|
||||
|
||||
@@ -91,6 +92,18 @@ def _run_startup_update_gate(*, checker=None, dialog_factory=None) -> bool:
|
||||
if result.error:
|
||||
_write_update_check_diagnostic("启动版本检查失败,已允许继续使用", result=result)
|
||||
if result.forced:
|
||||
failed = update_health.get_failed_release(
|
||||
appconfig.app_base_dir(),
|
||||
result.latest_version,
|
||||
result.sha256,
|
||||
)
|
||||
if failed:
|
||||
result = replace(
|
||||
result,
|
||||
automatic_update_error=(
|
||||
"该版本自动升级曾失败,已停止重复安装。请等待管理员发布修复版本,或手动安装新版。"
|
||||
),
|
||||
)
|
||||
return _show_forced_update_dialog(result, dialog_factory=dialog_factory)
|
||||
return True
|
||||
|
||||
@@ -101,15 +114,24 @@ def main() -> int:
|
||||
return 1
|
||||
_ensure_offscreen_for_headless_tests()
|
||||
app = QApplication.instance() or QApplication(sys.argv)
|
||||
health_context = update_health.context_from_argv(
|
||||
sys.argv,
|
||||
appconfig.app_base_dir(),
|
||||
APP_VERSION,
|
||||
)
|
||||
update_health.write_health(health_context, "process_started")
|
||||
try:
|
||||
appconfig.prepare_data_dir()
|
||||
except appconfig.DataMigrationConflictError as exc:
|
||||
update_health.write_health(health_context, "environment_blocked", str(exc))
|
||||
QMessageBox.critical(None, "数据迁移冲突", str(exc))
|
||||
return 1
|
||||
except appconfig.DataDirectoryWriteError as exc:
|
||||
update_health.write_health(health_context, "environment_blocked", str(exc))
|
||||
QMessageBox.critical(None, "数据目录不可写", str(exc))
|
||||
return 1
|
||||
except appconfig.ConfigError as exc:
|
||||
update_health.write_health(health_context, "environment_blocked", str(exc))
|
||||
QMessageBox.critical(None, "启动配置错误", str(exc))
|
||||
return 1
|
||||
if not _run_startup_update_gate():
|
||||
@@ -117,6 +139,7 @@ def main() -> int:
|
||||
try:
|
||||
startup = chrome.ensure_configured_chrome_path()
|
||||
except (OSError, appconfig.ConfigError) as exc:
|
||||
update_health.write_health(health_context, "environment_blocked", str(exc))
|
||||
QMessageBox.critical(None, "启动配置错误", str(exc))
|
||||
return 1
|
||||
window = MainWindow(
|
||||
@@ -124,4 +147,8 @@ def main() -> int:
|
||||
startup_status=startup["message"],
|
||||
)
|
||||
window.show()
|
||||
QTimer.singleShot(
|
||||
0,
|
||||
lambda: update_health.write_health(health_context, "main_window_ready"),
|
||||
)
|
||||
return app.exec()
|
||||
|
||||
Reference in New Issue
Block a user