diff --git a/libukui-notification/notification-settings/settings-manager-private.h b/libukui-notification/notification-settings/settings-manager-private.h index 3558edd..543e71d 100644 --- a/libukui-notification/notification-settings/settings-manager-private.h +++ b/libukui-notification/notification-settings/settings-manager-private.h @@ -51,6 +51,7 @@ private: QStringList getAppInfo(); void initSettingsData(QJsonObject &data); + void checkApplicationList(QJsonObject &data); public Q_SLOTS: void desktopFileAdd(const QStringList &data); @@ -65,6 +66,7 @@ private: QFileSystemWatcher *m_watcher = nullptr; UkuiSearch::ApplicationInfo * m_applicationInfo = nullptr; QJsonObject m_applicationDefaultSettings; + bool m_needCheckApplist = true; }; } diff --git a/libukui-notification/notification-settings/settings-manager.cpp b/libukui-notification/notification-settings/settings-manager.cpp index da2d6c0..9ae8386 100644 --- a/libukui-notification/notification-settings/settings-manager.cpp +++ b/libukui-notification/notification-settings/settings-manager.cpp @@ -82,6 +82,10 @@ void SettingsManagerPrivate::checkAndLoad() qDebug() << "Notification settings version is different, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION; updateSettingsFile(); } else { + if(m_needCheckApplist) { + checkApplicationList(settingsData); + m_needCheckApplist = false; + } m_settingsData.swap(settingsData); Q_EMIT settingsUpdateFinished(); m_watcher->addPath(SETTINGS_FILE_PATH_NAME); @@ -226,6 +230,30 @@ void SettingsManagerPrivate::save2SettingsFile(const QJsonObject &jsonDocData) 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)) { connect(d, &SettingsManagerPrivate::settingsUpdateFinished, this, &SettingsManager::settingsDataChanged); diff --git a/notification-ukcc-plugin/CMakeLists.txt b/notification-ukcc-plugin/CMakeLists.txt index d671460..80d4340 100644 --- a/notification-ukcc-plugin/CMakeLists.txt +++ b/notification-ukcc-plugin/CMakeLists.txt @@ -24,6 +24,7 @@ endforeach() include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) include_directories(../libukui-notification/notification-settings) +include_directories(../libukui-notification) target_link_libraries(notification-ukcc-plugin PRIVATE diff --git a/notification-ukcc-plugin/noticemenu.h b/notification-ukcc-plugin/noticemenu.h index bdeb606..ad72804 100644 --- a/notification-ukcc-plugin/noticemenu.h +++ b/notification-ukcc-plugin/noticemenu.h @@ -8,7 +8,7 @@ #include #include -#include "notification-settings/applications-settings.h" +#include "applications-settings.h" using namespace kdk;