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; }