From 2c560d0a298effda91bb322108742cfc9aa8f912 Mon Sep 17 00:00:00 2001 From: youdiansaodongxi Date: Thu, 30 May 2024 20:44:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(notification-ukcc-plugin):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=90=AF=E5=8A=A8=E6=97=B6=E5=AF=BC=E8=87=B4=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=8D=A1=E9=A1=BF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification-ukcc-plugin.cpp | 21 ++++++++++--------- .../notification-ukcc-plugin.h | 2 -- 2 files changed, 11 insertions(+), 12 deletions(-) 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