Skip to content

Commit 977a976

Browse files
18202781743deepin-bot[bot]
authored andcommitted
refactor: move XdgActivation to pluginitem and simplify dock plugins
1. Remove XdgActivation usage from all dock plugins (airplane, bluetooth, brightness, datetime, dnd, eye-comfort, keyboard, notification, power, shutdown, sound, wireless-casting) 2. Move XdgActivation request to PluginItem's invokeMenuItem and executeCommand methods 3. Standardize launching control-center with dde-am command without XdgActivation token 4. Set XDG_ACTIVATION_TOKEN environment variable in pluginitem before calling plugin's invokedMenuItem 5. Simplify command execution by using QProcess with environment variable Log: Refactored XdgActivation handling for dock plugin system Influence: 1. Verify all dock plugin settings buttons still open control-center correctly 2. Test that XDG_ACTIVATION_TOKEN is properly set when invoking plugin menu items 3. Verify command execution with XdgActivation token works 4. Test that plugins without settings (e.g., airplane mode toggle) still work 5. Verify no regressions in dock plugin functionality 6. Test keyboard layout add layout action refactor: 将XdgActivation移到pluginitem并简化dock插件 1. 从所有dock插件中移除XdgActivation使用(飞行模式、蓝牙、亮度、日期时 间、勿扰、护眼、键盘布局、通知、电源、关机、声音、投屏) 2. 将XdgActivation请求移动到PluginItem的invokeMenuItem和executeCommand方 法中 3. 标准化使用dde-am命令启动控制中心,不再传递XdgActivation令牌 4. 在调用插件invokedMenuItem之前,在pluginitem中设置XDG_ACTIVATION_TOKEN 环境变量 5. 通过使用带环境变量的QProcess简化命令执行 Log: 重构了dock插件系统的XdgActivation处理 Influence: 1. 验证所有dock插件设置按钮仍然正确打开控制中心 2. 测试调用插件菜单项时是否正确设置XDG_ACTIVATION_TOKEN 3. 验证带XdgActivation令牌的命令执行是否正常 4. 测试无设置的插件(如飞行模式切换)是否仍然正常工作 5. 验证dock插件功能没有回归问题 6. 测试键盘布局添加布局的操作
1 parent 912bcf7 commit 977a976

13 files changed

Lines changed: 51 additions & 135 deletions

File tree

plugins/dde-dock/airplane-mode/airplanemodeitem.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "constants.h"
88
#include "tipswidget.h"
99

10-
#include "xdgactivation.h"
1110

1211
#include <DGuiApplicationHelper>
1312

@@ -119,16 +118,8 @@ void AirplaneModeItem::invokeMenuItem(const QString menuId, const bool checked)
119118
if (menuId == SHIFT) {
120119
AMC_PTR->toggle();
121120
} else if (menuId == SETTINGS) {
122-
auto *activation = new tray::XdgActivation(this);
123-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
124-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
125-
if (!token.isEmpty())
126-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
127-
args << "--" << "-p" << "network/airplaneMode";
128-
QProcess::startDetached("dde-am", args);
129-
activation->deleteLater();
130-
}, Qt::SingleShotConnection);
131-
activation->requestToken();
121+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "network/airplaneMode"};
122+
QProcess::startDetached("dde-am", args);
132123

133124
Q_EMIT requestHideApplet();
134125
}

plugins/dde-dock/bluetooth/bluetoothitem.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "constants.h"
1111
#include "quickpanelwidget.h"
1212

13-
#include "xdgactivation.h"
1413

1514
#include <DApplication>
1615
#include <DGuiApplicationHelper>
@@ -128,16 +127,8 @@ void BluetoothItem::invokeMenuItem(const QString menuId, const bool checked)
128127
}
129128
m_applet->setAdapterPowered(!m_adapterPowered);
130129
} else if (menuId == SETTINGS) {
131-
auto *activation = new tray::XdgActivation(this);
132-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
133-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
134-
if (!token.isEmpty())
135-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
136-
args << "--" << "-p" << "device/bluetooth";
137-
QProcess::startDetached("dde-am", args);
138-
activation->deleteLater();
139-
}, Qt::SingleShotConnection);
140-
activation->requestToken();
130+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "device/bluetooth"};
131+
QProcess::startDetached("dde-am", args);
141132
Q_EMIT requestHideApplet();
142133
}
143134
}

