From f8d2e15dc0e6813d6cd8e816e74c6a43e0acac02 Mon Sep 17 00:00:00 2001 From: songwentao Date: Fri, 19 Aug 2022 16:07:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化新应用安装/启动后,AM发送消息通知dde-launcher的逻辑 Log: Influence: 安装应用/启动应用时,启动器功能正常 Bug: https://pms.uniontech.com/bug-view-150623.html Change-Id: Icebea449ccd5ad9eac39cf5d527e87813910b356 --- src/frameworkdbus/types/launcheriteminfo.h | 9 ++++ src/modules/launcher/launcher.cpp | 52 +++++++++++++--------- src/modules/launcher/launcher.h | 6 ++- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/frameworkdbus/types/launcheriteminfo.h b/src/frameworkdbus/types/launcheriteminfo.h index 0fabd02..2be19fe 100644 --- a/src/frameworkdbus/types/launcheriteminfo.h +++ b/src/frameworkdbus/types/launcheriteminfo.h @@ -24,6 +24,7 @@ #include #include #include +#include struct LauncherItemInfo { QString path; @@ -34,6 +35,14 @@ struct LauncherItemInfo { qint64 timeInstalled; QStringList keywords; bool operator!=(const LauncherItemInfo &versionInfo); + + friend QDebug operator<<(QDebug argument, const LauncherItemInfo &info) + { + argument << info.path << info.name << info.id; + argument << info.icon << info.categoryId << info.timeInstalled << info.keywords; + + return argument; + } }; Q_DECLARE_METATYPE(LauncherItemInfo) diff --git a/src/modules/launcher/launcher.cpp b/src/modules/launcher/launcher.cpp index 08d7979..b45b352 100644 --- a/src/modules/launcher/launcher.cpp +++ b/src/modules/launcher/launcher.cpp @@ -63,24 +63,7 @@ Launcher::Launcher(QObject *parent) loadNameMap(); initItems(); - // 关联org.deepin.daemon.DFWatcher1接口事件Event - QDBusConnection::sessionBus().connect("org.deepin.daemon.DFWatcher1", - "/org/deepin/daemon/DFWatcher1", - "org.deepin.daemon.DFWatcher1", - "Event", "", // TODO 修正事件参数 - this, SLOT(handleFSWatcherEvents(QDBusMessage))); - - // 关联org.deepin.daemon.LRecorder1接口事件Launched - QDBusConnection::sessionBus().connect("org.deepin.daemon.AlRecorder1", - "/org/deepin/daemon/AlRecorder1", - "org.deepin.daemon.AlRecorder1", - "Launched", "sa", - this, SLOT([&](QDBusMessage msg) { - QString path = msg.arguments().at(0).toString(); - Item item = getItemByPath(path); - if (item.isValid()) - Q_EMIT newAppLaunched(item.id); - })); + initConnection(); } Launcher::~Launcher() @@ -440,7 +423,7 @@ void Launcher::handleFSWatcherEvents(QDBusMessage msg) } else if (filePath == applicationsFile) { // 应用信息文件变化 loadPkgCategoryMap(); } else if (filePath.endsWith(".desktop")){ // desktop文件变化 - checkDesktopFile(filePath); + onCheckDesktopFile(filePath); } } @@ -521,8 +504,10 @@ void Launcher::loadPkgCategoryMap() } } -void Launcher::checkDesktopFile(QString filePath) +void Launcher::onCheckDesktopFile(const QString &filePath, int type) { + Q_UNUSED(type); + QString appId = getAppIdByFilePath(filePath, appDirs); if (appId.isEmpty()) return; @@ -563,6 +548,31 @@ void Launcher::checkDesktopFile(QString filePath) } } +void Launcher::onNewAppLaunched(const QString &filePath) +{ + Item item = getItemByPath(filePath); + + if (item.isValid()) + Q_EMIT newAppLaunched(item.info.id); +} + +void Launcher::initConnection() +{ + QDBusConnection::sessionBus().connect("org.deepin.daemon.DFWatcher1", + "/org/deepin/daemon/DFWatcher1", + "org.deepin.daemon.DFWatcher1", + "Event", + this, + SLOT(onCheckDesktopFile(const QString &, int))); + + QDBusConnection::sessionBus().connect("org.deepin.daemon.AlRecorder1", + "/org/deepin/daemon/AlRecorder1", + "org.deepin.daemon.AlRecorder1", + "Launched", + this, + SLOT(onNewAppLaunched(const QString &))); +} + /** * @brief Launcher::handleAppHiddenChanged 响应DConfig中隐藏应用配置变化 */ @@ -673,7 +683,7 @@ void Launcher::initItems() } } -void Launcher::addItem(Item item) +void Launcher::addItem(Item &item) { if (!item.isValid()) return; diff --git a/src/modules/launcher/launcher.h b/src/modules/launcher/launcher.h index bca18ef..8b6a7ea 100644 --- a/src/modules/launcher/launcher.h +++ b/src/modules/launcher/launcher.h @@ -119,19 +119,21 @@ Q_SIGNALS: private Q_SLOTS: void handleFSWatcherEvents(QDBusMessage msg); void onAppSuffixNameChanged(bool hidden); + void onCheckDesktopFile(const QString &filePath, int type = 0); + void onNewAppLaunched(const QString &filePath); private: + void initConnection(); void initSettings(); void loadDesktopPkgMap(); void loadPkgCategoryMap(); - void checkDesktopFile(QString filePath); void handleAppHiddenChanged(); void loadNameMap(); void initItems(); QString getAppIdByFilePath(QString filePath, QStringList dirs); bool isDeepinCustomDesktopFile(QString fileName); Item NewItemWithDesktopInfo(DesktopInfo &info); - void addItem(Item item); + void addItem(Item &item); Categorytype queryCategoryId(const Item *item); Categorytype getXCategory(const Item *item); QString queryPkgName(const QString &itemID, const QString &itemPath);