From 7a86c667a30c6ffdcd6cc5a71d41de8ff97ce57e Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Mon, 20 Nov 2023 14:08:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(app-database-service):=E4=BD=BF=E7=94=A8win?= =?UTF-8?q?ID=E6=9F=A5=E6=89=BEdesktop=E6=96=87=E4=BB=B6=E6=97=B6=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=BA=94=E7=94=A8=E4=BC=9A=E6=89=BE=E9=94=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-db-manager.cpp | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index 9b571a6..6007f99 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -1568,9 +1568,8 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id) QString classClass = info.windowClassClass(); //the 2nd part of WM_CLASS, specified by the application writer QSqlQuery query(m_database); query.setForwardOnly(true); - query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE EXEC LIKE :classClass OR DESKTOP_FILE_PATH LIKE :classClass " - "OR LOWER(START_UP_WMCLASS)=:windowClassClass OR LOWER(LOCAL_NAME)=:windowClassClass"); - query.bindValue(":classClass", "%" + classClass + "%"); + query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE " + "LOWER(START_UP_WMCLASS)=:windowClassClass OR LOWER(LOCAL_NAME)=:windowClassClass"); query.bindValue(":windowClassClass", classClass.toLower()); if (query.exec()) { @@ -1592,6 +1591,29 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id) } } } + //没有查到 + if (desktopFilePath.isEmpty()) { + query.prepare("SELECT DESKTOP_FILE_PATH, START_UP_WMCLASS FROM APPINFO WHERE EXEC LIKE :classClass OR DESKTOP_FILE_PATH LIKE :classClass"); + query.bindValue(":classClass", "%" + classClass + "%"); + + if (query.exec()) { + while (query.next()) { + wmClassInfos[query.value("DESKTOP_FILE_PATH").toString()] = query.value("START_UP_WMCLASS").toString(); + } + + if (!wmClassInfos.isEmpty()) { + for (auto it = wmClassInfos.constBegin(); it != wmClassInfos.constEnd(); it++) { + if (wmClassInfos.size() > 1 && it.key().startsWith(AUTOSTART_APP_DESKTOP_PATH)) { + continue; + } + if (it.key().section("/", -1) == (classClass + ".desktop") || it.value().toLower() == classClass.toLower()) { + desktopFilePath = it.key(); + break; + } + } + } + } + } if (!desktopFilePath.isEmpty()) { qDebug() << "WId:" << id.variant() << "Classclass of window:" << classClass << "Desktop file path:" << desktopFilePath; @@ -1603,10 +1625,17 @@ QString AppDBManager::tranWinIdToDesktopFilePath(const QDBusVariant &id) } if (desktopFilePath.isEmpty()) { - desktopFilePath = this->tranPidToDesktopFp(info.pid()); +// desktopFilePath = this->tranPidToDesktopFp(info.pid()); + QDBusReply reply = m_processManagerInterface->call("GetDesktopFileByPid", info.pid()); + if (reply.isValid()) { + desktopFilePath = reply.value(); + qDebug() << "PID: " << info.pid() << "Desktop file path: " << desktopFilePath; + } else { + qWarning() << "Cannot find desktop file by pid:" << info.pid() << "because of " << reply.error(); + } } } else { - qWarning() << "Cannot find desktop flie by WinId:" << id.variant() << "it is invalid" << id.variant().toULongLong(); + qWarning() << "Cannot find desktop file by WinId:" << id.variant() << "it is invalid" << id.variant().toULongLong(); } return desktopFilePath; }