From f830885be5c8eeaf5f024a79f3e19a04bf20cdf7 Mon Sep 17 00:00:00 2001 From: donghualin Date: Fri, 31 Dec 2021 17:27:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=90=AF=E5=8A=A8=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 任务栏插件加载的配置改成只在用到的时候创建一次,加速启动的时间,同时也减小了内存;启动器部分的提示框延迟创建。 Log: 优化启动速度 Influence: 任务栏启动时间 Task: https://pms.uniontech.com/zentao/task-view-95700.html Change-Id: I187100f24cf9ac932b1e143c7671beb0841b3fce --- frame/item/appitem.cpp | 24 ++++++++++-------------- frame/item/appitem.h | 6 ------ frame/item/launcheritem.cpp | 27 ++++++++++++++++----------- frame/item/launcheritem.h | 9 ++++----- frame/window/mainwindow.cpp | 3 +-- 5 files changed, 31 insertions(+), 38 deletions(-) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index c0ae364e6..610092f84 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -54,7 +54,6 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti , m_appSettings(appSettings) , m_activeAppSettings(activeAppSettings) , m_dockedAppSettings(dockedAppSettings) - , m_appNameTips(new TipsWidget(this)) , m_appPreviewTips(nullptr) , m_itemEntryInter(new DockEntryInter("com.deepin.dde.daemon.Dock", entry.path(), QDBusConnection::sessionBus(), this)) , m_swingEffectView(nullptr) @@ -70,7 +69,6 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti , m_retryObtainIconTimer(new QTimer(this)) , m_refershIconTimer(new QTimer(this)) , m_themeType(DGuiApplicationHelper::instance()->themeType()) - , m_config(new DConfig(QString("com.deepin.dde.dock.dconfig"), QString(), this)) { QHBoxLayout *centralLayout = new QHBoxLayout; centralLayout->setMargin(0); @@ -83,10 +81,6 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti m_id = m_itemEntryInter->id(); m_active = m_itemEntryInter->isActive(); - m_appNameTips->setObjectName(m_itemEntryInter->name()); - m_appNameTips->setVisible(false); - m_appNameTips->installEventFilter(this); - m_updateIconGeometryTimer->setInterval(500); m_updateIconGeometryTimer->setSingleShot(true); @@ -476,22 +470,24 @@ const QString AppItem::contextMenu() const QWidget *AppItem::popupTips() { - if (checkGSettingsControl()) { + if (checkGSettingsControl()) return nullptr; - } if (m_dragging) return nullptr; + static TipsWidget appNameTips(topLevelWidget()); + appNameTips.setVisible(false); + if (!m_windowInfos.isEmpty()) { const quint32 currentWindow = m_itemEntryInter->currentWindow(); Q_ASSERT(m_windowInfos.contains(currentWindow)); - m_appNameTips->setText(m_windowInfos[currentWindow].title.simplified()); + appNameTips.setText(m_windowInfos[currentWindow].title.simplified()); } else { - m_appNameTips->setText(m_itemEntryInter->name().simplified()); + appNameTips.setText(m_itemEntryInter->name().simplified()); } - return m_appNameTips; + return &appNameTips; } void AppItem::startDrag() @@ -672,8 +668,9 @@ void AppItem::showPreview() connect(m_appPreviewTips, &PreviewContainer::requestHidePopup, this, &AppItem::onResetPreview); // 预览标题显示方式的配置 - if (m_config->isValid() && m_config->keyList().contains("Dock_Show_Window_name")) - m_appPreviewTips->setTitleDisplayMode(m_config->value("Dock_Show_Window_name").toInt()); + DConfig config(QString("com.deepin.dde.dock.dconfig"), QString()); + if (config.isValid() && config.keyList().contains("Dock_Show_Window_name")) + m_appPreviewTips->setTitleDisplayMode(config.value("Dock_Show_Window_name").toInt()); showPopupWindow(m_appPreviewTips, true); } @@ -766,7 +763,6 @@ void AppItem::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType) AppItem::~AppItem() { stopSwingEffect(); - m_appNameTips->deleteLater(); } void AppItem::showEvent(QShowEvent *e) diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 0109f5b14..eb78d0406 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -39,10 +39,6 @@ using DockEntryInter = com::deepin::dde::daemon::dock::Entry; class QGSettings; -DCORE_BEGIN_NAMESPACE -class DConfig; -DCORE_END_NAMESPACE - class AppItem : public DockItem { Q_OBJECT @@ -114,7 +110,6 @@ private: const QGSettings *m_activeAppSettings; const QGSettings *m_dockedAppSettings; - TipsWidget *m_appNameTips; PreviewContainer *m_appPreviewTips; DockEntryInter *m_itemEntryInter; @@ -148,7 +143,6 @@ private: DGuiApplicationHelper::ColorType m_themeType; static QPoint MousePressPos; - DTK_CORE_NAMESPACE::DConfig *m_config; }; #endif // APPITEM_H diff --git a/frame/item/launcheritem.cpp b/frame/item/launcheritem.cpp index 9f0be789e..8bfbec4f4 100644 --- a/frame/item/launcheritem.cpp +++ b/frame/item/launcheritem.cpp @@ -22,26 +22,24 @@ #include "launcheritem.h" #include "themeappicon.h" #include "utils.h" +#include "../widgets/tipswidget.h" #include #include #include #include #include +#include +#include +#include +#include DCORE_USE_NAMESPACE LauncherItem::LauncherItem(QWidget *parent) : DockItem(parent) - , m_launcherInter(new LauncherInter("com.deepin.dde.Launcher", "/com/deepin/dde/Launcher", QDBusConnection::sessionBus(), this)) - , m_tips(new TipsWidget(this)) , m_gsettings(Utils::ModuleSettingsPtr("launcher", QByteArray(), this)) { - m_launcherInter->setSync(true, false); - - m_tips->setVisible(false); - m_tips->setObjectName("launcher"); - if (m_gsettings) { connect(m_gsettings, &QGSettings::changed, this, &LauncherItem::onGSettingsChanged); } @@ -102,9 +100,14 @@ void LauncherItem::mouseReleaseEvent(QMouseEvent *e) if (e->button() != Qt::LeftButton) return; - if (!m_launcherInter->IsVisible()) { - m_launcherInter->Show(); - } + DDBusSender dbusSender = DDBusSender() + .service("com.deepin.dde.Launcher") + .path("/com/deepin/dde/Launcher") + .interface("com.deepin.dde.Launcher"); + + QDBusPendingReply visibleReply = dbusSender.property("Visible").get(); + if (!visibleReply.value()) + dbusSender.method("Show").call(); } QWidget *LauncherItem::popupTips() @@ -113,8 +116,10 @@ QWidget *LauncherItem::popupTips() return nullptr; } + m_tips.reset(new TipsWidget(this)); + m_tips->setVisible(false); m_tips->setText(tr("Launcher")); - return m_tips; + return m_tips.get(); } void LauncherItem::onGSettingsChanged(const QString& key) { diff --git a/frame/item/launcheritem.h b/frame/item/launcheritem.h index 9381acc73..bd6d6342a 100644 --- a/frame/item/launcheritem.h +++ b/frame/item/launcheritem.h @@ -23,11 +23,11 @@ #define LAUNCHERITEM_H #include "dockitem.h" -#include "../widgets/tipswidget.h" -#include +namespace Dock { +class TipsWidget; +} -using LauncherInter = com::deepin::dde::Launcher; class QGSettings; class LauncherItem : public DockItem { @@ -57,9 +57,8 @@ private: private: QPixmap m_icon; - LauncherInter *m_launcherInter; - TipsWidget *m_tips; const QGSettings *m_gsettings; + QSharedPointer m_tips; }; #endif // LAUNCHERITEM_H diff --git a/frame/window/mainwindow.cpp b/frame/window/mainwindow.cpp index a2e992ae7..0d4cbb2d9 100755 --- a/frame/window/mainwindow.cpp +++ b/frame/window/mainwindow.cpp @@ -153,10 +153,9 @@ void MainWindow::launch() return; m_launched = true; - qApp->processEvents(); - setVisible(true); m_multiScreenWorker->initShow(); m_shadowMaskOptimizeTimer->start(); + QTimer::singleShot(0, this, [ this ] { this->setVisible(true); }); } /**