Skip to content

Commit 2e5ba9d

Browse files
committed
fix: improve update checking mechanism and activation state
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
1 parent 5a478a5 commit 2e5ba9d

5 files changed

Lines changed: 39 additions & 6 deletions

File tree

src/dcc-update-plugin/operation/updatemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ UpdateModel::UpdateModel(QObject* parent)
3636
: QObject(parent)
3737
, m_lastoreDaemonStatus(0)
3838
, m_isUpdateDisabled(false)
39-
, m_systemActivation(false)
39+
, m_systemActivation(true)
4040
, m_batterIsOK(false)
4141
, m_lastStatus(Default)
4242
, m_showCheckUpdate(false)

src/dcc-update-plugin/operation/updatework.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ UpdateWorker::UpdateWorker(UpdateModel* model, QObject* parent)
107107
, m_lastoreHeartBeatTimer(new QTimer(this))
108108
, m_machineid(std::nullopt)
109109
, m_testingChannelUrl(std::nullopt)
110+
, m_doCheckUpdates(false)
110111
, m_checkUpdateJob(nullptr)
111112
, m_fixErrorJob(nullptr)
112113
, m_downloadJob(nullptr)
@@ -381,6 +382,12 @@ void UpdateWorker::checkNeedDoUpdates()
381382
return;
382383
}
383384

385+
// 如果当前正在检查更新,则不再检查
386+
if (m_doCheckUpdates) {
387+
qCDebug(DCC_UPDATE_WORKER) << "Is doing check updates";
388+
return;
389+
}
390+
384391
// 如果打开控制中心后第一次进入检查更新界面,则显示页面并进行检查
385392
static bool doCheckFirst = true;
386393
if (doCheckFirst) {
@@ -432,6 +439,7 @@ void UpdateWorker::doCheckUpdates()
432439

433440
m_model->resetDownloadInfo(); // 在检查更新前重置数据,避免有上次检查的数据残留
434441

442+
m_doCheckUpdates = true;
435443
QDBusPendingCall call = m_updateInter->UpdateSource();
436444
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(call, this);
437445
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher] {
@@ -440,6 +448,7 @@ void UpdateWorker::doCheckUpdates()
440448
qCWarning(DCC_UPDATE_WORKER) << "Check update failed, error: " << reply.error().message();
441449
m_model->setLastStatus(UpdatesStatus::CheckingFailed, __LINE__);
442450
cleanLaStoreJob(m_checkUpdateJob);
451+
m_doCheckUpdates = false;
443452
} else {
444453
const QString jobPath = reply.value().path();
445454
qCInfo(DCC_UPDATE_WORKER) << "jobpath:" << jobPath;
@@ -1352,6 +1361,7 @@ void UpdateWorker::onCheckUpdateStatusChanged(const QString& value)
13521361
m_model->setLastStatus(CheckingFailed, __LINE__);
13531362
m_model->setCheckUpdateStatus(CheckingFailed);
13541363
deleteJob(m_checkUpdateJob);
1364+
m_doCheckUpdates = false;
13551365
}
13561366
} else if (value == "success" || value == "succeed") {
13571367
auto watcher = new QDBusPendingCallWatcher(m_updateInter->GetUpdateLogs(SystemUpdate | SecurityUpdate), this);
@@ -1374,6 +1384,7 @@ void UpdateWorker::onCheckUpdateStatusChanged(const QString& value)
13741384
m_model->setCheckUpdateStatus(UpdatesStatus(m_model->lastStatus()));
13751385
m_model->updateCheckUpdateUi();
13761386
deleteJob(m_checkUpdateJob);
1387+
m_doCheckUpdates = false;
13771388
}
13781389
}
13791390

src/dcc-update-plugin/operation/updatework.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public Q_SLOTS:
132132
std::optional<QUrl> m_testingChannelUrl;
133133
QMutex m_downloadMutex;
134134

135+
bool m_doCheckUpdates;
135136
QPointer<UpdateJobDBusProxy> m_checkUpdateJob;
136137
QPointer<UpdateJobDBusProxy> m_fixErrorJob;
137138
QPointer<UpdateJobDBusProxy> m_downloadJob;

src/dcc-update-plugin/qml/update.qml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,33 @@ import org.deepin.dtk 1.0 as D
99
import org.deepin.dcc 1.0
1010

1111
DccObject {
12+
id: root
13+
14+
property real count : 0
15+
signal activeUpdateModel()
16+
1217
name: "update"
1318
parentName: "root"
1419
displayName: qsTr("System Update")
1520
description: qsTr("System update and upgrade")
1621
icon: "update"
1722
weight: 100
23+
24+
page: DccRightView{
25+
26+
// 切换模块时候,控件会重新创建,从而触发检查更新
27+
Component.onCompleted: {
28+
count++
29+
activeUpdateModel();
30+
}
31+
}
32+
33+
// 通过dbus接口直接进入更新模块时,onCompleted已经发送了信号,但其子控件可能还没创建好,需要使用该信号触发检查更新,
34+
// count计数是为了避免多次执行,
35+
onChildrenChanged : {
36+
if (count == 1) {
37+
count++
38+
activeUpdateModel();
39+
}
40+
}
1841
}

src/dcc-update-plugin/qml/updateMain.qml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import org.deepin.dcc.update 1.0
1313
DccObject {
1414

1515
Connections {
16-
target: DccApp
17-
function onActiveObjectChanged(obj) {
18-
if (obj === dccModule) {
19-
dccData.work().checkNeedDoUpdates()
20-
}
16+
target: dccModule
17+
function onActiveUpdateModel() {
18+
dccData.work().checkNeedDoUpdates()
2119
}
2220
}
2321

0 commit comments

Comments
 (0)