Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion dbus/launcher1compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#include "pkutils.h"

#include <DDesktopEntry>
#include <DNotifySender>

Check warning on line 10 in dbus/launcher1compat.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DNotifySender> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <launcher1adaptor.h> // this is the adapter of daemon.Launcher1

Check warning on line 11 in dbus/launcher1compat.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <launcher1adaptor.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// Qt includes
#include <QSet>

Check warning on line 14 in dbus/launcher1compat.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// PackageKit-Qt
#include <Daemon>

Check warning on line 17 in dbus/launcher1compat.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <Daemon> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// Ends with a slash, this is the install prefix for the trusted launcher app.
// For package maintianers, if your distro install binaries to weird locations,
Expand Down Expand Up @@ -166,7 +169,41 @@
return;
}

QString desktopFilePath(desktopFileInfo.isSymLink() ? desktopFileInfo.symLinkTarget() : desktop);
QString desktopFilePath;
if (desktopFileInfo.isSymLink()) {
// Recursively resolve symlinks to get the final target
QString currentPath = desktop;
QSet<QString> visitedPaths; // Prevent infinite loops

while (true) {
QFileInfo currentInfo(currentPath);
if (!currentInfo.isSymLink()) {
// Found the final target
desktopFilePath = currentPath;
break;
}

QString symLinkTarget = currentInfo.symLinkTarget();
if (!QFile::exists(symLinkTarget)) {
qDebug() << "Symlink target" << symLinkTarget << "does not exist, using original path" << desktop;
desktopFilePath = desktop;
break;
}

if (visitedPaths.contains(currentPath)) {
qDebug() << "Circular symlink detected, using original path" << desktop;
desktopFilePath = desktop;
break;
}

visitedPaths.insert(currentPath);
currentPath = symLinkTarget;
}

qDebug() << "Resolved symlink chain from" << desktop << "to" << desktopFilePath;
} else {
desktopFilePath = desktop;
}
DDesktopEntry desktopEntry(desktopFilePath);
if (desktopEntry.status() != DDesktopEntry::NoError) {
qDebug() << "Desktop file" << desktop << "is invalid.";
Expand Down Expand Up @@ -221,6 +258,40 @@
sendNotification(desktopEntry.ddeDisplayName(), true);
}
// TODO: check if it's a flatpak or snap bundle and do the uninstallation?
// 单独处理chrome 的快捷浏览器创建卸载
} else if (desktopFilePath.contains("/.local/share/applications/") &&
(desktopFilePath.contains("chrome-") ||
desktopEntry.stringValue("Exec").contains("google-chrome"))) {
// Handle Chrome PWA apps specifically
qDebug() << "Detected Chrome PWA application:" << desktopFilePath;

bool success = true;
QString iconPath = desktopEntry.stringValue("Icon");

// Remove the desktop file
QFile desktopFile(desktopFilePath);
if (!desktopFile.remove()) {
qDebug() << "Failed to remove Chrome PWA desktop file:" << desktopFilePath;
success = false;
}

// Remove the associated icon if it's a file path
if (success && !iconPath.isEmpty() && QFile::exists(iconPath)) {
QFile iconFile(iconPath);
if (!iconFile.remove()) {
qDebug() << "Warning: Failed to remove Chrome PWA icon file:" << iconPath;
}
}

if (success) {
QFileInfo fileInfo(desktopFilePath);
postUninstallCleanUp(fileInfo.fileName());
emit UninstallSuccess(desktopFilePath);
sendNotification(desktopEntry.ddeDisplayName(), true);
} else {
emit UninstallFailed(desktopFilePath, QString("Failed to remove Chrome PWA application"));
sendNotification(desktopEntry.ddeDisplayName(), false);
}
} else {
m_packageDisplayName = desktopEntry.ddeDisplayName();

Expand Down