Skip to content

Commit 20ea249

Browse files
committed
address comments
1 parent 22a8921 commit 20ea249

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/core/desktopentry.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString&
102102
auto finishCategory = [&data, &groupName, &entries]() {
103103
if (groupName == "Desktop Entry") {
104104
if (entries.value("Type").second != "Application") return;
105-
106105
if (entries.value("Hidden").second == "true") return;
107106

108107
for (const auto& [key, pair]: entries.asKeyValueRange()) {
@@ -146,8 +145,8 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString&
146145
entries.clear();
147146
};
148147

149-
for (auto& line: text.split(u'\n')) {
150-
if (line.isEmpty() || line.startsWith(u'#')) continue;
148+
for (auto& line: text.split(u'\n', Qt::SkipEmptyParts)) {
149+
if (line.startsWith(u'#')) continue;
151150

152151
if (line.startsWith(u'[') && line.endsWith(u']')) {
153152
finishCategory();
@@ -213,7 +212,6 @@ void DesktopEntry::updateActions(const QHash<QString, DesktopActionData>& newAct
213212
auto old = this->mActions;
214213

215214
for (const auto& [key, d]: newActions.asKeyValueRange()) {
216-
217215
DesktopAction* act = nullptr;
218216
if (auto found = old.find(key); found != old.end()) {
219217
act = found.value();
@@ -311,7 +309,7 @@ QVector<QString> DesktopEntry::parseExecString(const QString& execString) {
311309
}
312310

313311
void DesktopEntry::doExec(const QList<QString>& execString, const QString& workingDirectory) {
314-
auto ctx = qs::io::process::ProcessContext();
312+
qs::io::process::ProcessContext ctx;
315313
ctx.setCommand(execString);
316314
ctx.setWorkingDirectory(workingDirectory);
317315
QuickshellGlobal::execDetached(ctx);
@@ -326,11 +324,10 @@ DesktopEntryScanner::DesktopEntryScanner(DesktopEntryManager* manager): manager(
326324
}
327325

328326
void DesktopEntryScanner::run() {
329-
auto desktopPaths = DesktopEntryManager::desktopPaths();
327+
const auto& desktopPaths = DesktopEntryManager::desktopPaths();
330328
auto scanResults = QList<ParsedDesktopEntryData>();
331329

332-
for (int i = desktopPaths.size() - 1; i >= 0; --i) {
333-
const auto& path = desktopPaths.at(i);
330+
for (const auto& path: desktopPaths | std::views::reverse) {
334331
auto file = QFileInfo(path);
335332
if (!file.isDir()) continue;
336333

@@ -395,11 +392,13 @@ void DesktopEntryManager::scanDesktopEntries() {
395392
qCDebug(logDesktopEntry) << "Starting desktop entry scan";
396393

397394
if (this->scanInProgress) {
398-
qCDebug(logDesktopEntry) << "Scan already in progress, skipping";
395+
qCDebug(logDesktopEntry) << "Scan already in progress, queuing another scan";
396+
this->scanQueued = true;
399397
return;
400398
}
401399

402400
this->scanInProgress = true;
401+
this->scanQueued = false;
403402
auto* scanner = new DesktopEntryScanner(this);
404403
QThreadPool::globalInstance()->start(scanner);
405404
}
@@ -444,11 +443,13 @@ void DesktopEntryManager::handleFileChanges() {
444443
qCDebug(logDesktopEntry) << "Directory change detected, performing full rescan";
445444

446445
if (this->scanInProgress) {
447-
qCDebug(logDesktopEntry) << "Scan already in progress, skipping";
446+
qCDebug(logDesktopEntry) << "Scan already in progress, queuing another scan";
447+
this->scanQueued = true;
448448
return;
449449
}
450450

451451
this->scanInProgress = true;
452+
this->scanQueued = false;
452453
auto* scanner = new DesktopEntryScanner(this);
453454
QThreadPool::globalInstance()->start(scanner);
454455
}
@@ -476,7 +477,13 @@ const QStringList& DesktopEntryManager::desktopPaths() {
476477
}
477478

478479
void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& scanResults) {
479-
auto guard = qScopeGuard([this] { this->scanInProgress = false; });
480+
auto guard = qScopeGuard([this] {
481+
this->scanInProgress = false;
482+
if (this->scanQueued) {
483+
this->scanQueued = false;
484+
this->scanDesktopEntries();
485+
}
486+
});
480487

481488
auto oldEntries = this->desktopEntries;
482489
auto newEntries = QHash<QString, DesktopEntry*>();
@@ -536,9 +543,9 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
536543

537544
this->mApplications.diffUpdate(newApplications);
538545

539-
for (auto* e: oldEntries) e->deleteLater();
540-
541546
emit applicationsChanged();
547+
548+
for (auto* e: oldEntries) e->deleteLater();
542549
}
543550

544551
DesktopEntries::DesktopEntries() {

src/core/desktopentry.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ private slots:
278278
ObjectModel<DesktopEntry> mApplications {this};
279279
DesktopEntryMonitor* monitor = nullptr;
280280
bool scanInProgress = false;
281+
bool scanQueued = false;
281282

282283
friend class DesktopEntryScanner;
283284
};

src/core/desktopentrymonitor.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ DesktopEntryMonitor::DesktopEntryMonitor(QObject* parent): QObject(parent) {
2323
this->debounceTimer.setSingleShot(true);
2424
this->debounceTimer.setInterval(100);
2525

26-
connect(
26+
QObject::connect(
2727
&this->watcher,
2828
&QFileSystemWatcher::directoryChanged,
2929
this,
3030
&DesktopEntryMonitor::onDirectoryChanged
3131
);
32-
connect(&this->debounceTimer, &QTimer::timeout, this, &DesktopEntryMonitor::processChanges);
32+
QObject::connect(
33+
&this->debounceTimer,
34+
&QTimer::timeout,
35+
this,
36+
&DesktopEntryMonitor::processChanges
37+
);
3338

3439
this->startMonitoring();
3540
}

0 commit comments

Comments
 (0)