Commit 31303ad3 authored by Konrad Materka's avatar Konrad Materka
Browse files

[SNI] Fix race condition in item registration

If StatusNotifierItem is registered and then immediately destroyed, it is possible that QDBusServiceWatcher will not emit the serviceUnregistered signal.
Add an additional check to avoid such situations.

BUG: 416652
FIXED-IN: 5.18.0

Test Plan: Telegram should not add empty items.

Reviewers: #plasma_workspaces, #plasma, davidedmundson

Reviewed By: #plasma_workspaces, #plasma, davidedmundson

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision:
parent 557246c9
...@@ -65,18 +65,22 @@ void StatusNotifierWatcher::RegisterStatusNotifierItem(const QString &serviceOrP ...@@ -65,18 +65,22 @@ void StatusNotifierWatcher::RegisterStatusNotifierItem(const QString &serviceOrP
path = QStringLiteral("/StatusNotifierItem"); path = QStringLiteral("/StatusNotifierItem");
} }
QString notifierItemId = service + path; QString notifierItemId = service + path;
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(service).value() && if (m_registeredServices.contains(notifierItemId)) {
!m_registeredServices.contains(notifierItemId)) { return;
qDebug()<<"Registering" << notifierItemId << "to system tray"; }
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(service).value()) {
//check if the service has registered a SystemTray object //check if the service has registered a SystemTray object
org::kde::StatusNotifierItem trayclient(service, path, org::kde::StatusNotifierItem trayclient(service, path, QDBusConnection::sessionBus());
if (trayclient.isValid()) { if (trayclient.isValid()) {
qDebug() << "Registering" << notifierItemId << "to system tray";
m_registeredServices.append(notifierItemId); m_registeredServices.append(notifierItemId);
emit StatusNotifierItemRegistered(notifierItemId); emit StatusNotifierItemRegistered(notifierItemId);
} else {
} }
} else {
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment