通知设置排除/etc/xdg/autostart目录下的desktop文件;

增加desktop文件名转全路径的接口。

Signed-off-by: iaom <zhangpengfei@kylinos.cn>
This commit is contained in:
iaom 2023-04-18 10:52:18 +08:00
parent 188a895ca9
commit c2b047fdc9
5 changed files with 32 additions and 7 deletions

View File

@ -159,7 +159,9 @@ void SettingsManagerPrivate::updateSettingsFile()
QStringList SettingsManagerPrivate::getAppInfo() QStringList SettingsManagerPrivate::getAppInfo()
{ {
return m_applicationInfo->getInfo(UkuiSearch::ApplicationProperties{}).keys();
return m_applicationInfo->getInfo(UkuiSearch::ApplicationProperties{},
UkuiSearch::ApplicationPropertyMap{{UkuiSearch::ApplicationProperty::AutoStart, 0}}).keys();
} }
void SettingsManagerPrivate::initSettingsData(QJsonObject &data) void SettingsManagerPrivate::initSettingsData(QJsonObject &data)
@ -185,9 +187,17 @@ void SettingsManagerPrivate::initSettingsData(QJsonObject &data)
void SettingsManagerPrivate::desktopFileAdd(const QStringList &data) void SettingsManagerPrivate::desktopFileAdd(const QStringList &data)
{ {
QJsonObject applicationsSettings = m_settingsData.value(QStringLiteral("Applications")).toObject(); QJsonObject applicationsSettings = m_settingsData.value(QStringLiteral("Applications")).toObject();
bool needUpdate = false;
for (const QString &desktopPath : data) { for (const QString &desktopPath : data) {
applicationsSettings.insert(desktopPath, m_applicationDefaultSettings); if(m_applicationInfo->getInfo(desktopPath, UkuiSearch::ApplicationProperty::AutoStart).toInt() == 0) {
applicationsSettings.insert(desktopPath, m_applicationDefaultSettings);
needUpdate = true;
}
} }
if(!needUpdate) {
return;
}
m_settingsData.insert(QStringLiteral("Applications"), applicationsSettings); m_settingsData.insert(QStringLiteral("Applications"), applicationsSettings);
QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock")); QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock"));

View File

@ -23,14 +23,16 @@
#include <KWindowSystem> #include <KWindowSystem>
#include <application-info.h> #include <application-info.h>
using namespace UkuiNotification; using namespace UkuiNotification;
static UkuiSearch::ApplicationInfo s_applicationInfo;
QString Utils::desktopEntryFromPid(uint pid) QString Utils::desktopEntryFromPid(uint pid)
{ {
QString desktop; QString desktop;
if(UkuiSearch::ApplicationInfo().tranPidToDesktopFp(pid, desktop)) { if(s_applicationInfo.tranPidToDesktopFp(pid, desktop)) {
return desktop; return desktop;
} }
return {}; return {};
} }
QString Utils::displayFromPid(uint pid) QString Utils::displayFromPid(uint pid)
{ {
QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid))); QFile environFile(QStringLiteral("/proc/%1/environ").arg(QString::number(pid)));
@ -50,4 +52,11 @@ QString Utils::displayFromPid(uint pid)
} }
} }
return {}; return {};
}
QString Utils::desktopEntryFromName(const QString& desktopFileName)
{
QString desktopFilePathName;
s_applicationInfo.desktopFilePathFromName(desktopFileName, desktopFilePathName);
return desktopFilePathName;
} }

View File

@ -24,6 +24,7 @@ namespace UkuiNotification {
namespace Utils { namespace Utils {
QString desktopEntryFromPid(uint pid); QString desktopEntryFromPid(uint pid);
QString displayFromPid(uint pid); QString displayFromPid(uint pid);
QString desktopEntryFromName(const QString& desktopFileName);
} }
} }
#endif //UKUI_NOTIFICATION_UTILS_H #endif //UKUI_NOTIFICATION_UTILS_H

View File

@ -34,7 +34,7 @@ NotificationServerApplication::NotificationServerApplication(int &argc, char **a
}); });
Server::self().init(); Server::self().init();
} }
parseCmd(this->arguments().join(" ").toUtf8(), !isRunning()); parseCmd(arguments().join(" ").toUtf8(), !isRunning());
} }
NotificationServerApplication::~NotificationServerApplication() NotificationServerApplication::~NotificationServerApplication()

View File

@ -67,10 +67,15 @@ uint ServerPrivate::Notify(const QString &app_name, uint replaces_id, const QStr
if(newHints.value(QStringLiteral("x-ukui-display")).toString().isEmpty() && pid > 0) { if(newHints.value(QStringLiteral("x-ukui-display")).toString().isEmpty() && pid > 0) {
newHints.insert(QStringLiteral("x-ukui-display"), UkuiNotification::Utils::displayFromPid(pid)); newHints.insert(QStringLiteral("x-ukui-display"), UkuiNotification::Utils::displayFromPid(pid));
} }
//todo 如果desktop-entry只有文件名需要获取全路径 //如果desktop-entry只有文件名需要获取全路径
if(newHints.value(QStringLiteral("desktop-entry")).toString().isEmpty() && pid > 0) { QString desktopEntry = newHints.value(QStringLiteral("desktop-entry")).toString();
newHints.insert(QStringLiteral("desktop-entry"), UkuiNotification::Utils::desktopEntryFromPid(pid)); if(!desktopEntry.isEmpty()) {
desktopEntry = UkuiNotification::Utils::desktopEntryFromName(desktopEntry);
} }
if(desktopEntry.isEmpty() && pid > 0) {
desktopEntry = UkuiNotification::Utils::desktopEntryFromPid(pid);
}
newHints.insert(QStringLiteral("desktop-entry"), desktopEntry);
qDebug() << "New message received:" << app_name << id << app_icon << summary << body qDebug() << "New message received:" << app_name << id << app_icon << summary << body
<< actions << hints << timeout << "new hints" << newHints; << actions << hints << timeout << "new hints" << newHints;