Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(privacy): some applications that have been abnormally excluded #2035

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/plugin-privacy/operation/privacysecuritymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ bool PrivacySecurityModel::addApplictionItem(ApplicationItem *item)

void PrivacySecurityModel::removeApplictionItem(const QString &id)
{
auto it = std::find_if(m_appModel->appList().begin(), m_appModel->appList().end(), [id](ApplicationItem *appItem) {
const auto list = m_appModel->appList();
auto it = std::find_if(list.cbegin(), list.cend(), [id](ApplicationItem *appItem) {
return appItem->id() == id;
});
if (it != m_appModel->appList().end()) {
Q_EMIT itemAboutToBeRemoved(it - m_appModel->appList().begin());
if (it != list.end()) {
Q_EMIT itemAboutToBeRemoved(it - list.begin());
m_appModel->removeItem(*it);
delete *it;
Q_EMIT itemRemoved();
Expand Down
25 changes: 20 additions & 5 deletions src/plugin-privacy/operation/privacysecurityworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,32 @@ QString PrivacySecurityWorker::getAppPath(const QMap<QString, QString> &execs)
if (it.key() != DESKTOP_ENTRY_ICON_KEY) {
continue;
}
const QString exec = it.value().split(' ').first();
QString exec = it.value();
if (s_excludeBin.contains(exec)) {
continue;
}
if (QFile::exists(exec)) {
appPath = exec;

QRegularExpression regex(R"(^\s*("|')([^"]+)\1|^(\S+))");
QRegularExpressionMatch match = regex.match(exec);

QString cleanedString;

if (match.hasMatch()) {
if (match.captured(2).isEmpty()) {
cleanedString = match.captured(3); // 没有引号的命令
} else {
cleanedString = match.captured(2); // 引号包裹的命令
}
}

if (QFile::exists(cleanedString)) {
appPath = cleanedString;
break;
} else {
for (const auto &binDir : m_pathList) {
QDir bin(binDir);
if (bin.exists(exec)) {
appPath = bin.absolutePath() + "/" + exec;
if (bin.exists(cleanedString)) {
appPath = bin.absolutePath() + "/" + cleanedString;
break;
}
}
Expand Down Expand Up @@ -284,6 +298,7 @@ void PrivacySecurityWorker::updateAppPath(ApplicationItem *item)

QString path = getAppPath(item->execs());
if (path.isEmpty()) {
qCInfo(DCC_PRIVACY) << "Exclude app id: " << item->id() << ", name: " << item->name() << "because it appPath is empty";
QMetaObject::invokeMethod(m_model, "removeApplictionItem", Qt::QueuedConnection, Q_ARG(QString, item->id()));
} else {
item->onAppPathChanged(path);
Expand Down