From 7648df05cd2e633cb54c546cc8692bd055918750 Mon Sep 17 00:00:00 2001 From: xionglinlin Date: Tue, 20 May 2025 11:37:45 +0800 Subject: [PATCH] fix: improve update checking mechanism and activation state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Changed default systemActivation state to true in UpdateModel for proper initialization 2. Added m_doCheckUpdates flag to prevent duplicate update checks 3. Modified update checking logic to use new activeUpdateModel signal instead of ActiveObjectChanged 4. Added count property and childrenChanged handler in update.qml to ensure proper timing for update checks 5. Simplified updateMain.qml to use direct signal connection for update checks The changes address several issues: - Prevents duplicate update checks when switching modules - Ensures update checks happen at the right time when entering the module - Improves initialization state management - Makes the update checking process more reliable and predictable fix: 改进更新检查机制和激活状态 1. 在UpdateModel中将默认systemActivation状态改为true以正确初始化 2. 添加m_doCheckUpdates标志防止重复检查更新 3. 修改更新检查逻辑,使用新的activeUpdateModel信号替代 ActiveObjectChanged 4. 在update.qml中添加count属性和childrenChanged处理程序以确保更新检查的 正确时机 5. 简化updateMain.qml,使用直接信号连接进行更新检查 这些更改解决了以下问题: - 防止切换模块时重复检查更新 - 确保进入模块时在正确时间检查更新 - 改进初始化状态管理 - 使更新检查过程更可靠和可预测 pms: Bug-316589 --- .../operation/updatemodel.cpp | 2 +- .../operation/updatework.cpp | 11 ++++++++++ src/dcc-update-plugin/operation/updatework.h | 1 + src/dcc-update-plugin/qml/update.qml | 21 +++++++++++++++++++ src/dcc-update-plugin/qml/updateMain.qml | 8 +++---- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/dcc-update-plugin/operation/updatemodel.cpp b/src/dcc-update-plugin/operation/updatemodel.cpp index 2f8dac556..5a97c22ef 100644 --- a/src/dcc-update-plugin/operation/updatemodel.cpp +++ b/src/dcc-update-plugin/operation/updatemodel.cpp @@ -36,7 +36,7 @@ UpdateModel::UpdateModel(QObject* parent) : QObject(parent) , m_lastoreDaemonStatus(0) , m_isUpdateDisabled(false) - , m_systemActivation(false) + , m_systemActivation(true) , m_batterIsOK(false) , m_lastStatus(Default) , m_showCheckUpdate(false) diff --git a/src/dcc-update-plugin/operation/updatework.cpp b/src/dcc-update-plugin/operation/updatework.cpp index bc569c104..a6ce0c7bf 100644 --- a/src/dcc-update-plugin/operation/updatework.cpp +++ b/src/dcc-update-plugin/operation/updatework.cpp @@ -107,6 +107,7 @@ UpdateWorker::UpdateWorker(UpdateModel* model, QObject* parent) , m_lastoreHeartBeatTimer(new QTimer(this)) , m_machineid(std::nullopt) , m_testingChannelUrl(std::nullopt) + , m_doCheckUpdates(false) , m_checkUpdateJob(nullptr) , m_fixErrorJob(nullptr) , m_downloadJob(nullptr) @@ -381,6 +382,12 @@ void UpdateWorker::checkNeedDoUpdates() return; } + // 如果当前正在检查更新,则不再检查 + if (m_doCheckUpdates) { + qCDebug(DCC_UPDATE_WORKER) << "Is doing check updates"; + return; + } + // 如果打开控制中心后第一次进入检查更新界面,则显示页面并进行检查 static bool doCheckFirst = true; if (doCheckFirst) { @@ -432,6 +439,7 @@ void UpdateWorker::doCheckUpdates() m_model->resetDownloadInfo(); // 在检查更新前重置数据,避免有上次检查的数据残留 + m_doCheckUpdates = true; QDBusPendingCall call = m_updateInter->UpdateSource(); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher] { @@ -440,6 +448,7 @@ void UpdateWorker::doCheckUpdates() qCWarning(DCC_UPDATE_WORKER) << "Check update failed, error: " << reply.error().message(); m_model->setLastStatus(UpdatesStatus::CheckingFailed, __LINE__); cleanLaStoreJob(m_checkUpdateJob); + m_doCheckUpdates = false; } else { const QString jobPath = reply.value().path(); qCInfo(DCC_UPDATE_WORKER) << "jobpath:" << jobPath; @@ -1352,6 +1361,7 @@ void UpdateWorker::onCheckUpdateStatusChanged(const QString& value) m_model->setLastStatus(CheckingFailed, __LINE__); m_model->setCheckUpdateStatus(CheckingFailed); deleteJob(m_checkUpdateJob); + m_doCheckUpdates = false; } } else if (value == "success" || value == "succeed") { auto watcher = new QDBusPendingCallWatcher(m_updateInter->GetUpdateLogs(SystemUpdate | SecurityUpdate), this); @@ -1374,6 +1384,7 @@ void UpdateWorker::onCheckUpdateStatusChanged(const QString& value) m_model->setCheckUpdateStatus(UpdatesStatus(m_model->lastStatus())); m_model->updateCheckUpdateUi(); deleteJob(m_checkUpdateJob); + m_doCheckUpdates = false; } } diff --git a/src/dcc-update-plugin/operation/updatework.h b/src/dcc-update-plugin/operation/updatework.h index 4a0d1248b..55da73db1 100644 --- a/src/dcc-update-plugin/operation/updatework.h +++ b/src/dcc-update-plugin/operation/updatework.h @@ -132,6 +132,7 @@ public Q_SLOTS: std::optional m_testingChannelUrl; QMutex m_downloadMutex; + bool m_doCheckUpdates; QPointer m_checkUpdateJob; QPointer m_fixErrorJob; QPointer m_downloadJob; diff --git a/src/dcc-update-plugin/qml/update.qml b/src/dcc-update-plugin/qml/update.qml index 2013e7d82..8e2f08de8 100644 --- a/src/dcc-update-plugin/qml/update.qml +++ b/src/dcc-update-plugin/qml/update.qml @@ -9,10 +9,31 @@ import org.deepin.dtk 1.0 as D import org.deepin.dcc 1.0 DccObject { + id: root + + property bool hasHandledChildrenChange: false + signal activeUpdateModel() + name: "update" parentName: "root" displayName: qsTr("System Update") description: qsTr("System update and upgrade") icon: "update" weight: 100 + + page: DccRightView{ + + // 切换模块时候,控件会重新创建,从而触发检查更新 + Component.onCompleted: { + activeUpdateModel(); + } + } + + // 通过dbus接口直接进入更新模块时,onCompleted已经发送了信号,但其子控件可能还没创建好,需要使用该信号触发检查更新,但只需要触发一次即可 + onChildrenChanged : { + if (!hasHandledChildrenChange) { + hasHandledChildrenChange = true + activeUpdateModel(); + } + } } diff --git a/src/dcc-update-plugin/qml/updateMain.qml b/src/dcc-update-plugin/qml/updateMain.qml index ee770bfe5..f9d35cd07 100644 --- a/src/dcc-update-plugin/qml/updateMain.qml +++ b/src/dcc-update-plugin/qml/updateMain.qml @@ -13,11 +13,9 @@ import org.deepin.dcc.update 1.0 DccObject { Connections { - target: DccApp - function onActiveObjectChanged(obj) { - if (obj === dccModule) { - dccData.work().checkNeedDoUpdates() - } + target: dccModule + function onActiveUpdateModel() { + dccData.work().checkNeedDoUpdates() } }