Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.
C++
Add asynchronous startup update checks and transient release banner
Veyra Goal Agent0f9a61ee2d79
diff --git a/AGENTS.md b/AGENTS.mdindex f8ef8611..92faaa0e 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,5 +1,8 @@# Veyra 项目 Agent 执行规则+> **2026-10-13 更新检查授权**:用户要求真正检查更新、每次启动后台检查、新版本顶部小提示自动消失、无更新静默。按 docs/UPDATE_CHECK_PLAN_2026-10-13.md 隔离 codex/update-check-20261013,仅必要 UI 网络服务/bridge/QML/翻译/CMake/验收;覆盖这些接点旧冻结,70旧树/脏文件保护。保持引擎/运行库/用户配置及33ms/250ms刷新,不派Agent。产物全E盘,无main合并/push/Release/关机。++> **2026-10-13 2.0.7正式发布授权**:用户明确直接采用已验2.0.7-test-r2两个包发布GitHub、六群原图替换、README/Release加知识库、完整说明2.0.6以来变化。按docs/RELEASE_2.0.7_PLAN_2026-10-13.md,只改发布文档/图片和外部文件名,ZIP/EXE/运行组件逐字节保持。允许本地main合入、普通push nrvideo/main与两个标签、主v2.0.7两资产及独立非latest源码归档;保留原赞助/Discord/Ko-fi/width220。69旧树/509脏文件、旧包和旧Release保护,全产物E盘;无子Agent/代发/关机。不伪称包内test标识被去掉,不把混合模型取舍或合成误差包装成普遍画质/提速,也不宣称NV显存/BMD/HDR现场已根治。> **2026-10-12 用户确认 Claude 内容节奏修复实机通过并授权合并重打 2.0.7**:从 main05bc4b5 隔离合入 claude/cadence-exact-20261012(60a93f3、8d11cad),按 docs/TEST_2.0.7_REFRESH_2026-10-12.md 重新构建、定向回归、本地 main 合并与 NVIDIA/AMD 完整测试包;显示2.0.7-test-r2。保护68旧树/509脏文件及已交付原包,全部研发产物在E盘新任务目录。不改用户正在运行的播放器/配置、UI频率/默认GPU优先级/运行库/模型,无新push/Release/关机或子Agent授权。diff --git a/CMakeLists.txt b/CMakeLists.txtindex a0005884..8c9de3f3 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -946,13 +946,19 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformoption(VEYRA_BUILD_QT_PROBE "Build the Qt + D3D12 host probe" OFF)option(VEYRA_BUILD_QML_UI "Build the QML front end" OFF)if(VEYRA_BUILD_QT_PROBE OR VEYRA_BUILD_QML_UI)- find_package(Qt6 6.8 QUIET COMPONENTS Core Gui Qml Quick QuickControls2 Widgets)+ find_package(Qt6 6.8 QUIET COMPONENTS Core Gui Qml Quick QuickControls2 Widgets Network)endif()# The QML bridge. It is engine code (no QML files), so it compiles into a# separate small library rather than into veyra_engine: the product build must# never depend on Qt being installed.if(VEYRA_BUILD_QML_UI AND Qt6_FOUND)+ add_library(veyra_update_checker STATIC src/ui/UpdateChecker.cpp include/veyra/ui/UpdateChecker.h)+ set_target_properties(veyra_update_checker PROPERTIES AUTOMOC ON)+ target_compile_features(veyra_update_checker PUBLIC cxx_std_20)+ target_compile_options(veyra_update_checker PRIVATE /utf-8)+ target_include_directories(veyra_update_checker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)+ target_link_libraries(veyra_update_checker PUBLIC Qt6::Core Qt6::Gui Qt6::Network)add_library(veyra_qml_bridge STATIC src/ui/QmlExportQueueModel.cpp include/veyra/ui/QmlExportQueueModel.h src/ui/QmlPlayerBridge.cpp src/ui/ThumbnailProvider.cppsrc/ui/PlaylistModel.cpp include/veyra/ui/PlaylistModel.hinclude/veyra/ui/QmlPlayerBridge.h include/veyra/ui/ThumbnailProvider.h@@ -969,7 +975,7 @@ if(VEYRA_BUILD_QML_UI AND Qt6_FOUND)target_compile_options(veyra_ui_i18n PRIVATE /utf-8)target_include_directories(veyra_ui_i18n PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)target_link_libraries(veyra_ui_i18n PUBLIC veyra_base Qt6::Core)- target_link_libraries(veyra_qml_bridge PUBLIC veyra_ui_i18n)+ target_link_libraries(veyra_qml_bridge PUBLIC veyra_ui_i18n veyra_update_checker)add_executable(veyra_ui_i18n_tests tests/unit/UiLanguageTests.cpp)target_compile_options(veyra_ui_i18n_tests PRIVATE /utf-8)target_link_libraries(veyra_ui_i18n_tests PRIVATE veyra_ui_i18n)@@ -1016,6 +1022,10 @@ if(VEYRA_BUILD_QML_UI AND Qt6_FOUND)target_link_libraries(veyra_playlist_tests PRIVATE Qt6::Core)find_package(Qt6 COMPONENTS Test)if(TARGET Qt6::Test)+ add_executable(veyra_update_checker_tests tests/unit/UpdateCheckerTests.cpp)+ set_target_properties(veyra_update_checker_tests PROPERTIES AUTOMOC ON)+ target_compile_options(veyra_update_checker_tests PRIVATE /utf-8)+ target_link_libraries(veyra_update_checker_tests PRIVATE veyra_update_checker Qt6::Test)add_executable(veyra_playlist_window_tests tests/qml/PlaylistWindowTests.cpp)target_compile_features(veyra_playlist_window_tests PRIVATE cxx_std_20)target_compile_options(veyra_playlist_window_tests PRIVATE /utf-8)diff --git a/docs/UPDATE_CHECK_PLAN_2026-10-13.md b/docs/UPDATE_CHECK_PLAN_2026-10-13.mdnew file mode 100644index 00000000..cbe57d2d--- /dev/null+++ b/docs/UPDATE_CHECK_PLAN_2026-10-13.md@@ -0,0 +1,11 @@+# 更新检查(2026-10-13)++用户要求真正检查更新,每次启动自动检查;有新版本顶部短暂提示,无更新静默。起点 main7571919,隔离 codex/update-check-20261013;70旧工作树/脏文件及增量源码已存档 E:/项目/Veyra/archives/update-check-20261013。++只改 UI 更新服务、bridge、QML、翻译、必要 CMake/验证。无需修改引擎、运行库、模型、用户设置或33ms/250ms刷新节奏。新网络模块由现有 windeployqt 根据 imports 部署。产物全部 E:/项目/Veyra/{build,tests,logs,tmp,reports}/update-check-20261013。不派Agent、不合 main/push/发布或关机。++实现:界面就绪2.5秒后单次异步 GET GitHub /repos/Likely7/Veyra-NRVideo/releases/latest,无凭据;12秒总超时、128KiB响应上限、不重试。只接受非草稿/非预发布的 v数字.数字.数字,数值比较(当前 -test-r2 标识归一同版本),验证链接属于当前仓库正式标签。有更新显示8秒顶部提示,可点击发布页/关闭,设置页保留下载入口。自动无更新/失败均无提示,手动显示最新/失败/可用结果;并发点击合并为一个请求。++验收:独立本地 HTTP 服务覆盖新/同/旧版本、10与9数值比较、预发布/源码归档/无效JSON/外部URL、404/403、总超时、超大响应、自动静默/手动、并发/销毁;真实匿名 HTTPS GitHub 查询验证。Qt Quick 测顶部弹窗显示、8秒关闭、点击/窄屏;完整产品构建和私有配置启动。不得用本地夹具冒充真实远端查询,不生成完整测试包。++参考:GitHub REST releases latest https://docs.github.com/en/rest/releases/releases#get-the-latest-release;Qt6.8 QNetworkAccessManager https://doc.qt.io/qt-6.8/qnetworkaccessmanager.html。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 4abca2f6..e2e86ff1 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -9345,3 +9345,8 @@ ZIP/EXE原字节晋级,仅外部下载名去test-r2;包内显示原标识在v2.0.7 ID 410800361,published_at 2026-10-12T16:24:59Z,latest/非草稿/非预发布通过;两个运行资产服务器SHA/size等于原test-r2。v2.0.7-sources ID 410800322,两源资产、非latest,未变依赖源保留v2.0.6。main/tag6ede5a7普通atomic推送成功,产品与67ab696相同,后续只补回执文档。remote.py draft/upload/verify-draft/publish/verify-public均通过;public-check.py final全部公开文档/双QR/Ko-fi/Release/下载200,六群原图SHA吻合,飞书带Cookie匿名GET200。最初无Cookie404/循环证据保留,不把它写成知识库本身失效。旧v2.0.6Release完整稳定字段不变,68其它树/509脏文件/全部原包保护通过。详细docs/RELEASE_2.0.7_REPORT_2026-10-13.md;外部reports/logs回执固定远端正文/资产digest。只读发布辅助检查曾因utf8-sig别名和依赖回执尚未完成失败,原错误说明保留,改编码/顺序后原检查通过,未重发或改资产。原扩展NR+DLSS热切换失败和NV显存/BMD/HDR/AMD实卡限制保留,没有新性能或全硬件通过声明。群公告632字符仅保存给用户,无代发/关机。+++## 2026-10-13 更新检查开工++用户要求启动自动查新版并短暂顶部提示,无更新静默。起点main7571919,隔离codex/update-check-20261013;70旧树/脏文件与增量bundle存档verify通过。实施独立Qt Network异步服务/bridge/顶部8秒可点击提示/设置手动检查/四语。保持33ms/250ms、引擎和真实配置,产物全E盘。当前待构建、HTTP异常及真实GitHub/GUI验证,尚不称完成。详情UPDATE_CHECK_PLAN_2026-10-13.md。diff --git a/i18n/catalog.json b/i18n/catalog.jsonindex 4a7a569f..c3299e7b 100644--- a/i18n/catalog.json+++ b/i18n/catalog.json@@ -15716,6 +15716,48 @@"zh-TW": "{} {}X 補幀初始化失敗,未替換後端或降低倍率;請查看工作診斷日誌","en": "{} {}X frame generation could not initialize. The backend and multiplier were retained; see the task diagnostic log.","ja": "{} {}X フレーム生成を初期化できませんでした。バックエンドと倍率は維持されています。タスク診断ログを確認してください。"+ },+ {+ "zh": "发现新版本 %1",+ "src": "qml/Veyra/SettingsPage.qml",+ "zh-TW": "發現新版本 %1",+ "en": "New version %1 available",+ "ja": "新しいバージョン %1 があります"+ },+ {+ "zh": "发现新版本 %1,点击查看更新",+ "src": "qml/Veyra/UpdateBanner.qml",+ "zh-TW": "發現新版本 %1,點擊查看更新",+ "en": "Version %1 available. Click to view the update.",+ "ja": "バージョン %1 があります。クリックして更新を確認。"+ },+ {+ "zh": "启动时自动检查,有更新时提示",+ "src": "qml/Veyra/SettingsPage.qml",+ "zh-TW": "啟動時自動檢查,有更新時提示",+ "en": "Checks on startup; notifies when an update is available",+ "ja": "起動時に確認し、更新がある場合に通知します"+ },+ {+ "zh": "当前已是最新版本",+ "src": "src/ui/UpdateChecker.cpp",+ "zh-TW": "目前已是最新版本",+ "en": "You are up to date",+ "ja": "最新バージョンです"+ },+ {+ "zh": "查看更新",+ "src": "qml/Veyra/SettingsPage.qml",+ "zh-TW": "查看更新",+ "en": "View update",+ "ja": "更新を見る"+ },+ {+ "zh": "检查更新失败,请检查网络后重试",+ "src": "src/ui/UpdateChecker.cpp",+ "zh-TW": "檢查更新失敗,請檢查網路後重試",+ "en": "Could not check for updates. Check your connection and try again.",+ "ja": "更新を確認できませんでした。接続を確認して再試行してください。"}]}diff --git a/include/veyra/ui/QmlPlayerBridge.h b/include/veyra/ui/QmlPlayerBridge.hindex cf2d0a6d..5e8d369d 100644--- a/include/veyra/ui/QmlPlayerBridge.h+++ b/include/veyra/ui/QmlPlayerBridge.h@@ -102,6 +102,7 @@ class QmlPlayerBridge : public QObject {// The loaded runtime components, as the engine reports them. A hand-written// list here could drift from what the package actually contains.Q_PROPERTY(QVariantList componentList READ componentList NOTIFY snapshotChanged)+ Q_PROPERTY(QObject* updates READ updates CONSTANT)// --- capture dialog ----------------------------------------------------// Device and format lists come from the source's own enumeration, so the UI@@ -695,6 +696,7 @@ public:Q_INVOKABLE bool presentationOverlayRunning() const;Q_INVOKABLE void openFeedbackPage();Q_INVOKABLE void openReleasesPage();+ QObject* updates() const;QVariantList audioDevices() const;QVariantList gpuMonitorChoices() const;QString gpuMonitorName() const;@@ -1202,6 +1204,7 @@ private:struct Impl;std::unique_ptr<Impl> impl_;+ QObject* updates_ = nullptr;};} // namespace veyra::uidiff --git a/include/veyra/ui/UpdateChecker.h b/include/veyra/ui/UpdateChecker.hnew file mode 100644index 00000000..3517c8f2--- /dev/null+++ b/include/veyra/ui/UpdateChecker.h@@ -0,0 +1,46 @@+#pragma once+#include <QObject>+#include <QByteArray>+#include <QUrl>+#include <QTimer>+#include <QNetworkAccessManager>+#include <QNetworkReply>++namespace veyra::ui {+// UI-only, bounded asynchronous metadata request; never touches the engine.+class UpdateChecker final : public QObject {+ Q_OBJECT+ Q_PROPERTY(bool checking READ checking NOTIFY checkingChanged)+ Q_PROPERTY(QString latestVersion READ latestVersion NOTIFY releaseChanged)+ Q_PROPERTY(QUrl releaseUrl READ releaseUrl NOTIFY releaseChanged)+public:+ explicit UpdateChecker(QString currentVersion, QObject* parent = nullptr,+ QUrl endpoint = QUrl(QStringLiteral("https://api.github.com/repos/Likely7/Veyra-NRVideo/releases/latest")),+ int timeoutMs = 12000);+ ~UpdateChecker() override;+ bool checking() const { return reply_ != nullptr; }+ QString latestVersion() const { return latestVersion_; }+ QUrl releaseUrl() const { return releaseUrl_; }+ Q_INVOKABLE void startAutomaticCheck();+ Q_INVOKABLE void check(bool manual = true);+ Q_INVOKABLE void openRelease();+signals:+ void checkingChanged();+ void releaseChanged();+ void updateAvailable(const QString& version);+ void notice(const QString& message, bool isError);+ // Terminal diagnostic result (also used by deterministic/real HTTP tests).+ void completed(const QString& result);+private:+ void finish();+ QNetworkAccessManager network_;+ QTimer deadline_;+ QNetworkReply* reply_ = nullptr;+ QString currentVersion_, latestVersion_;+ QUrl endpoint_, releaseUrl_;+ QByteArray body_;+ QString failure_;+ int timeoutMs_;+ bool automaticScheduled_ = false, manual_ = false;+};+}diff --git a/qml/Veyra/Main.qml b/qml/Veyra/Main.qmlindex 6db286c2..5b2d6ec8 100644--- a/qml/Veyra/Main.qml+++ b/qml/Veyra/Main.qml@@ -634,6 +634,19 @@ Window {Shortcut { sequence: "Y"; onActivated: veyra.cycleSubtitle(true) }// Toasts: a refused edit, a finished export, a failed open.+ UpdateBanner {+ id: updateBanner+ z: 35+ anchors.top: parent.top+ anchors.topMargin: 12+ anchors.horizontalCenter: parent.horizontalCenter+ width: Math.min(500, root.width - 32)+ onOpenRequested: veyra.updates.openRelease()+ }+ Connections {+ target: veyra.updates+ function onUpdateAvailable(version) { updateBanner.show(version) }+ }// pages.css .canvas-toast: top 12px, padding 7px 12px, from translate -8px and// opacity 0; .on: opacity .2s, translate .45s --spring; hidden after 2600 ms.Rectangle {@@ -793,6 +806,7 @@ Window {}onClosing: if (!root.fullscreen && !root.maximized && !root.cinema) veyra.rememberWindowSize(root.width, root.height)Component.onCompleted: {+ veyra.updates.startAutomaticCheck()applyStartupSize()// Open on the configured page: the user's saved preference, or the// override a test passes on the command line.diff --git a/qml/Veyra/SettingsPage.qml b/qml/Veyra/SettingsPage.qmlindex 186f403c..850b583d 100644--- a/qml/Veyra/SettingsPage.qml+++ b/qml/Veyra/SettingsPage.qml@@ -957,8 +957,19 @@ VPage {VGroup {VRow {label: qsTr("检查更新")- hint: qsTr("GitHub · Likely7/Veyra-NRVideo · 发布页")- VButton { text: qsTr("检查"); onClicked: veyra.openReleasesPage() }+ hint: veyra.updates.latestVersion.length > 0+ ? qsTr("发现新版本 %1").arg(veyra.updates.latestVersion)+ : qsTr("启动时自动检查,有更新时提示")+ VButton {+ text: veyra.updates.checking ? qsTr("检查中…") : qsTr("检查")+ enabled: !veyra.updates.checking+ onClicked: veyra.updates.check(true)+ }+ VButton {+ visible: veyra.updates.latestVersion.length > 0+ text: qsTr("查看更新")+ onClicked: veyra.updates.openRelease()+ }}VRow {label: qsTr("反馈问题")diff --git a/qml/Veyra/UpdateBanner.qml b/qml/Veyra/UpdateBanner.qmlnew file mode 100644index 00000000..cb287b23--- /dev/null+++ b/qml/Veyra/UpdateBanner.qml@@ -0,0 +1,53 @@+import QtQuick+import QtQuick.Controls++Rectangle {+ id: banner+ // The native video host subtracts visible videoCover items from its region.+ objectName: "videoCover"+ property real coverRadius: 10+ property string version: ""+ property bool shown: false+ signal openRequested()+ width: 500+ height: Math.max(54, message.implicitHeight + 24)+ radius: 10+ color: "#17251E"+ border.color: "#426C51"+ visible: shown+ function show(value) { version = value; shown = true; dismissTimer.restart() }+ function dismiss() { shown = false; dismissTimer.stop() }+ // One-shot only: idle UI and playback render rates are unchanged.+ Timer { id: dismissTimer; interval: 8000; onTriggered: banner.shown = false }+ MouseArea {+ anchors.fill: parent+ cursorShape: Qt.PointingHandCursor+ onClicked: { banner.openRequested(); banner.dismiss() }+ }+ Text {+ id: message+ anchors.left: parent.left+ anchors.leftMargin: 16+ anchors.right: closeButton.left+ anchors.rightMargin: 8+ anchors.verticalCenter: parent.verticalCenter+ text: qsTr("发现新版本 %1,点击查看更新").arg(banner.version)+ color: "#D5F3DE"+ font.family: Theme.fontUi+ font.pixelSize: Theme.fsBody+ wrapMode: Text.WordWrap+ textFormat: Text.PlainText+ }+ VButton {+ id: closeButton+ objectName: "update-dismiss"+ anchors.right: parent.right+ anchors.rightMargin: 8+ anchors.verticalCenter: parent.verticalCenter+ icon: true+ iconName: "x"+ ghost: true+ tip: qsTr("关闭")+ onClicked: banner.dismiss()+ }+}diff --git a/qml/Veyra/qmldir b/qml/Veyra/qmldirindex b1c15c58..53fd949e 100644--- a/qml/Veyra/qmldir+++ b/qml/Veyra/qmldir@@ -1,4 +1,5 @@module Veyra+UpdateBanner 1.0 UpdateBanner.qmlPlaylistWindow 1.0 PlaylistWindow.qmlPlaybackRateButton 1.0 PlaybackRateButton.qmlPlaybackRateDialog 1.0 PlaybackRateDialog.qmldiff --git a/src/ui/QmlPlayerBridge.cpp b/src/ui/QmlPlayerBridge.cppindex e6bd74a4..cb553a6b 100644--- a/src/ui/QmlPlayerBridge.cpp+++ b/src/ui/QmlPlayerBridge.cpp@@ -5,6 +5,7 @@#include "veyra/engine/FrameGenerationSelection.h"#include "veyra/ui/QmlExportQueueModel.h"#include "veyra/ui/PlaylistModel.h"+#include "veyra/ui/UpdateChecker.h"#include "veyra/ui/UiLanguage.h"#include <QQmlEngine>#include <QMetaMethod>@@ -1064,6 +1065,9 @@ QVariantList QmlPlayerBridge::srBackendChoices() const {QmlPlayerBridge::QmlPlayerBridge(engine::EngineController& engine, std::filesystem::path dataDirectory,QObject* parent): QObject(parent), impl_(std::make_unique<Impl>(engine, std::move(dataDirectory))) {+ auto* checker = new UpdateChecker(version(), this);+ updates_ = checker;+ connect(checker, &UpdateChecker::notice, this, &QmlPlayerBridge::notice);impl_->playlist = new PlaylistModel(utf8Of((impl_->dataDir / L"playlist.v1.json").wstring()), this);connect(impl_->playlist, &PlaylistModel::playRequested, this, [this](const QString& path) {openPath(path);@@ -5519,6 +5523,7 @@ void QmlPlayerBridge::openFeedbackPage() {void QmlPlayerBridge::openReleasesPage() {QDesktopServices::openUrl(QUrl(QStringLiteral("https://github.com/Likely7/Veyra-NRVideo/releases")));}+QObject* QmlPlayerBridge::updates() const { return updates_; }bool QmlPlayerBridge::eventFilter(QObject* watched, QEvent* event) {const auto type = event->type();if (type == QEvent::KeyPress || type == QEvent::KeyRelease) {diff --git a/src/ui/UpdateChecker.cpp b/src/ui/UpdateChecker.cppnew file mode 100644index 00000000..850f6a14--- /dev/null+++ b/src/ui/UpdateChecker.cpp@@ -0,0 +1,112 @@+#include "veyra/ui/UpdateChecker.h"+#include <QDesktopServices>+#include <QJsonDocument>+#include <QJsonObject>+#include <QNetworkRequest>+#include <QRegularExpression>+#include <QVersionNumber>+#include <QDebug>++namespace veyra::ui {+namespace {+constexpr qsizetype maxBody = 128 * 1024;+QVersionNumber versionNumber(const QString& text, bool local) {+ static const QRegularExpression stable(QStringLiteral("^v?([0-9]+\\.[0-9]+\\.[0-9]+)$"));+ static const QRegularExpression installed(QStringLiteral("^v?([0-9]+\\.[0-9]+\\.[0-9]+)(?:\\.0)?(?:-[A-Za-z0-9.-]+)?$"));+ const auto match = (local ? installed : stable).match(text);+ return match.hasMatch() ? QVersionNumber::fromString(match.captured(1)) : QVersionNumber{};+}+}+UpdateChecker::UpdateChecker(QString currentVersion, QObject* parent, QUrl endpoint, int timeoutMs)+ : QObject(parent), currentVersion_(std::move(currentVersion)), endpoint_(std::move(endpoint)), timeoutMs_(timeoutMs) {+ deadline_.setSingleShot(true);+ connect(&deadline_, &QTimer::timeout, this, [this] {+ if (reply_) { failure_ = QStringLiteral("timeout"); reply_->abort(); }+ });+}+UpdateChecker::~UpdateChecker() {+ deadline_.stop();+ if (reply_) {+ reply_->disconnect(this);+ reply_->abort();+ }+}+void UpdateChecker::startAutomaticCheck() {+ if (automaticScheduled_) return;+ automaticScheduled_ = true;+ QTimer::singleShot(2500, this, [this] {+ // A manual check made during startup already fulfils this run's check.+ if (!checking() && !manual_) check(false);+ });+}+void UpdateChecker::check(bool manual) {+ if (checking()) { manual_ = manual_ || manual; return; }+ manual_ = manual;+ body_.clear(); failure_.clear();+ QNetworkRequest request(endpoint_);+ request.setRawHeader("Accept", "application/vnd.github+json");+ request.setRawHeader("User-Agent", "Veyra-Update-Check");+ request.setRawHeader("X-GitHub-Api-Version", "2022-11-28");+ request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);+ request.setMaximumRedirectsAllowed(3);+ request.setTransferTimeout(timeoutMs_);+ reply_ = network_.get(request);+ reply_->setReadBufferSize(maxBody + 1);+ connect(reply_, &QIODevice::readyRead, this, [this] {+ body_ += reply_->read(maxBody + 1 - body_.size());+ if (body_.size() > maxBody) { failure_ = QStringLiteral("response-too-large"); reply_->abort(); }+ });+ connect(reply_, &QNetworkReply::finished, this, &UpdateChecker::finish);+ deadline_.start(timeoutMs_);+ emit checkingChanged();+}+void UpdateChecker::finish() {+ deadline_.stop();+ auto* reply = reply_;+ body_ += reply->read(maxBody + 1 - body_.size());+ if (body_.size() > maxBody) failure_ = QStringLiteral("response-too-large");+ const int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();+ if (failure_.isEmpty() && (reply->error() != QNetworkReply::NoError || status != 200))+ failure_ = QStringLiteral("http-%1-network-%2").arg(status).arg(int(reply->error()));+ reply_ = nullptr;+ reply->deleteLater();+ QString result;+ if (failure_.isEmpty()) {+ QJsonParseError error;+ const auto document = QJsonDocument::fromJson(body_, &error);+ const auto obj = document.object();+ const auto tag = obj.value(QStringLiteral("tag_name")).toString();+ const auto remote = versionNumber(tag, false), local = versionNumber(currentVersion_, true);+ const QUrl url(obj.value(QStringLiteral("html_url")).toString());+ const bool validUrl = url.scheme() == QStringLiteral("https") && url.host() == QStringLiteral("github.com")+ && url.userInfo().isEmpty() && url.port(-1) == -1 && !url.hasQuery() && !url.hasFragment()+ && url.path() == QStringLiteral("/Likely7/Veyra-NRVideo/releases/tag/") + tag;+ if (error.error != QJsonParseError::NoError || !document.isObject()+ || !obj.value(QStringLiteral("draft")).isBool() || obj.value(QStringLiteral("draft")).toBool()+ || !obj.value(QStringLiteral("prerelease")).isBool() || obj.value(QStringLiteral("prerelease")).toBool()+ || local.segmentCount() != 3 || remote.segmentCount() != 3 || !validUrl) {+ failure_ = QStringLiteral("invalid-release");+ } else if (QVersionNumber::compare(remote, local) > 0) {+ latestVersion_ = remote.toString(); releaseUrl_ = url;+ emit releaseChanged();+ emit updateAvailable(latestVersion_);+ result = QStringLiteral("available");+ } else {+ latestVersion_.clear(); releaseUrl_.clear(); emit releaseChanged();+ if (manual_) emit notice(tr("当前已是最新版本"), false);+ result = QStringLiteral("current");+ }+ }+ if (!failure_.isEmpty()) {+ if (manual_) emit notice(tr("检查更新失败,请检查网络后重试"), true);+ result = failure_;+ }+ body_.clear();+ qInfo().noquote() << "[update-check]" << result;+ emit checkingChanged();+ emit completed(result);+}+void UpdateChecker::openRelease() {+ if (!releaseUrl_.isEmpty()) QDesktopServices::openUrl(releaseUrl_);+}+}diff --git a/tests/qml/quick/tst_update_banner.qml b/tests/qml/quick/tst_update_banner.qmlnew file mode 100644index 00000000..3f89bf68--- /dev/null+++ b/tests/qml/quick/tst_update_banner.qml@@ -0,0 +1,38 @@+import QtQuick+import QtTest+import Veyra++Item {+ width: 620; height: 250+ UpdateBanner { id: banner; anchors.centerIn: parent }+ SignalSpy { id: opened; target: banner; signalName: "openRequested" }+ TestCase {+ name: "UpdateBanner"+ when: windowShown+ function cleanup() { banner.dismiss(); banner.width = 500; opened.clear() }+ function test_defaultSilent() { compare(banner.visible, false) }+ function test_click() {+ banner.show("2.0.8")+ compare(banner.visible, true)+ mouseClick(banner, 30, banner.height / 2)+ compare(opened.count, 1)+ compare(banner.visible, false)+ }+ function test_close() {+ banner.show("2.0.8")+ const close = findChild(banner, "update-dismiss")+ mouseClick(close, close.width / 2, close.height / 2)+ compare(opened.count, 0)+ compare(banner.visible, false)+ }+ function test_timeoutAndNarrow() {+ banner.width = 230+ banner.show("2.0.100")+ verify(banner.height >= 54)+ wait(7500)+ compare(banner.visible, true)+ tryCompare(banner, "visible", false, 1200)+ compare(opened.count, 0)+ }+ }+}diff --git a/tests/unit/UpdateCheckerTests.cpp b/tests/unit/UpdateCheckerTests.cppnew file mode 100644index 00000000..193144e0--- /dev/null+++ b/tests/unit/UpdateCheckerTests.cpp@@ -0,0 +1,149 @@+#include "veyra/ui/UpdateChecker.h"+#include <QCoreApplication>+#include <QJsonDocument>+#include <QJsonObject>+#include <QSignalSpy>+#include <QTcpServer>+#include <QTcpSocket>+#include <QtTest>+#include <memory>++using veyra::ui::UpdateChecker;+namespace {+QByteArray release(QString tag = QStringLiteral("v2.0.8"), bool prerelease = false, bool draft = false,+ QString url = {}) {+ if (url.isEmpty()) url = QStringLiteral("https://github.com/Likely7/Veyra-NRVideo/releases/tag/") + tag;+ return QJsonDocument(QJsonObject{{"tag_name", tag}, {"draft", draft}, {"prerelease", prerelease},+ {"html_url", url}}).toJson();+}+class Server : public QTcpServer {+public:+ QByteArray body = release(), request;+ int status = 200, requests = 0;+ bool hang = false;+ Server() {+ if (!listen(QHostAddress::LocalHost)) qFatal("Cannot listen on localhost");+ connect(this, &QTcpServer::newConnection, this, [this] {+ while (hasPendingConnections()) {+ auto* socket = nextPendingConnection();+ auto header = std::make_shared<QByteArray>();+ connect(socket, &QTcpSocket::disconnected, socket, &QObject::deleteLater);+ connect(socket, &QTcpSocket::readyRead, socket, [this, socket, header] {+ *header += socket->readAll();+ if (!header->contains("\r\n\r\n")) return;+ socket->disconnect(socket, &QTcpSocket::readyRead, nullptr, nullptr);+ ++requests; request = *header;+ if (hang) return;+ socket->write("HTTP/1.1 " + QByteArray::number(status) + " Test\r\nContent-Type: application/json\r\nContent-Length: "+ + QByteArray::number(body.size()) + "\r\nConnection: close\r\n\r\n" + body);+ socket->disconnectFromHost();+ });+ }+ });+ }+ QUrl endpoint() const { return QUrl(QStringLiteral("http://127.0.0.1:%1/latest").arg(serverPort())); }+};+}+class UpdateCheckerTests : public QObject {+ Q_OBJECT+private slots:+ void response_data() {+ QTest::addColumn<QString>("local"); QTest::addColumn<QByteArray>("body");+ QTest::addColumn<int>("http"); QTest::addColumn<QString>("result");+ QTest::newRow("new") << "2.0.7" << release() << 200 << "available";+ QTest::newRow("same-test-r2") << "2.0.7-test-r2" << release("v2.0.7") << 200 << "current";+ QTest::newRow("same") << "2.0.7" << release("v2.0.7") << 200 << "current";+ QTest::newRow("old") << "2.0.9" << release() << 200 << "current";+ QTest::newRow("numeric-10-over-9") << "2.0.9" << release("v2.0.10") << 200 << "available";+ QTest::newRow("numeric-9-below-10") << "2.0.10" << release("v2.0.9") << 200 << "current";+ QTest::newRow("major") << "2.99.99" << release("v3.0.0") << 200 << "available";+ QTest::newRow("four-component-local") << "2.0.7.0" << release() << 200 << "available";+ QTest::newRow("draft") << "2.0.7" << release("v2.0.8", false, true) << 200 << "invalid-release";+ QTest::newRow("prerelease") << "2.0.7" << release("v2.0.8", true) << 200 << "invalid-release";+ QTest::newRow("beta-tag") << "2.0.7" << release("v2.0.8-beta") << 200 << "invalid-release";+ QTest::newRow("sources-tag") << "2.0.7" << release("v2.0.8-sources") << 200 << "invalid-release";+ QTest::newRow("json") << "2.0.7" << QByteArray("not json") << 200 << "invalid-release";+ QTest::newRow("array") << "2.0.7" << QByteArray("[]") << 200 << "invalid-release";+ QTest::newRow("missing-fields") << "2.0.7" << QByteArray("{\"tag_name\":\"v2.0.8\"}") << 200 << "invalid-release";+ QTest::newRow("untrusted-link") << "2.0.7" << release("v2.0.8", false, false, "https://example.com/update") << 200 << "invalid-release";+ QTest::newRow("other-repo") << "2.0.7" << release("v2.0.8", false, false, "https://github.com/other/repo/releases/tag/v2.0.8") << 200 << "invalid-release";+ QTest::newRow("mismatched-tag") << "2.0.7" << release("v2.0.8", false, false, "https://github.com/Likely7/Veyra-NRVideo/releases/tag/v2.0.9") << 200 << "invalid-release";+ QTest::newRow("overflow") << "2.0.7" << release("v2.0.2147483648") << 200 << "invalid-release";+ QTest::newRow("unknown-local") << "dev" << release() << 200 << "invalid-release";+ QTest::newRow("404") << "2.0.7" << release() << 404 << "http-404-network-203";+ QTest::newRow("rate-limit") << "2.0.7" << release() << 403 << "http-403-network-201";+ QTest::newRow("too-large") << "2.0.7" << QByteArray(128*1024+1, 'x') << 200 << "response-too-large";+ }+ void response() {+ QFETCH(QString, local); QFETCH(QByteArray, body); QFETCH(int, http); QFETCH(QString, result);+ for (bool manual : {false, true}) {+ Server server; server.body = body; server.status = http;+ UpdateChecker checker(local, nullptr, server.endpoint());+ QSignalSpy done(&checker, &UpdateChecker::completed), available(&checker, &UpdateChecker::updateAvailable),+ notices(&checker, &UpdateChecker::notice);+ checker.check(manual);+ QVERIFY(checker.checking());+ QTRY_COMPARE_WITH_TIMEOUT(done.size(), 1, 3000);+ QCOMPARE(done[0][0].toString(), result);+ QCOMPARE(checker.checking(), false);+ QCOMPARE(server.requests, 1);+ QCOMPARE(available.size(), result == "available" ? 1 : 0);+ QCOMPARE(notices.size(), manual && result != "available" ? 1 : 0);+ QVERIFY(server.request.contains("User-Agent: Veyra-Update-Check"));+ QVERIFY(!server.request.contains("Authorization:"));+ if (result == "available") {+ QVERIFY(!checker.latestVersion().isEmpty()); QVERIFY(!checker.releaseUrl().isEmpty());+ } else { QVERIFY(checker.latestVersion().isEmpty()); QVERIFY(checker.releaseUrl().isEmpty()); }+ }+ }+ void timeoutAndCoalescing() {+ Server server; server.hang = true;+ UpdateChecker checker("2.0.7", nullptr, server.endpoint(), 200);+ QSignalSpy done(&checker, &UpdateChecker::completed), notices(&checker, &UpdateChecker::notice);+ checker.check(false); checker.check(true); checker.check(true);+ QTRY_COMPARE_WITH_TIMEOUT(done.size(), 1, 2000);+ QCOMPARE(server.requests, 1); QCOMPARE(notices.size(), 1);+ QCOMPARE(done[0][0].toString(), QString("timeout"));+ checker.check(false);+ QTRY_COMPARE_WITH_TIMEOUT(done.size(), 2, 2000);+ QCOMPARE(server.requests, 2); QCOMPARE(notices.size(), 1);+ }+ void startupOnce() {+ Server server; server.body = release("v2.0.7");+ UpdateChecker checker("2.0.7-test-r2", nullptr, server.endpoint());+ QSignalSpy done(&checker, &UpdateChecker::completed), notices(&checker, &UpdateChecker::notice);+ checker.startAutomaticCheck(); checker.startAutomaticCheck();+ QCOMPARE(server.requests, 0);+ QTRY_COMPARE_WITH_TIMEOUT(done.size(), 1, 4000);+ checker.startAutomaticCheck(); QTest::qWait(2700);+ QCOMPARE(server.requests, 1); QCOMPARE(notices.size(), 0);+ }+ void manualBeforeStartup() {+ Server server;+ UpdateChecker checker("2.0.7", nullptr, server.endpoint());+ QSignalSpy done(&checker, &UpdateChecker::completed);+ checker.startAutomaticCheck(); checker.check(true);+ QTRY_COMPARE_WITH_TIMEOUT(done.size(), 1, 3000);+ QTest::qWait(2700); QCOMPARE(server.requests, 1);+ }+ void destructionInFlight() {+ Server server; server.hang = true;+ auto checker = std::make_unique<UpdateChecker>("2.0.7", nullptr, server.endpoint());+ checker->startAutomaticCheck(); checker->check(false);+ QTRY_COMPARE(server.requests, 1);+ checker.reset(); QTest::qWait(2700); QCOMPARE(server.requests, 1);+ }+};+int main(int argc, char** argv) {+ QCoreApplication app(argc, argv);+ if (app.arguments().contains("--live")) {+ UpdateChecker checker("2.0.7-test-r2");+ QObject::connect(&checker, &UpdateChecker::completed, &app, [&](const QString& result) {+ qInfo().noquote() << "LIVE GitHub result:" << result << "version:" << checker.latestVersion();+ app.exit(result == "current" || result == "available" ? 0 : 1);+ });+ checker.check(false); return app.exec();+ }+ UpdateCheckerTests tests; return QTest::qExec(&tests, argc, argv);+}+#include "UpdateCheckerTests.moc"