From e18bb390a7077368465404d986ef3a95960c5fb0 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Tue, 14 Nov 2023 14:55:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(app-database-service):=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=88=A0=E9=99=A4=E5=90=8E=E9=87=8D=E5=BB=BA=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=EF=BC=8C=E5=BA=94=E7=94=A8=E6=89=93=E5=BC=80=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E8=AE=B0=E5=BD=95=E9=94=99=E8=AF=AF.=20=E5=BB=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=97=B6=E7=BC=BA=E5=B0=91START=5FU?= =?UTF-8?q?P=5FWMCLAS=E5=AD=97=E6=AE=B5=E5=AF=BC=E8=87=B4=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=95=B0=E6=8D=AE=E5=86=99=E5=85=A5=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=EF=BC=8C=E8=AE=B0=E5=BD=95=E6=89=93=E5=BC=80=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=A2=E6=88=90=E4=BD=BF=E7=94=A8processmanager=E7=9A=84?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9D=A5=E8=A7=A6=E5=8F=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-db-manager.cpp | 53 +++++++++++++------ ukui-search-app-data-service/app-db-manager.h | 6 +++ 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index dbf247c..c4b861f 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -25,6 +25,8 @@ #include "appdatabaseadaptor.h" #include "file-utils.h" #include "application-property-helper.h" +#include "app-db-manager.h" + #define GENERAL_APP_DESKTOP_PATH "/usr/share/applications" #define ANDROID_APP_DESKTOP_PATH QDir::homePath() + "/.local/share/applications" @@ -168,14 +170,24 @@ AppDBManager::AppDBManager(QObject *parent) : QThread(parent), m_database(QSqlDa }, Qt::DirectConnection); */ + m_processManagerInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"), + QStringLiteral("/com/kylin/ProcessManager/AppLauncher"), + QStringLiteral("com.kylin.ProcessManager.AppLauncher"), + QDBusConnection::sessionBus(), this); + if (!m_processManagerInterface->isValid()) { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } else { + connect(m_processManagerInterface, SIGNAL(AppLaunched(QString)), this, SLOT(handleAppLaunched(QString))); + } + //监控应用进程开启 - connect(KWindowSystem::self(), &KWindowSystem::windowAdded, [ = ](WId id) { - QDBusVariant dbusVariant(id); - QString desktopFilePath = this->tranWinIdToDesktopFilePath(dbusVariant); - if (!desktopFilePath.isEmpty()) { - this->updateLaunchTimes(desktopFilePath); - } - }); +// connect(KWindowSystem::self(), &KWindowSystem::windowAdded, [ = ](WId id) { +// QDBusVariant dbusVariant(id); +// QString desktopFilePath = this->tranWinIdToDesktopFilePath(dbusVariant); +// if (!desktopFilePath.isEmpty()) { +// this->updateLaunchTimes(desktopFilePath); +// } +// }); new AppDBManagerAdaptor(this); } else { qDebug() << "App-db-manager does nothing."; @@ -187,12 +199,12 @@ AppDBManager::~AppDBManager() if (m_watcher) { delete m_watcher; } - m_watcher = NULL; + m_watcher = nullptr; if (m_snapdWatcher) { delete m_snapdWatcher; } - m_snapdWatcher = NULL; + m_snapdWatcher = nullptr; // if(m_watchAppDir) { // delete m_watchAppDir; @@ -205,7 +217,7 @@ void AppDBManager::buildAppInfoDB() { qDebug() << "I'm going to build app info database."; QSqlQuery sql(m_database); - QString cmd = QString("CREATE TABLE IF NOT EXISTS appInfo(%1, %2, %3, %4, %5, %6, %7, %8,%9, %10, %11, %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %22)") + QString cmd = QString("CREATE TABLE IF NOT EXISTS appInfo(%1, %2, %3, %4, %5, %6, %7, %8,%9, %10, %11, %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %22, %23)") // .arg("ID INT")//自增id .arg("DESKTOP_FILE_PATH TEXT PRIMARY KEY NOT NULL")//desktop文件路径 .arg("MODIFYED_TIME TEXT")//YYYYMMDDHHmmSS 修改日期 @@ -228,7 +240,8 @@ void AppDBManager::buildAppInfoDB() .arg("TOP INT")//置顶顺序 0:未置顶;>0的数字表示置顶顺序 .arg("LOCK INT")//应用是否锁定(管控),0未锁定,1锁定 .arg("DONT_DISPLAY INT")//应用隐藏(NoDisplay, NotShowIn) - .arg("AUTO_START INT");//自启应用 + .arg("AUTO_START INT")//自启应用 + .arg("START_UP_WMCLASS TEXT");//classname if (!sql.exec(cmd)) { qWarning() << m_database.lastError() << cmd; return; @@ -262,7 +275,7 @@ void AppDBManager::initFileSystemWatcher() connect(m_snapdWatcher, &FileSystemWatcher::created, this, [ = ] (const QString &path, bool isDir) { if (isDir) { - //监测新增目录为/var/lib/snapd时,将其替换为snapdWatcher的watchpath + //监测新增目录为/var/lib/snapd时,将其替换为snapdWatcher的watch path if (path == "/var/lib/snapd") { m_snapdWatcher->removeWatch(m_snapdPath); m_snapdWatcher->addWatch(path); @@ -1311,7 +1324,7 @@ void AppDBManager::handleDataBaseRefresh(const QStringList &appPaths, bool dbVer this->loadDesktopFilePaths(path, infos); } - if(infos.size() < 1) { + if(infos.isEmpty()) { return; } XdgDesktopFile desktopfile; @@ -1329,7 +1342,7 @@ void AppDBManager::handleDataBaseRefresh(const QStringList &appPaths, bool dbVer } desktopfile.load(path); - //排除loaclized名字为空 + //排除localized名字为空 if (desktopfile.localizedValue("Name").toString().isEmpty()) { continue; } @@ -1379,8 +1392,8 @@ bool AppDBManager::handleValueSet(const ApplicationInfoMap appInfoMap) QSqlQuery query(m_database); for (auto iter = appInfoMap.constBegin(); iter != appInfoMap.constEnd(); iter++) { - QString desktopFilePath = iter.key(); - ApplicationPropertyMap propMap = iter.value(); + const QString& desktopFilePath = iter.key(); + const ApplicationPropertyMap& propMap = iter.value(); for (auto propIter = propMap.constBegin(); propIter != propMap.constEnd(); ++propIter) { QString field = ApplicationPropertyHelper(propIter.key()).dataBaseField(); @@ -1643,3 +1656,11 @@ void AppDBManager::setValue(const ApplicationInfoMap &infos2BSet) PendingAppInfoQueue::getAppInfoQueue().enqueue(item); } } + +void AppDBManager::handleAppLaunched(QString desktopFilePath) { + if (!desktopFilePath.isEmpty()) { + this->updateLaunchTimes(desktopFilePath); + } else { + qWarning() << "desktopFilePath is empty."; + } +} diff --git a/ukui-search-app-data-service/app-db-manager.h b/ukui-search-app-data-service/app-db-manager.h index 2fd1269..1b51f34 100644 --- a/ukui-search-app-data-service/app-db-manager.h +++ b/ukui-search-app-data-service/app-db-manager.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "pending-app-info-queue.h" #include "file-system-watcher.h" @@ -105,6 +106,9 @@ public Q_SLOTS: void setValue(const ApplicationInfoMap &infos2BSet); +private Q_SLOTS: + void handleAppLaunched(QString desktopFilePath); + protected: void run() override; @@ -143,6 +147,8 @@ private: QSettings *m_lastLocaleNameQsettings = nullptr; QSettings *m_dbVersionQsettings = nullptr; + QDBusInterface *m_processManagerInterface = nullptr; + // QTimer *m_timer = nullptr; // QTimer *m_maxProcessTimer = nullptr; // QFileSystemWatcher *m_watchAppDir = nullptr;