feat: add xdg-activation-v1 client for SNI tray activation token#462
feat: add xdg-activation-v1 client for SNI tray activation token#46218202781743 wants to merge 3 commits into
Conversation
Add XdgActivationClient that uses QWaylandClientExtension to bind dde-shell's xdg_activation_v1 global and request activation tokens via standard Wayland protocol before calling SNI Activate. Modified sniprotocolhandler to request token asynchronously before calling Activate, setting XDG_ACTIVATION_TOKEN env var. Log: SNI托盘图标Wayland下点击时申请xdgactivation token激活DBus窗口 Issue: #6
There was a problem hiding this comment.
Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff。本次修改主要为Wayland环境下的系统托盘添加了 整体来看,代码结构清晰,逻辑基本合理。但在语法逻辑、代码质量、性能和安全性方面,有一些值得注意和改进的地方。以下是详细的审查意见: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
修改建议代码示例针对 // xdgactivationclient.cpp
XdgActivationClient *XdgActivationClient::instance()
{
// 使用静态局部变量保证线程安全,且无需手动管理内存
static XdgActivationClient s_instance(qApp);
return &s_instance;
}
void XdgActivationClient::requestToken(QWindow *window, const QString &appId, TokenCallback callback)
{
if (m_pendingProvider) {
qCWarning(trayXdgActivation) << "Token request already in progress";
if (callback) callback(QString());
return;
}
if (!isActive()) {
qCDebug(trayXdgActivation) << "xdg_activation_v1 not active";
if (callback) callback(QString());
return;
}
auto effectiveWindow = window ? window : QGuiApplication::focusWindow();
if (!effectiveWindow) {
qCWarning(trayXdgActivation) << "No target window for activation token";
if (callback) callback(QString());
return;
}
auto *provider = m_activation->createTokenProvider(effectiveWindow, appId);
m_pendingProvider = provider;
// 传入 this 作为 context,防止 this 被销毁时 lambda 仍然被调用
connect(provider, &XdgActivationTokenV1::done, this, [this, callback](const QString &token) {
m_pendingProvider = nullptr;
if (token.isEmpty())
qCWarning(trayXdgActivation) << "Empty activation token received";
else
qCDebug(trayXdgActivation) << "Activation token received";
if (callback) callback(token);
sender()->deleteLater();
}, Qt::SingleShotConnection);
}对于 // sniprotocolhandler.cpp
if (activationClient->isActive()) {
auto widget = static_cast<QWidget*>(parent());
auto *win = widget->window()->windowHandle();
auto sniInter = m_sniInter;
activationClient->requestToken(win, QString(), [sniInter](const QString &token) {
if (!token.isEmpty()) {
qputenv("XDG_ACTIVATION_TOKEN", token.toUtf8());
}
// Activate 是异步调用,环境变量在进程内,底层DBus发送时会读取当前进程环境
sniInter->Activate(0, 0);
// 注意:立即 qunsetenv 可能导致底层DBus尚未读取到该变量
// 如果确实需要清理,建议使用 QTimer::singleShot(0, []{ qunsetenv("XDG_ACTIVATION_TOKEN"); });
// 但最安全的做法是不使用环境变量传递,或者确认SNI实现会在Activate调用时立即拷贝环境变量
qunsetenv("XDG_ACTIVATION_TOKEN");
});
} else {
m_sniInter->Activate(0, 0);
}希望这些审查意见对你有所帮助!如果有任何疑问,欢迎继续交流。 |
|
TAG Bot New tag: 2.0.33 |
Add XdgActivationClient that uses QWaylandClientExtension to bind dde-shell's xdg_activation_v1 global and request activation tokens via standard Wayland protocol before calling SNI Activate.
Issue: #6