增加设置接口启动时校验应用列表功能

This commit is contained in:
iaom 2023-03-17 16:08:24 +08:00
parent a3b53d48e4
commit f150ebca0a
4 changed files with 32 additions and 1 deletions

View File

@ -51,6 +51,7 @@ private:
QStringList getAppInfo(); QStringList getAppInfo();
void initSettingsData(QJsonObject &data); void initSettingsData(QJsonObject &data);
void checkApplicationList(QJsonObject &data);
public Q_SLOTS: public Q_SLOTS:
void desktopFileAdd(const QStringList &data); void desktopFileAdd(const QStringList &data);
@ -65,6 +66,7 @@ private:
QFileSystemWatcher *m_watcher = nullptr; QFileSystemWatcher *m_watcher = nullptr;
UkuiSearch::ApplicationInfo * m_applicationInfo = nullptr; UkuiSearch::ApplicationInfo * m_applicationInfo = nullptr;
QJsonObject m_applicationDefaultSettings; QJsonObject m_applicationDefaultSettings;
bool m_needCheckApplist = true;
}; };
} }

View File

@ -82,6 +82,10 @@ void SettingsManagerPrivate::checkAndLoad()
qDebug() << "Notification settings version is different, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION; qDebug() << "Notification settings version is different, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION;
updateSettingsFile(); updateSettingsFile();
} else { } else {
if(m_needCheckApplist) {
checkApplicationList(settingsData);
m_needCheckApplist = false;
}
m_settingsData.swap(settingsData); m_settingsData.swap(settingsData);
Q_EMIT settingsUpdateFinished(); Q_EMIT settingsUpdateFinished();
m_watcher->addPath(SETTINGS_FILE_PATH_NAME); m_watcher->addPath(SETTINGS_FILE_PATH_NAME);
@ -226,6 +230,30 @@ void SettingsManagerPrivate::save2SettingsFile(const QJsonObject &jsonDocData)
settingsFile.close(); settingsFile.close();
} }
void SettingsManagerPrivate::checkApplicationList(QJsonObject &data)
{
QStringList appList = getAppInfo();
QStringList appNeedRemoved;
QJsonObject applicationSettings = data.value(QStringLiteral("Applications")).toObject();
for(const QString &desktopFile : applicationSettings.keys()) {
if(appList.contains(desktopFile)) {
appList.removeAll(desktopFile);
} else {
appNeedRemoved.append(desktopFile);
}
}
//移除应用列表里已经不存在的应用
for(const QString &desktopFile : appNeedRemoved) {
applicationSettings.remove(desktopFile);
}
//将配置文件中没有的应用插入
for(const QString &desktopFile : appList) {
applicationSettings.insert(desktopFile, m_applicationDefaultSettings);
}
data.insert(QStringLiteral("Applications"), applicationSettings);
save2SettingsFile(data);
}
SettingsManager::SettingsManager(QObject *parent) : QObject(parent), d(new SettingsManagerPrivate(this)) SettingsManager::SettingsManager(QObject *parent) : QObject(parent), d(new SettingsManagerPrivate(this))
{ {
connect(d, &SettingsManagerPrivate::settingsUpdateFinished, this, &SettingsManager::settingsDataChanged); connect(d, &SettingsManagerPrivate::settingsUpdateFinished, this, &SettingsManager::settingsDataChanged);

View File

@ -24,6 +24,7 @@ endforeach()
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
include_directories(../libukui-notification/notification-settings) include_directories(../libukui-notification/notification-settings)
include_directories(../libukui-notification)
target_link_libraries(notification-ukcc-plugin target_link_libraries(notification-ukcc-plugin
PRIVATE PRIVATE

View File

@ -8,7 +8,7 @@
#include <QFrame> #include <QFrame>
#include <kswitchbutton.h> #include <kswitchbutton.h>
#include "notification-settings/applications-settings.h" #include "applications-settings.h"
using namespace kdk; using namespace kdk;