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() } }