Skip to content

Commit

Permalink
fix: filter other launched app in frecently-used
Browse files Browse the repository at this point in the history
We only compare launched app by us. and it's LaunchedTimes is
not zero.
  • Loading branch information
18202781743 committed Mar 30, 2024
1 parent 56480c3 commit cdf6531
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/models/frequentlyusedproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ bool FrequentlyUsedProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex

bool FrequentlyUsedProxyModel::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const
{
const int leftLaunchedTimes = sourceLeft.data(AppItem::LaunchedTimesRole).toInt();
const int rightLaunchedTimes = sourceRight.data(AppItem::LaunchedTimesRole).toInt();
const auto leftLaunchedTimes = sourceLeft.data(AppItem::LaunchedTimesRole).toLongLong();
const auto rightLaunchedTimes = sourceRight.data(AppItem::LaunchedTimesRole).toLongLong();

if (leftLaunchedTimes != rightLaunchedTimes)
return leftLaunchedTimes < rightLaunchedTimes;

const auto leftLastLaunchedTime = sourceLeft.data(AppItem::LastLaunchedTimeRole).toLongLong();
const auto rightLastLaunchedTimes = sourceRight.data(AppItem::LastLaunchedTimeRole).toLongLong();
if (leftLastLaunchedTime != rightLastLaunchedTimes)
return leftLastLaunchedTime < rightLastLaunchedTimes;
// Only compare lastLaunchedTime when LaunchedTimes is not zero (
// maybe the app is auto-start instead of by-user).
if (leftLaunchedTimes != 0 && rightLaunchedTimes != 0) {
const auto leftLastLaunchedTime = sourceLeft.data(AppItem::LastLaunchedTimeRole).toLongLong();
const auto rightLastLaunchedTimes = sourceRight.data(AppItem::LastLaunchedTimeRole).toLongLong();
if (leftLastLaunchedTime != rightLastLaunchedTimes)
return leftLastLaunchedTime < rightLastLaunchedTimes;
}

return lessThenByFrequentlyUsed(sourceLeft, sourceRight);
}
Expand Down

0 comments on commit cdf6531

Please sign in to comment.