Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions dcc-network/operation/dccnetwork.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dccnetwork.h"
Expand Down Expand Up @@ -33,9 +33,16 @@ DccNetwork::DccNetwork(QObject *parent)
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
}

DccNetwork::~DccNetwork()
{
if (m_manager) {
disconnect(m_manager, &NetManager::request, this, &DccNetwork::request);
}
}

NetItem *DccNetwork::root() const
{
return m_manager->root();
return m_manager ? m_manager->root() : nullptr;
}

bool DccNetwork::CheckPasswordValid(const QString &key, const QString &password)
Expand Down
3 changes: 2 additions & 1 deletion dcc-network/operation/dccnetwork.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef DCCNETWORK_H
Expand All @@ -23,6 +23,7 @@ class DccNetwork : public QObject

public:
explicit DccNetwork(QObject *parent = nullptr);
~DccNetwork() override;
NetItem *root() const;
Q_INVOKABLE static bool CheckPasswordValid(const QString &key, const QString &password);

Expand Down
22 changes: 18 additions & 4 deletions net-view/operation/private/netmanagerthreadprivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ NetManagerThreadPrivate::NetManagerThreadPrivate()
, m_netCheckAvailable(false)
, m_isSleeping(false)
, m_showPageTimer(nullptr)
, m_vpnStateUpdateTimer(nullptr)
, m_supportWireless(false)
{
moveToThread(m_thread);
Expand All @@ -106,12 +107,15 @@ NetManagerThreadPrivate::NetManagerThreadPrivate()

NetManagerThreadPrivate::~NetManagerThreadPrivate()
{
// 先断开所有信号,防止析构期间再有新任务(如singleShot)入队
disconnect();
m_thread->quit();
m_thread->wait(QDeadlineTimer(200));
// 增大等待时间至1000ms,避免50ms定时器回调等正在执行的任务被terminate强杀
m_thread->wait(QDeadlineTimer(1000));
if (m_thread->isRunning()) {
m_thread->terminate();
}
m_thread->wait(QDeadlineTimer(200));
m_thread->wait(QDeadlineTimer(500));
delete m_thread;
}

Expand Down Expand Up @@ -416,6 +420,9 @@ void NetManagerThreadPrivate::doInit()
}
Q_EMIT itemAdded("Root", vpnControlItem);

m_vpnStateUpdateTimer = new QTimer(this);
m_vpnStateUpdateTimer->setSingleShot(true);
m_vpnStateUpdateTimer->setInterval(55);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

控制中心已有55的定时器,改为54、56这种
//设置kwin接口后, 等待55ms给kwin反应,根据isEffectLoaded返回值确定真实状态
QTimer::singleShot(55, this, [this] {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

时间算了吧,测试崩溃的时候的控制中心已经改了,说明不是控制中心那些更改的问题,

auto updateVPNConnectionState = [this]() {
auto itemList = NetworkController::instance()->vpnController()->items();
NetType::NetDeviceStatus state = NetType::DS_Disconnected;
Expand All @@ -431,8 +438,10 @@ void NetManagerThreadPrivate::doInit()
}
Q_EMIT dataChanged(DataChanged::VPNConnectionStateChanged, "NetVPNControlItem", QVariant::fromValue(state));
};
auto vpnConnectionStateChanged = [this, updateVPNConnectionState] {
QTimer::singleShot(50, this, updateVPNConnectionState);
connect(m_vpnStateUpdateTimer, &QTimer::timeout, this, updateVPNConnectionState);
auto vpnConnectionStateChanged = [this] {
// 使用成员定时器,重复触发时自动重置计时,防止多次触发累积
m_vpnStateUpdateTimer->start();
};

auto vpnItemChanged = [this, vpnConnectionStateChanged] {
Expand Down Expand Up @@ -596,6 +605,11 @@ void NetManagerThreadPrivate::clearData()
delete m_autoScanTimer;
m_autoScanTimer = nullptr;
}
if (m_vpnStateUpdateTimer) {
m_vpnStateUpdateTimer->stop();
delete m_vpnStateUpdateTimer;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议用deleteLater

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image 有特殊含义么?

m_vpnStateUpdateTimer = nullptr;
}
if (m_secretAgent) {
delete m_secretAgent;
m_secretAgent = nullptr;
Expand Down
1 change: 1 addition & 0 deletions net-view/operation/private/netmanagerthreadprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ protected Q_SLOTS:
QMap<NetworkDetails *, QString> m_detailsItemsMap; // 存储 NetworkDetails 指针到唯一ID的映射
QString m_showPageCmd;
QTimer *m_showPageTimer;
QTimer *m_vpnStateUpdateTimer;
QString m_newVPNuuid;
bool m_supportWireless;
};
Expand Down
11 changes: 8 additions & 3 deletions src/networkcontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -18,6 +18,8 @@
#include "wirelessdevice.h"
#include "connectivityhandler.h"

#include <QGlobalStatic>

Check warning on line 21 in src/networkcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGlobalStatic> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// const static QString networkService = "org.deepin.dde.Network1";
// const static QString networkPath = "/org/deepin/dde/Network1";
static QString localeName;
Expand Down Expand Up @@ -102,10 +104,12 @@

NetworkController::~NetworkController() = default;

// 文件级互斥锁,instance() 和 free() 共用,防止数据竞争
Q_GLOBAL_STATIC(QMutex, s_networkControllerMutex)

NetworkController *NetworkController::instance()
{
static QMutex m;
QMutexLocker locker(&m);
QMutexLocker locker(s_networkControllerMutex());
if (!m_networkController) {
m_networkController = new NetworkController;
};
Expand All @@ -114,6 +118,7 @@

void NetworkController::free()
{
QMutexLocker locker(s_networkControllerMutex());
if (m_networkController) {
m_networkController->deleteLater();
m_networkController = nullptr;
Expand Down
Loading