|
1 | | -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. |
| 1 | +// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd. |
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | 4 |
|
|
22 | 22 | #include <QLoggingCategory> |
23 | 23 |
|
24 | 24 | #include <cmath> |
25 | | -#include <thread> |
| 25 | +#include <QThreadPool> |
| 26 | +#include <QRunnable> |
26 | 27 |
|
27 | 28 | namespace tray { |
28 | 29 |
|
@@ -150,25 +151,25 @@ void DDEindicatorProtocolHandlerPrivate::initDBus() |
150 | 151 | } |
151 | 152 |
|
152 | 153 | const QJsonObject action = config.value("action").toObject(); |
153 | | - if (!action.isEmpty()) |
154 | | - q->connect(q, &DDEindicatorProtocolHandler::clicked, q, [ = ](uint8_t button_index, int x, int y) { |
155 | | - std::thread t([ = ] ()-> void { |
156 | | - auto triggerConfig = action.value("trigger").toObject(); |
157 | | - auto dbusService = triggerConfig.value("dbus_service").toString(); |
158 | | - auto dbusPath = triggerConfig.value("dbus_path").toString(); |
159 | | - auto dbusInterface = triggerConfig.value("dbus_interface").toString(); |
160 | | - auto methodName = triggerConfig.value("dbus_method").toString(); |
161 | | - auto isSystemBus = triggerConfig.value("system_dbus").toBool(false); |
| 154 | + if (!action.isEmpty()) { |
| 155 | + const auto triggerConfig = action.value("trigger").toObject(); |
| 156 | + const auto dbusService = triggerConfig.value("dbus_service").toString(); |
| 157 | + const auto dbusPath = triggerConfig.value("dbus_path").toString(); |
| 158 | + const auto dbusInterface = triggerConfig.value("dbus_interface").toString(); |
| 159 | + const auto methodName = triggerConfig.value("dbus_method").toString(); |
| 160 | + const auto isSystemBus = triggerConfig.value("system_dbus").toBool(false); |
| 161 | + |
| 162 | + q->connect(q, &DDEindicatorProtocolHandler::clicked, q, [=](uint8_t button_index, int x, int y) { |
| 163 | + QThreadPool::globalInstance()->start([=] { |
162 | 164 | auto bus = isSystemBus ? QDBusConnection::systemBus() : QDBusConnection::sessionBus(); |
163 | | - |
164 | 165 | QDBusInterface interface(dbusService, dbusPath, dbusInterface, bus); |
165 | 166 | QDBusReply<void> reply = interface.call(methodName, button_index, x, y); |
166 | 167 | if (!reply.isValid()) { |
167 | 168 | interface.call(methodName); |
168 | 169 | } |
169 | 170 | }); |
170 | | - t.detach(); |
171 | 171 | }); |
| 172 | + } |
172 | 173 | }); |
173 | 174 | } |
174 | 175 |
|
|
0 commit comments