fix(app-database-service):使用winID查找desktop文件时一些应用会找错。

This commit is contained in:
JunjieBai 2023-11-20 14:08:37 +08:00
parent e49d867075
commit 7a86c667a3
1 changed files with 34 additions and 5 deletions

View File

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