plugins/dde-dock/brightness/brightnessitem.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "constants.h"
77
#include "brightnessmodel.h"
88

9-
#include "xdgactivation.h"
109

1110
#include <DFontSizeManager>
1211
#include <DGuiApplicationHelper>
@@ -81,16 +80,8 @@ void BrightnessItem::invokeMenuItem(const QString menuId, const bool checked)
8180
Q_UNUSED(checked);
8281

8382
if (menuId == SETTINGS) {
84-
auto *activation = new tray::XdgActivation(this);
85-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
86-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
87-
if (!token.isEmpty())
88-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
89-
args << "--" << "-p" << "display";
90-
QProcess::startDetached("dde-am", args);
91-
activation->deleteLater();
92-
}, Qt::SingleShotConnection);
93-
activation->requestToken();
83+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "display"};
84+
QProcess::startDetached("dde-am", args);
9485

9586
Q_EMIT requestHideApplet();
9687
}

plugins/dde-dock/datetime/datetimeplugin.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "plugins-logging-category.h"
88
#include "regionFormat.h"
99

10-
#include "xdgactivation.h"
1110

1211
#include <DConfig>
1312
#include <DDBusSender>
@@ -216,16 +215,8 @@ void DatetimePlugin::invokedMenuItem(const QString &itemKey, const QString &menu
216215
Q_UNUSED(checked)
217216

218217
if (menuId == "open") {
219-
auto *activation = new tray::XdgActivation(this);
220-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
221-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
222-
if (!token.isEmpty())
223-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
224-
args << "--" << "-p" << "datetime";
225-
QProcess::startDetached("dde-am", args);
226-
activation->deleteLater();
227-
}, Qt::SingleShotConnection);
228-
activation->requestToken();
218+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "datetime"};
219+
QProcess::startDetached("dde-am", args);
229220
} else if (menuId == "settings") {
230221
const bool is24HourFormat = m_centralWidget->is24HourFormat();
231222
m_centralWidget->set24HourFormat(!is24HourFormat);

plugins/dde-dock/dnd-mode/dndmodeitem.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include "dndmodecontroller.h"
99
#include "tipswidget.h"
1010

11-
#include "xdgactivation.h"
12-
1311
#include <DGuiApplicationHelper>
1412

1513
#include <QDBusConnection>
@@ -112,16 +110,8 @@ void DndModeItem::invokeMenuItem(const QString menuId, const bool checked)
112110
if (menuId == SHIFT) {
113111
DndModeController::ref().toggle();
114112
} else if (menuId == SETTINGS) {
115-
auto *activation = new tray::XdgActivation(this);
116-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
117-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
118-
if (!token.isEmpty())
119-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
120-
args << "--" << "-p" << "notification";
121-
QProcess::startDetached("dde-am", args);
122-
activation->deleteLater();
123-
}, Qt::SingleShotConnection);
124-
activation->requestToken();
113+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "notification"};
114+
QProcess::startDetached("dde-am", args);
125115

126116
Q_EMIT requestHideApplet();
127117
}

plugins/dde-dock/eye-comfort-mode/eyecomfortmodeitem.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "tipswidget.h"
1010
#include "quickpanelwidget.h"
1111

12-
#include "xdgactivation.h"
1312

1413
#include <DGuiApplicationHelper>
1514

@@ -187,16 +186,8 @@ void EyeComfortModeItem::invokeMenuItem(const QString menuId, const bool checked
187186
if (menuId == SHIFT) {
188187
EyeComfortModeController::ref().toggle();
189188
} else if (menuId == SETTINGS) {
190-
auto *activation = new tray::XdgActivation(this);
191-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
192-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
193-
if (!token.isEmpty())
194-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
195-
args << "--" << "-p" << "display";
196-
QProcess::startDetached("dde-am", args);
197-
activation->deleteLater();
198-
}, Qt::SingleShotConnection);
199-
activation->requestToken();
189+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "display"};
190+
QProcess::startDetached("dde-am", args);
200191
Q_EMIT requestHideApplet();
201192
}
202193
}

