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: move and sort app failed #410

Merged
merged 1 commit into from
Aug 25, 2023
Merged
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
22 changes: 11 additions & 11 deletions src/model/appsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void AppsManager::removeDuplicateData(ItemInfoList_v1 &processList)
// if same applications are installed, only show the one which path in front of XDG_DATA_DIRS
const auto xdgDataDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);

QList<QPair<int, QPair<QString, ItemInfo_v1>>> tmpList;
QMap<QString, ItemInfo_v1> id2Item;
QSet<QString> desktopIdList;

for (const auto &item : processList) {
Expand All @@ -535,22 +535,22 @@ void AppsManager::removeDuplicateData(ItemInfoList_v1 &processList)
auto desktopPath = item.m_desktop;
auto fullSuffix = xdgDataDirs[index] + "/";
auto desktopId = desktopPath.remove(fullSuffix).replace("/", "-");
tmpList.append(qMakePair(index, qMakePair(desktopId, item)));
if (id2Item.contains(desktopId))
break;

id2Item[desktopId] = item;
break;
}
}
}

// sort by the index of path which in XDG_DATA_DIRS
std::sort(tmpList.begin(), tmpList.end());
// id2Item 只会记录 XDG_DATA_DIRS 中找到的首个 item
// 这里从列表中移除所有 id2Item 不包含的 item
auto it = std::remove_if(processList.begin(), processList.end(), [&](const ItemInfo_v1 &item){
return !id2Item.values().contains(item);
});

processList.clear();
for (const auto &pair : tmpList) {
if(!desktopIdList.contains(pair.second.first)) {
desktopIdList.insert(pair.second.first);
processList.append(pair.second.second);
}
}
processList.erase(it);
}

void AppsManager::removeNonexistentData()
Expand Down
Loading