From f93a522546da8a5f1a1759eb0cc0166ff4f6e554 Mon Sep 17 00:00:00 2001 From: songwentao Date: Fri, 6 Jan 2023 15:40:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8D=B8=E8=BD=BDwine?= =?UTF-8?q?=E5=BA=94=E7=94=A8=EF=BC=8C=E6=A1=8C=E9=9D=A2=E6=AE=8B=E7=95=99?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 卸载应用,从桌面移除应用的路径有误,导致文件残留 2. 缓存应用信息时,如果应用是desktop文件全路径是软连接,则获取其实际文件路径 Log: Influence: 启动器-卸载wine应用时,桌面不残留应用图标 Bug: https://pms.uniontech.com/bug-view-180665.html Change-Id: I2d1e3d3bea9aaeed940c4abeca5cc083015b94ae --- src/modules/launcher/launcher.cpp | 54 ++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/modules/launcher/launcher.cpp b/src/modules/launcher/launcher.cpp index 325212e..af6f397 100644 --- a/src/modules/launcher/launcher.cpp +++ b/src/modules/launcher/launcher.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -288,16 +289,18 @@ bool Launcher::requestSendToDesktop(QString appId) */ void Launcher::requestUninstall(const QString &desktop) { + QString appDesktopPath = desktop; + bool exist = false; for (const Item &item : m_desktopAndItemMap.values()) { - if (item.info.path == desktop) { + if (item.info.path == appDesktopPath) { exist = true; break; } } if (!exist) { - qWarning() << QString(" %1 uninstall faill ...").arg(desktop); + qWarning() << QString(" %1 uninstall faill ...").arg(appDesktopPath); return; } @@ -311,16 +314,21 @@ void Launcher::requestUninstall(const QString &desktop) QString result = QString::fromUtf8(process.readAllStandardOutput()); process.close(); if (result != launcherExe) { - qWarning() << result << " has no right to uninstall " << desktop; + qWarning() << result << " has no right to uninstall " << appDesktopPath; return; } - if (!m_desktopAndItemMap.keys().contains(desktop)) { - qWarning() << QString("can't find desktopPath: %1").arg(desktop); - return; + if (!m_desktopAndItemMap.keys().contains(appDesktopPath)) { + QFileInfo fileInfo(appDesktopPath); + if (!fileInfo.isSymLink()) { + qWarning() << QString("can't find desktopPath: %1").arg(appDesktopPath); + return; + } + + appDesktopPath = fileInfo.symLinkTarget(); } - const Item &item = m_desktopAndItemMap[desktop]; + const Item &item = m_desktopAndItemMap[appDesktopPath]; DesktopInfo info(item.info.path.toStdString()); if (!info.isValidDesktop()) { qWarning() << QString("%1 desktop file is invalid...").arg(item.info.name); @@ -729,7 +737,13 @@ void Launcher::addItem(Item &item) item.info.categoryId = qint64(queryCategoryId(&item)); itemsMap[item.info.id] = item; - m_desktopAndItemMap[item.info.path] = item; + + QFileInfo desktopInfo(item.info.path); + if (desktopInfo.isSymLink()) { + m_desktopAndItemMap[desktopInfo.symLinkTarget()] = item; + } else { + m_desktopAndItemMap[item.info.path] = item; + } } Categorytype Launcher::queryCategoryId(const Item *item) @@ -1123,13 +1137,20 @@ void Launcher::uninstallApp(const QString &name, const QString &pkg) */ void Launcher::removeDesktop(const QString &desktop) { - QFile file(desktop); + QFileInfo fileInfo(desktop); + const QString &curDesktop = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + const QString &appDesktopPath = curDesktop + "/" + fileInfo.fileName(); + + QFile file(appDesktopPath); if (!file.exists()) { qDebug() << "file not exist...item info: " << desktop; return; } + // 删除应用列表中的数据 m_desktopAndItemMap.remove(desktop); + + // 删除发送到桌面的应用 file.remove(); } @@ -1162,13 +1183,16 @@ void Launcher::notifyUninstallDone(const Item &item, bool result) void Launcher::removeAutoStart(const QString &desktop) { - QFile file(desktop); - if (!file.exists()) { - qDebug() << QString("desktop file %1 doesn't exist...").arg(desktop); - return; - } + QFileInfo fileInfo(desktop); + const QString &autostartPath = BaseDir::userAutoStartDir().c_str() + fileInfo.fileName(); - file.remove(); + QFile file(autostartPath); + if (!file.exists()) { + qDebug() << QString("desktop file %1 doesn't exist...").arg(autostartPath); + return; + } + + file.remove(); } /**