diff --git a/notification-ukcc-plugin/notification-ukcc-plugin.cpp b/notification-ukcc-plugin/notification-ukcc-plugin.cpp index 804aa0e..26ebbec 100644 --- a/notification-ukcc-plugin/notification-ukcc-plugin.cpp +++ b/notification-ukcc-plugin/notification-ukcc-plugin.cpp @@ -26,8 +26,17 @@ #include #include #include +#include #define THEME_QT_SCHEMA "org.ukui.style" +static std::once_flag flag; +static UkuiSearch::ApplicationInfo *s_appInfo = nullptr; +UkuiSearch::ApplicationInfo *appInfo() { + std::call_once(flag, [ & ] { + s_appInfo = new UkuiSearch::ApplicationInfo(); + }); + return s_appInfo; +} class ToolButton : public QToolButton { @@ -59,9 +68,6 @@ Notice::Notice() if (!m_globalSettings) { m_globalSettings = new UkuiNotification::NotificationGlobalSettings(); } - if (!m_appInfo) { - m_appInfo = new UkuiSearch::ApplicationInfo(); - } m_pluginWidget = new QWidget; m_pluginWidget->setAttribute(Qt::WA_DeleteOnClose); @@ -79,11 +85,6 @@ Notice::~Notice() delete m_globalSettings; m_globalSettings = nullptr; } - if (m_appInfo) { - delete m_appInfo; - m_appInfo = nullptr; - } - } QString Notice::plugini18nName() @@ -473,7 +474,7 @@ void Notice::initListUI() connect(this, &Notice::appDataInfo, this, &Notice::addItemUi, Qt::QueuedConnection); QtConcurrent::run([=](){ - const UkuiSearch::ApplicationInfoMap& appInfoMap = m_appInfo->getInfo(properties, restrictions); + const UkuiSearch::ApplicationInfoMap& appInfoMap = appInfo()->getInfo(properties, restrictions); Q_EMIT appDataInfo(appInfoMap); }); @@ -487,7 +488,7 @@ void Notice::initListUI() }; QtConcurrent::run([=](){ - UkuiSearch::ApplicationPropertyMap dataMap = m_appInfo->getInfo(desktopEntry, properties); + UkuiSearch::ApplicationPropertyMap dataMap = appInfo()->getInfo(desktopEntry, properties); UkuiSearch::ApplicationInfoMap appInfoMap = {{desktopEntry, dataMap}}; Q_EMIT appDataInfo(appInfoMap); }); diff --git a/notification-ukcc-plugin/notification-ukcc-plugin.h b/notification-ukcc-plugin/notification-ukcc-plugin.h index f251458..1e50f8c 100644 --- a/notification-ukcc-plugin/notification-ukcc-plugin.h +++ b/notification-ukcc-plugin/notification-ukcc-plugin.h @@ -110,8 +110,6 @@ private: QVBoxLayout *m_appListVerticalLayout = nullptr; UkuiNotification::NotificationGlobalSettings *m_globalSettings = nullptr; - - UkuiSearch::ApplicationInfo *m_appInfo = nullptr; }; #endif // NOTIFICATION_UKCC_PLUGIN_H