[Notifications] Fall back to process ID when no desktop_entry is provided in Inhibit

xdg-desktop-portal forwards appId only for sandboxed apps it can trust,
essentially blocking us from posting an inhibition from xdg-desktop-portal
as we wouldn't have an app.
wilder-5.22
Kai Uwe Broulik 5 years ago
parent 54b13de10c
commit c249f46340
  1. 28
      libnotificationmanager/server_p.cpp

@ -378,17 +378,33 @@ uint ServerPrivate::Inhibit(const QString &desktop_entry, const QString &reason,
{
const QString dbusService = message().service();
QString applicationName = desktop_entry;
qCDebug(NOTIFICATIONMANAGER) << "Request inhibit from service" << dbusService << "which is" << desktop_entry << "with reason" << reason;
// xdg-desktop-portal forwards appId only for sandboxed apps it can trust
// Resolve it to process name here to at least have something, even if that means showing "xdg-desktop-portal-kde is currently..."
if (desktop_entry.isEmpty()) {
// TODO return error
return 0;
QDBusReply<uint> pidReply = connection().interface()->servicePid(message().service());
if (pidReply.isValid()) {
const auto pid = pidReply.value();
const QString processName = Utils::processNameFromPid(pid);
if (!processName.isEmpty()) {
qCDebug(NOTIFICATIONMANAGER) << "Resolved inhibition to be from process name" << processName;
applicationName = processName;
}
}
} else {
KService::Ptr service = KService::serviceByDesktopName(desktop_entry);
if (service) {
applicationName = service->name();
}
}
KService::Ptr service = KService::serviceByDesktopName(desktop_entry);
QString applicationName;
if (service) { // should we check for this and error if it didn't find a service?
applicationName = service->name();
if (applicationName.isEmpty()) {
sendErrorReply(QDBusError::InvalidArgs, QStringLiteral("No meaningful desktop_entry provided"));
return 0;
}
m_inhibitionWatcher->addWatchedService(dbusService);

Loading…
Cancel
Save