plugins/dde-dock/keyboard-layout/dbusadaptors.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "fcitxinputmethoditem.h"
88
#include "plugins-logging-category.h"
99

10-
#include "xdgactivation.h"
1110

1211
#include <DSysInfo>
1312

@@ -177,16 +176,8 @@ void DBusAdaptors::refreshMenuSelection()
177176
void DBusAdaptors::handleActionTriggered(QAction *action)
178177
{
179178
if (action == m_addLayoutAction) {
180-
auto *activation = new tray::XdgActivation(this);
181-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
182-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
183-
if (!token.isEmpty())
184-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
185-
args << "--" << "-p" << "keyboard/Keyboard Layout/Add Keyboard Layout";
186-
QProcess::startDetached("dde-am", args);
187-
activation->deleteLater();
188-
}, Qt::SingleShotConnection);
189-
activation->requestToken();
179+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "keyboard/Keyboard Layout/Add Keyboard Layout"};
180+
QProcess::startDetached("dde-am", args);
190181
}
191182

192183
const QString layout = action->objectName();

plugins/dde-dock/notification/notificationplugin.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44
#include "notificationplugin.h"
55

6-
#include "xdgactivation.h"
76

87
#include <DGuiApplicationHelper>
98

@@ -134,16 +133,8 @@ void NotificationPlugin::invokedMenuItem(const QString &itemKey, const QString &
134133
if (menuId == TOGGLE_DND) {
135134
m_notification->setDndMode(!m_notification->dndMode());
136135
} else if (menuId == NOTIFICATION_SETTINGS) {
137-
auto *activation = new tray::XdgActivation(this);
138-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
139-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
140-
if (!token.isEmpty())
141-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
142-
args << "--" << "-p" << "notification";
143-
QProcess::startDetached("dde-am", args);
144-
activation->deleteLater();
145-
}, Qt::SingleShotConnection);
146-
activation->requestToken();
136+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "notification"};
137+
QProcess::startDetached("dde-am", args);
147138
}
148139
}
149140

plugins/dde-dock/power/powerplugin.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "dbus/dbusaccount.h"
1010
#include "plugins-logging-category.h"
1111

12-
#include "xdgactivation.h"
1312

1413
#include <DConfig>
1514

@@ -143,16 +142,8 @@ void PowerPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,
143142
Q_UNUSED(checked)
144143

145144
if (menuId == "power") {
146-
auto *activation = new tray::XdgActivation(this);
147-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
148-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
149-
if (!token.isEmpty())
150-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
151-
args << "--" << "-p" << "power";
152-
QProcess::startDetached("dde-am", args);
153-
activation->deleteLater();
154-
}, Qt::SingleShotConnection);
155-
activation->requestToken();
145+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "power"};
146+
QProcess::startDetached("dde-am", args);
156147
}
157148
}
158149

plugins/dde-dock/shutdown/shutdownplugin.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "./dbus/org_deepin_dde_sessionmanager.h"
1010
#include "plugins-logging-category.h"
1111

12-
#include "xdgactivation.h"
1312

1413
#include <DSysInfo>
1514
#include <DDBusSender>
@@ -309,16 +308,8 @@ void ShutdownPlugin::invokedMenuItem(const QString &itemKey, const QString &menu
309308
QCoreApplication::processEvents(QEventLoop::AllEvents, 200);
310309

311310
if (menuId == "power") {
312-
auto *activation = new tray::XdgActivation(this);
313-
connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
314-
QStringList args {"--by-user", "org.deepin.dde.control-center"};
315-
if (!token.isEmpty())
316-
args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
317-
args << "--" << "-p" << "power";
318-
QProcess::startDetached("dde-am", args);
319-
activation->deleteLater();
320-
}, Qt::SingleShotConnection);
321-
activation->requestToken();
311+
QStringList args {"--by-user", "org.deepin.dde.control-center", "--", "-p", "power"};
312+
QProcess::startDetached("dde-am", args);
322313
} else if (menuId == "Lock") {
323314
if (QFile::exists(ICBC_CONF_FILE)) {
324315
QDBusMessage send = QDBusMessage::createMethodCall("org.deepin.dde.LockFront1", "/org/deepin/dde/LockFront1", "org.deepin.dde.LockFront1", "SwitchTTYAndShow");

0 commit comments

Comments
 (0)