Skip to content

Commit 6056b09

Browse files
committed
feat(notification): add ActivationToken support for wayland
Add xdg-activation-v1 token support to notification service: - Emit ActivationToken signal before ActionInvoked for non-extended actions - Pass XDG_ACTIVATION_TOKEN env to dde-am for extended actions - Use async token request without blocking 为通知服务添加wayland激活令牌支持: - 非扩展动作先发送ActivationToken信号再发送ActionInvoked - 扩展动作通过环境变量传递令牌给dde-am - 使用异步方式获取令牌,不阻塞主线程 Log: 为通知服务添加wayland激活令牌支持
1 parent db53374 commit 6056b09

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

panels/notification/server/dbusadaptor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -32,7 +32,7 @@ public Q_SLOTS: // methods
3232
Q_SIGNALS:
3333
void ActionInvoked(uint id, const QString &actionKey);
3434
void NotificationClosed(uint id, uint reason);
35-
// todo void ActivationToken(uint id, const QString &activationToken)
35+
void ActivationToken(uint id, const QString &token);
3636
};
3737

3838
class DDENotificationDbusAdaptor : public QDBusAbstractAdaptor
@@ -54,7 +54,7 @@ public Q_SLOTS: // methods
5454
Q_SIGNALS:
5555
void ActionInvoked(uint id, const QString &actionKey);
5656
void NotificationClosed(uint id, uint reason);
57-
// todo void ActivationToken(uint id, const QString &activationToken)
57+
void ActivationToken(uint id, const QString &token);
5858

5959
public Q_SLOTS: // methods
6060
uint recordCount() const;

panels/notification/server/notificationmanager.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <appletbridge.h>
2828
#include <pluginloader.h>
29+
#include <wayland/xdgactivation.h>
2930

3031
DCORE_USE_NAMESPACE
3132
DS_USE_NAMESPACE
@@ -134,8 +135,19 @@ void NotificationManager::actionInvoked(qint64 id, uint bubbleId, const QString
134135
qInfo(notifyLog) << "Action invoked, bubbleId:" << bubbleId << ", id:" << id << ", actionKey" << actionKey;
135136
actionInvoked(id, actionKey);
136137

137-
Q_EMIT ActionInvoked(bubbleId, actionKey);
138-
Q_EMIT NotificationClosed(bubbleId, NotifyEntity::Closed);
138+
// For non-extended actions, emit ActivationToken first if available
139+
auto *activation = new DS_NAMESPACE::XdgActivation(this);
140+
connect(activation, &DS_NAMESPACE::XdgActivation::tokenReady, this,
141+
[this, bubbleId, actionKey, activation](const QString &token) {
142+
if (!token.isEmpty()) {
143+
Q_EMIT ActivationToken(bubbleId, token);
144+
qDebug(notifyLog) << "Emitted ActivationToken for non-extended action:" << token;
145+
}
146+
Q_EMIT ActionInvoked(bubbleId, actionKey);
147+
Q_EMIT NotificationClosed(bubbleId, NotifyEntity::Closed);
148+
activation->deleteLater();
149+
}, Qt::SingleShotConnection);
150+
activation->requestToken();
139151
}
140152

141153
void NotificationManager::notificationClosed(qint64 id, uint bubbleId, uint reason)
@@ -566,13 +578,27 @@ void NotificationManager::doActionInvoked(const NotifyEntity &entity, const QStr
566578
amArgs << "--" << args;
567579
}
568580

569-
QProcess pro;
570-
pro.setProgram("dde-am");
571-
pro.setArguments(amArgs);
572-
QProcessEnvironment proEnv = QProcessEnvironment::systemEnvironment();
573-
proEnv.remove("DSG_APP_ID");
574-
pro.setProcessEnvironment(proEnv);
575-
pro.startDetached();
581+
// Get activation token, then start process
582+
auto *activation = new DS_NAMESPACE::XdgActivation(this);
583+
auto amArgsCopy = amArgs;
584+
connect(activation, &DS_NAMESPACE::XdgActivation::tokenReady, this,
585+
[amArgsCopy, activation](const QString &token) {
586+
QProcess pro;
587+
pro.setProgram("dde-am");
588+
pro.setArguments(amArgsCopy);
589+
QProcessEnvironment proEnv = QProcessEnvironment::systemEnvironment();
590+
proEnv.remove("DSG_APP_ID");
591+
592+
if (!token.isEmpty()) {
593+
proEnv.insert("XDG_ACTIVATION_TOKEN", token);
594+
qDebug(notifyLog) << "Set XDG_ACTIVATION_TOKEN for extended action:" << token;
595+
}
596+
597+
pro.setProcessEnvironment(proEnv);
598+
pro.startDetached();
599+
activation->deleteLater();
600+
}, Qt::SingleShotConnection);
601+
activation->requestToken();
576602
}
577603
} else if (i.key() == "deepin-dde-shell-action-" + actionId) {
578604
const QString data(i.value().toString());

panels/notification/server/notificationmanager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class NotificationManager : public QObject, public QDBusContext
5050

5151
void NotificationStateChanged(qint64 id, int processedType);
5252

53+
// Activation token signal for Wayland
54+
void ActivationToken(uint id, const QString &token);
55+
5356
public Q_SLOTS:
5457
// Standard Notifications dbus implementation
5558
QStringList GetCapabilities();

0 commit comments

Comments
 (0)